models

package
v0.0.0-...-11c8b56 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2018 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package models contains all of our models and utility functions for creating and modifying them

Index

Constants

View Source
const (
	FloatField  DataType = "FLOAT"
	StringField          = "STRING"
	IntField             = "INT"
	DateField            = "DATE"
	OptionField          = "OPTION"
)

These are the available data types for fields on Tickets.

View Source
const (
	StatusTodo       StatusType = "TODO"
	StatusInProgress            = "IN_PROGRESS"
	StatusDone                  = "Done"

	// StatusNull is a special type used for transitions that allow from any or
	// for create transitions
	StatusNull = "NULL"
)

Available status types

Variables

DataTypes holds the available data types

View Source
var ErrInvalidDataType = errors.New("Invalid data type for field")

ErrInvalidDataType indicates that the field was created with an incorrect data type

Functions

This section is empty.

Types

type Comment

type Comment struct {
	ID          bson.ObjectId `json:"id"`
	UpdatedDate time.Time     `json:"updatedDate"`
	CreatedDate time.Time     `json:"createdDate"`
	Body        string        `json:"body" required:"true"`
	Author      string        `json:"author" required:"true"`
}

Comment is a comment on an issue / ticket.

func (*Comment) String

func (c *Comment) String() string

type DataType

type DataType string

DataType is a string which indicates the type of data in a given field.

type Field

type Field struct {
	Name     string   `json:"name"`
	DataType DataType `json:"dataType"`

	// Options is only relevant for Fields of DataType OPTION
	Options []string `json:"options,omitempty" bson:"options,omitempty"`

	// Value holds the value of the given field
	Value interface{} `json:"value,omitempty" bson:"value,omitempty"`
}

Field is a ticket field

func (Field) IsValidDataType

func (f Field) IsValidDataType() bool

IsValidDataType is used to verify that the field has a data type we can support

func (Field) String

func (f Field) String() string

type FieldScheme

type FieldScheme struct {
	ID   bson.ObjectId `json:"id" bson:"_id,omitempty"`
	Name string        `json:"name" required:"true"`

	// Map ticket type to fields
	Fields map[string][]Field `json:"fields"`
}

FieldScheme assigns fields to a ticke type.

func (FieldScheme) ValidateTicket

func (fs FieldScheme) ValidateTicket(t Ticket) error

ValidateTicket verifies that all fields on t are valid

type Hook

type Hook struct {
	Endpoint string `json:"endpoint"`
	Method   string `json:"method"`
	Body     string `json:"body"`
}

Hook contains information about what webhooks to fire when a given transition is run.

func (Hook) String

func (h Hook) String() string

type Notification

type Notification struct {
	ID             bson.ObjectId `bson:"_id" json:"id"`
	Project        string        `json:"project"`
	ActioningUser  string        `json:"actioningUser"`
	ActionedTicket string        `json:"actionedTicket"`
	Type           string        `json:"eventType"`
	Body           string        `json:"body"`
	Read           bool          `json:"read"`
	Watcher        string        `json:"watcher"`
	CreatedDate    time.Time     `json:"createdDate"`
}

Notification is any kind of activity on a project for which a user might want an auditble history of

type Project

type Project struct {
	Key         string           `json:"key" bson:"_id" required:"true"`
	Name        string           `json:"name" required:"true"`
	CreatedDate time.Time        `json:"createdDate"`
	Lead        string           `json:"lead"`
	Homepage    string           `json:"homepage,omitempty"`
	Repo        string           `json:"repo,omitempty"`
	TicketTypes []string         `json:"ticketTypes"`
	Public      bool             `json:"public"`
	Permissions []RolePermission `json:"permissions"`

	FieldScheme bson.ObjectId `json:"fieldScheme"`

	// Map ticket types to workflow ID's
	WorkflowScheme []WorkflowMapping `json:"workflowScheme"`

	Icon *mgo.GridFile `json:"-"`
}

Project is the model used to represent a project in the database.

func HasPermission

func HasPermission(permName permission.Permission, user User,
	projects ...Project) []Project

HasPermission will return a slice of projects for which the given user has the permission indicated out of the projects given.

func (Project) GetPermsForRoles

func (p Project) GetPermsForRoles(roles ...Role) permission.Permissions

GetPermsForRoles will take the given roles and return a slice of Permissions that those roles have NOTE: It does not remove duplicates so some permissions may exist more than once

func (Project) GetWorkflow

func (p Project) GetWorkflow(ticketType string) bson.ObjectId

GetWorkflow will return the ID of the workflow to use for tickets of the given type for this project.

func (Project) HasTicketType

func (p Project) HasTicketType(typeName string) bool

HasTicketType is used to validate whether the given ticket type exists for this project

func (Project) String

func (p Project) String() string

type Role

type Role string

Role is an alias type to make it's use more clear inside of other models.

type RolePermission

type RolePermission struct {
	Role       Role                  `json:"role"`
	Permission permission.Permission `json:"permission"`
}

RolePermission maps a role to a permission on a project

type Sanitizer

type Sanitizer interface {
	Sanitize() interface{}
}

Sanitizer is implemented by any model which needs to be sanitized before being JSON serialized

type Session

type Session struct {
	Token    string `bson:"_id"`
	ClientID string
}

Session ties a token to a specific client

func (Session) String

func (s Session) String() string

type Settings

type Settings struct {
	DefaultProject string `json:"defaultProject,omitempty"`
	DefaultView    string `json:"defaultView,omitempty"`
}

Settings represents an individual users preferences

type Status

type Status struct {
	Name string     `bson:"name" json:"name"`
	Type StatusType `bson:"type" json:"type"`
}

Status is a ticket and workflow status

type StatusType

type StatusType string

StatusType represents the statuses type based on the basic three types: TODO, In Progress, or Done

type Ticket

type Ticket struct {
	CreatedDate time.Time `json:"createdDate"`
	UpdatedDate time.Time `json:"updatedDate"`
	Key         string    `bson:"_id" json:"key"`
	Summary     string    `json:"summary" required:"true"`
	Description string    `json:"description" required:"true"`
	Status      Status    `json:"status"`
	Reporter    string    `json:"reporter" required:"true"`
	Assignee    string    `json:"assignee"`
	Type        string    `json:"type" required:"true"`
	Labels      []string  `json:"labels"`
	Watchers    []string  `json:"watchers"`

	Fields   []Field   `json:"fields"`
	Comments []Comment `json:"comments,omitempty"`

	Workflow bson.ObjectId `json:"workflow"`
	Project  string        `json:"project" required:"true"`
}

Ticket represents a ticket

func (Ticket) String

func (t Ticket) String() string

func (Ticket) Transition

func (t Ticket) Transition(db *mgo.Database, name string) (Transition, bool)

Transition searches through the available transitions for the ticket returning a boolean indicating success or failure and the transition

type Transition

type Transition struct {
	Name       string `json:"name"`
	FromStatus Status `json:"fromStatus"`
	ToStatus   Status `json:"toStatus"`
	Hooks      []Hook `json:"hooks"`
}

Transition contains information about what hooks to perform when performing a transition

func (Transition) String

func (t Transition) String() string

type User

type User struct {
	Username   string   `json:"username" bson:"_id" required:"true"`
	Password   string   `json:"password,omitempty" required:"true"`
	Email      string   `json:"email" required:"true"`
	FullName   string   `json:"fullName" required:"true"`
	ProfilePic string   `json:"profilePicture" `
	IsAdmin    bool     `json:"isAdmin,omitempty"`
	IsActive   bool     `json:"isActive,omitempty"`
	Settings   Settings `json:"settings,omitempty"`

	Roles []UserRole `json:"roles"`
}

User represents a user of our application

func NewUser

func NewUser(username, password, fullName, email string, admin bool) (*User, error)

NewUser will create the user after encrypting the password with bcrypt

func (User) CheckPw

func (u User) CheckPw(pw []byte) bool

CheckPw will verify if the given password matches for this user. Logs any errors it encounters

func (User) ProjectsMemberOf

func (u User) ProjectsMemberOf() []string

ProjectsMemberOf returns an array of project keys which this user has a role in.

func (User) RolesForProject

func (u User) RolesForProject(p Project) []Role

RolesForProject will return an array of the roles a this user has for the given project.

func (User) Sanitize

func (u User) Sanitize() interface{}

Sanitize implements models.Sanitizer so that we don't send sensitive info back to the client

func (User) String

func (u User) String() string

type UserRole

type UserRole struct {
	Role    Role   `json:"role"`
	Project string `json:"project"`
}

UserRole is a mapping of a user to a role

type Users

type Users []User

Users is an alias for a slice of Users which implements Sanitize

func (Users) Sanitize

func (ur Users) Sanitize() interface{}

Sanitize implements models.Sanitizer so that we don't send sensitive info back to the client

type Workflow

type Workflow struct {
	ID          bson.ObjectId `json:"id" bson:"_id,omitempty"`
	Name        string        `json:"name" required:"true"`
	Transitions []Transition  `json:"transitions" required:"true"`
}

Workflow is the container for issues and keeps track of available transitions

func (Workflow) CreateTransition

func (w Workflow) CreateTransition() Transition

CreateTransition will return the transition to perform on a ticket during creation

func (Workflow) String

func (w Workflow) String() string

type WorkflowMapping

type WorkflowMapping struct {
	Workflow   bson.ObjectId `json:"workflow"`
	TicketType string        `json:"ticket_type"`
}

WorkflowMapping maps a ticket type to a workflow

Directories

Path Synopsis
Package permission is used to store the various permission in praelatus, it acts as a pseudo-enumeration
Package permission is used to store the various permission in praelatus, it acts as a pseudo-enumeration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL