database

package
v0.0.0-...-dd30ea9 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account interface {
	SessionDb() Session
	SetSessionDb(item *Session)

	UserDb() User
	SetUserDb(item *User)

	//Tries to load an user given its id or email
	FullLoadUser(tx interface{}, user *domain.User) error

	//Creates a new session object and increases the login count
	//If validatePassword parameter is false, then no authentication method is used
	LoginUser(tx interface{}, email, password string, ipaddress string, validatePassword bool) (*domain.Session, error)

	//Removes the active session for the connected user
	LogoutUser(tx interface{}) error

	//Changes the password of any user
	ChangePassword(tx interface{}, id string, password string) error

	//Changes the password for the connected user
	ChangeMyPassword(tx interface{}, password string) error

	//Delays the session expire date based on the duration provided as parameter
	LoginDelay(tx interface{}, delay time.Duration) error

	//Creates a token for password recovery
	PasswordRecoverCreateToken(tx interface{}, user *domain.User) error

	//Verifies the token for password recovery is good.
	VerifyTokenEmail(tx interface{}, user *domain.User, ipaddress string) error
}

type Bootstrap

type Bootstrap interface {
	PriorityDb() Priority
	SetPriorityDb(item *Priority)

	StatusDb() Status
	SetStatusDb(item *Status)

	UserDb() User
	SetUserDb(item *User)

	//Bootstraps the database and configuration for the first time the app runs
	//database and db objects must exist before this method is executed
	BootstrapAll(tx interface{}, conn *setup.ConfigurationDatabase, environment string, chdir string) error

	//Creates the first admin user in database, if it already exists returns true on first return value
	BootstrapAdminUser(tx interface{}) (exists bool, admin *domain.User, err error)

	//Make the chdir point to the root of the application
	ResetApplicationPath(chdir string) error

	//Executes any migration tool to upgrade db objects and data
	UpgradeDbScripts(conn *setup.ConfigurationDatabase, environment string, chdir string) error

	//Bootstraps all the permission names
	CreatePermissionNames(tx interface{}) error

	//Add basic workflows as part of the startup
	BootstrapWorkflows(tx interface{}) error

	//Add some values to catalog
	BootstrapPriorities(tx interface{}) error
}

type CurrentSession

type CurrentSession interface {
	CurrentSession() *domain.Session
	SetCurrentSession(user *domain.Session)
}

Defines operations with connected users

type Db

type Db interface {

	//Creates a new database transaction and returns its object
	Begin() (interface{}, error)

	//Commmits a database transaction
	Commit(tran interface{}) error

	//Rollbacks a database transaction
	Rollback(tran interface{}) error

	//Starts the SQL Tracing
	SqlTraceOn()

	//Stops the SQL Tracing
	SqlTraceOff()

	//If the engine is compatible with any relational database,
	//it will register all the internal structs to tables
	Register()

	//Contains the object which holds information about the current session connected
	//to the system
	CurrentSession

	//Closes the db connections and releases resources
	Close()
}

base del db

type DbOperations

type DbOperations struct {
	//Main database implementation
	Db Db

	//Login, authentication operations
	AccountDb Account

	//ERP Bootstrap operations
	BootstrapDb Bootstrap

	//FileItem operations
	FileItemDb FileItem

	//Issue, IssueAttachment, IssueComment and IssueSubscription operations
	IssueDb Issue

	//PermissionName, PermissionScheme, PermissionSchemeItem operations
	PermissionDb Permission

	//Priority operations
	PriorityDb Priority

	//Project, ProjectRole and ProjectRoleMember operations
	ProjectDb Project

	//Session manager
	SessionDb Session

	//Status, Workflow and WorkflowStep operations
	StatusDb Status

	//User, UserGroup, Group and Role operations
	UserDb User
}

Container of all db operations

type FileFilter

type FileFilter struct {
	YearMonth string
}

Filter used to query the DirectoryGrid

type FileItem

type FileItem interface {

	//Creates a new FileItem in database
	Create(tx interface{}, item *domain.FileItem) error

	//Retrieves a FileItem object along with the data it contains
	Data(tx interface{}, id string) (*domain.FileItem, error)

	//Loads only the metadata of the FileItem without the data
	Load(tx interface{}, id string) (*domain.FileItem, error)

	//Removes the metadata and file data from database
	Remove(tx interface{}, id string) (*domain.FileItem, error)

	//Returs a grid based on information splitted by year and month simulating a directory structure
	DirectoryGrid(tx interface{}, grid *tecgrid.NgGrid) error

	//Returns a grid of files
	FileGrid(tx interface{}, grid *tecgrid.NgGrid, filter *FileFilter) error
}

type Issue

type Issue interface {
	FileItemDb() FileItem
	SetFileItemDb(item *FileItem)

	PermissionDb() Permission
	SetPermissionDb(item *Permission)

	PriorityDb() Priority
	SetPriorityDb(item *Priority)

	ProjectDb() Project
	SetProjectDb(item *Project)

	StatusDb() Status
	SetStatusDb(item *Status)

	UserDb() User
	SetUserDb(item *User)

	//Adds an attachment to an issue
	AttachmentAdd(tx interface{}, issue *domain.Issue, item *domain.FileItem) (*domain.IssueAttachment, error)

	//Loads an Attachment from database along with inner objects
	AttachmentLoad(tx interface{}, id string) (*domain.IssueAttachment, error)

	//Removes an Attachment from database along with the FileItem it is related
	AttachmentRemove(tx interface{}, attachment *domain.IssueAttachment) error

	//Returns a list of attachments for a given issue
	AttachmentList(tx interface{}, issue *domain.Issue) ([]domain.IssueAttachment, error)

	//Removes all the attachments from a given issue
	AttachmentRemoveAll(tx interface{}, issue *domain.Issue) error

	//Returns the list of comments for a given issue
	CommentList(tx interface{}, issue *domain.Issue) ([]domain.IssueComment, error)

	//Adds a comment to a given issue
	CommentAdd(tx interface{}, comment *domain.IssueComment) error

	//Retrieves a comment from database by its id
	CommentLoad(tx interface{}, id string) (*domain.IssueComment, error)

	//Updates a comment in database
	CommentUpdate(tx interface{}, comment *domain.IssueComment) error

	//Removes a comment from database
	CommentRemove(tx interface{}, id string) (*domain.IssueComment, error)

	//Removes all the comments that are related with a given issue
	CommentRemoveAll(tx interface{}, issue *domain.Issue) error

	//Returns a query grouping pending issues by assignee
	DashbordIssueGroupByAssignee(tx interface{}, filter *IssueGroupFilter) ([]IssueGroupResult, error)

	//Returns a query grouping pending issues by reporter
	DashbordIssueGroupByReporter(tx interface{}, filter *IssueGroupFilter) ([]IssueGroupResult, error)

	//Returns a query grouping pending issues by priority
	DashboardIssueGroupByPriority(tx interface{}, filter *IssueGroupFilter) ([]IssueGroupResult, error)

	//Returns a query grouping pending issues by status
	DashboardIssueGroupByStatus(tx interface{}, filter *IssueGroupFilter) ([]IssueGroupResult, error)

	//Returns a query grouping pending issues by project
	DashboardIssueGroupByProject(tx interface{}, filter *IssueGroupFilter) ([]IssueGroupResult, error)

	//Returns a query grouping pending issues by year/month of dueDate
	DashbordIssueGroupByDueDate(tx interface{}, filter *IssueGroupFilter) ([]IssueGroupResult, error)

	//Changes the status of a given issue and takes as parameter a func to process if there are no errors
	StatusChange(tx interface{}, issue *domain.Issue, status *domain.Status, fn IssueStatusFn) error

	//Returns the list of users subscribed to a given issue
	Subscribers(tx interface{}, issue *domain.Issue, excludeCurrentUser bool) (items []domain.User, err error)

	//Returns a list of the subscriptions the current session users' has been subscribed
	MySubscriptions(tx interface{}, grid *tecgrid.NgGrid) error

	//Processes a grid with all the subscriptions for a given user
	SubscriptionsUser(tx interface{}, grid *tecgrid.NgGrid, user *domain.User) error

	//Subscribes or unsubscribes the connected user with an Issue
	SubscriptionToggle(tx interface{}, issue *domain.Issue) (selected bool, err error)

	//Subscribes or unsubscribes a given user with an Issue
	SubscriptionToggleUser(tx interface{}, issue *domain.Issue, user *domain.User) (selected bool, err error)

	//Returns true if the given user is subscribed, false if he is not
	IsSubscribed(tx interface{}, issue *domain.Issue, user *domain.User) (ok bool, err error)

	//Returns a list of users subscribed/unsubscribed to a given issue
	SubscribersIssue(tx interface{}, issue *domain.Issue) (selected []domain.User, unselected []domain.User, err error)

	//Adds a subscription to a given issue
	SubscriptionAdd(tx interface{}, issue *domain.Issue, user *domain.User) error

	//Creates an issue
	Create(tx interface{}, item *domain.Issue, parent string) error

	//Loads an issue along with its inner objects
	Load(tx interface{}, id string, pkey string) (*domain.Issue, error)

	//Removes an issue from database
	Remove(tx interface{}, id string) (*domain.Issue, error)

	//Returns the id of the root issue for a given issue
	FindRoot(tx interface{}, id string) (root string, err error)

	//Updates an issue in database
	Update(tx interface{}, u *domain.Issue) error

	//Processes the grid query for issues applying permissions when requiered
	Grid(tx interface{}, grid *tecgrid.NgGrid, filter *IssueFilter) error

	//Gets all the slibings at the first level for a given issue
	Children(tx interface{}, issue *domain.Issue) ([]IssueGrid, error)

	//Updates an Issue moving the project from where it belongs. A new pkey is assigned and new
	//permissions will apply depending on the new project configuration
	MoveProject(tx interface{}, issue *domain.Issue, target *domain.Project) (*domain.Issue, error)
}

type IssueFilter

type IssueFilter struct {
	domain.Issue
	Parent   *domain.Issue `json:"parent"`
	Due      sql.NullBool
	Resolved sql.NullBool
	DueDate  *time.Time
}

type IssueGrid

type IssueGrid struct {
	domain.Issue
	Reporter  string         `json:"reporter"`
	Priority  string         `json:"priority"`
	Status    string         `json:"status"`
	Project   string         `json:"project"`
	Assignee  string         `json:"assignee"`
	ParentKey string         `json:"parent" db:"parent"`
	IdParent  sql.NullString `json:"-"`
}

type IssueGroupFilter

type IssueGroupFilter struct {
	Project  string
	Assignee string
	Reporter string
	Status   string
}

type IssueGroupResult

type IssueGroupResult struct {
	Id       string `json:"id"`
	Name     string `json:"name"`
	RowCount int64  `json:"rowCount"`
	DataType string `json:"dataType"`
}

type IssueStatusFn

type IssueStatusFn func(tx interface{}, oldItem *domain.Issue, nextStep *domain.WorkflowStep, oldStatus *domain.Status, newStatus *domain.Status) error

Lambda that can be passed as required when an Issue status has changed

type Permission

type Permission interface {
	ProjectDb() Project
	SetProjectDb(item *Project)

	UserDb() User
	SetUserDb(item *User)

	//Returns a list of all the permission names in database
	Names(tx interface{}) ([]domain.PermissionName, error)

	//Given an user and a permission name, optionaly also an Issue (evaluating the project where it belongs to)
	//Evaluates if the access is granted or not
	AllowedUser(tx interface{}, user *domain.User, issue *domain.Issue, permission *domain.PermissionName) (ok bool, err error)

	//Given an user and optionaly an Issue, returns the list of permission names the user can access
	AvailablesUser(tx interface{}, user *domain.User, issue *domain.Issue) ([]domain.PermissionName, error)

	//Creates a new permission scheme item
	ItemAdd(tx interface{}, item *domain.PermissionSchemeItem) error

	//Loads a permission scheme item
	ItemLoad(tx interface{}, item *domain.PermissionSchemeItem) (*domain.PermissionSchemeItem, error)

	//Removes a permission scheme item
	ItemRemove(tx interface{}, item *domain.PermissionSchemeItem) error

	//Returns a list of all permission scheme items that belong to a given permission scheme and user
	Items(tx interface{}, item *domain.PermissionScheme) ([]domain.PermissionSchemeItem, error)

	//Creates a permission scheme on database
	Create(tx interface{}, item *domain.PermissionScheme) error

	//Updates a permission scheme in database
	Update(tx interface{}, item *domain.PermissionScheme) error

	//Loads the permission scheme from database
	Load(tx interface{}, id string) (*domain.PermissionScheme, error)

	//Returns a list of all the permission schemes available
	List(tx interface{}) ([]domain.PermissionScheme, error)

	//Removes a permission scheme from database
	Remove(tx interface{}, id string) (*domain.PermissionScheme, error)

	//Processes a grid query for permission schemes
	Grid(tx interface{}, grid *tecgrid.NgGrid) error

	//Returns a list of all the projects which are using a given permission scheme
	Projects(tx interface{}, item *domain.PermissionScheme) ([]ProjectQuery, error)

	//Clears all the permission scheme items for a given permission scheme
	ClearAll(tx interface{}, item *domain.PermissionScheme) error
}

type Priority

type Priority interface {

	//Creates a new priority in database
	Create(tx interface{}, priority *domain.Priority) error

	//Loads a priority from database
	Load(tx interface{}, id string) (*domain.Priority, error)

	//Removes a priority from database
	Remove(tx interface{}, id string) (*domain.Priority, error)

	//Updates a priority in database
	Update(tx interface{}, priority *domain.Priority) error

	//Returns a list of all the priorities in database
	List(tx interface{}) ([]domain.Priority, error)

	//Returns the first priority available in database
	GetFirst(tx interface{}) (*domain.Priority, error)

	//Processes a query grid of priorities
	Grid(tx interface{}, grid *tecgrid.NgGrid) error

	ValidateDups(tx interface{}, item *domain.Priority) error
}

type Project

type Project interface {
	PermissionDb() Permission
	SetPermissionDb(item *Permission)

	UserDb() User
	SetUserDb(item *User)

	//Creates a project in database
	Create(tx interface{}, item *domain.Project) error

	//Loads a project from database including inner objects
	Load(tx interface{}, id string) (*domain.Project, error)

	//Loads just the basic project information from database
	LoadSimple(tx interface{}, id string) (*domain.Project, error)

	//Removes a project from database
	Remove(tx interface{}, id string) (*domain.Project, error)

	//Updates a project in datebase
	Update(tx interface{}, item *domain.Project) error

	//Processes a query grid of projects applying permissions on the connected user
	Grid(tx interface{}, grid *tecgrid.NgGrid, filter *ProjectFilter) error

	//Generates a simulated sequence next number for a given project
	NextNumber(tx interface{}, id string) (*domain.Project, error)

	//Checks for duplicated projects in database based in the name or pkey
	ValidateDups(tx interface{}, item *domain.Project) error

	//Returns the project data along with other dependencies for the UI
	CreateMeta(tx interface{}, id string) (*ProjectMeta, error)

	//Adds a project role to a project
	RoleAdd(tx interface{}, item *domain.ProjectRole) error

	//Removes a project role from a project
	RoleRemove(tx interface{}, item *domain.ProjectRole) error

	//Loads a project role from a project
	RoleLoad(tx interface{}, project *domain.Project, role *domain.Role) (*domain.ProjectRole, error)

	//Returns all the project roles that a given user for a given project can access
	Roles(tx interface{}, item *domain.Project) ([]domain.ProjectRole, error)

	//Generates all the rows of project roles for a given project
	RoleCreateAll(tx interface{}, item *domain.Project) error

	//Loads a member for a project role, along with its group, role or user related
	RoleMemberLoad(tx interface{}, project *domain.Project, role *domain.Role, user *domain.User, group *domain.Group) (*domain.ProjectRoleMember, error)

	//Creates a new member to the project role
	RoleMemberAdd(tx interface{}, projectRole *domain.ProjectRole, user *domain.User, group *domain.Group) error

	//Removes a member from the project role
	RoleMemberRemove(tx interface{}, item *domain.ProjectRoleMember) error

	//Returns a list of project role members for a given project role
	RoleMembers(tx interface{}, item *domain.ProjectRole) ([]domain.ProjectRoleMember, error)

	//Returns a list of project role members for a given project
	RoleProjectMembers(tx interface{}, item *domain.Project) ([]domain.ProjectRoleMember, error)
}

type ProjectFilter

type ProjectFilter struct {
	ProjectLead string
	Resolved    sql.NullBool
}

type ProjectMeta

type ProjectMeta struct {
	Item         *domain.Project      `json:"item"`
	Users        []domain.User        `json:"users"`
	ProjectRoles []domain.ProjectRole `json:"projectRoles"`
}

type ProjectQuery

type ProjectQuery struct {
	domain.Project
	ProjectLead         string  `json:"projectLead"`
	PercentageCompleted float64 `json:"percentageCompleted"`
	PermissionScheme    string  `json:"permissionScheme"`
}

type Session

type Session interface {
	UserDb() User
	SetUserDb(item *User)

	//Returns a list of all the active sessions for a given user
	List(tx interface{}, user *domain.User) ([]domain.Session, error)

	//Loads the session from database
	Load(tx interface{}, token string) (*domain.Session, error)

	//Removes the session from database
	Remove(tx interface{}, token string, validateCurrentSession bool) error

	//Updates the session from database
	Update(tx interface{}, session *domain.Session) error

	//Creates a new session for a login user
	Create(tx interface{}, session *domain.Session) error

	//Middleware function to retrieve the current session based on the token provided
	ValidateToken(tx interface{}, token string) (*domain.Session, error)
}

type Status

type Status interface {
	UserDb() User
	SetUserDb(item *User)

	//Loads a status object from database
	Load(tx interface{}, id string) (*domain.Status, error)

	//Creates a new status in database
	Create(tx interface{}, item *domain.Status) error

	//Updates a status in database
	Update(tx interface{}, item *domain.Status) error

	//Removes a status from database
	Remove(tx interface{}, id string) (*domain.Status, error)

	//List all of the statuses the are related with a given Workflow object
	List(tx interface{}, workflow *domain.Workflow) ([]domain.Status, error)

	//Loads a Workflow object from database
	WorkflowLoad(tx interface{}, id string) (item *domain.Workflow, err error)

	//Creates a new Workflow object in database
	WorkflowCreate(tx interface{}, item *domain.Workflow) error

	//Updates a Workflow object in database
	WorkflowUpdate(tx interface{}, item *domain.Workflow) error

	//Removes a Workflow object from database
	WorkflowRemove(tx interface{}, id string) (*domain.Workflow, error)

	//Returns a list of all the Workflows available in database
	WorkflowList(tx interface{}) ([]domain.Workflow, error)

	//Processes a grid query of Workflow objects
	WorkflowGrid(tx interface{}, grid *tecgrid.NgGrid) error

	//Checks for duplicated steps for a given status
	WorkflowStepDups(tx interface{}, step *domain.WorkflowStep) error

	WorkflowStepLoad(tx interface{}, id string) (*domain.WorkflowStep, error)

	//Retrieves a list of all the WorkflowSteps related with a given Workflow object
	WorkflowSteps(tx interface{}, workflow *domain.Workflow) ([]domain.WorkflowStep, error)

	//Creates a new WorkflowStep object in database
	WorkflowStepCreate(tx interface{}, step *domain.WorkflowStep) error

	//Updates a WorkflowStep object in database
	WorkflowStepUpdate(tx interface{}, step *domain.WorkflowStep) error

	//Removes a WorkflowStep object from database
	WorkflowStepRemove(tx interface{}, id string) (*domain.WorkflowStep, error)

	//Returns a list of all the WorkflowSteps that can be applied for a given status
	WorkflowStepAvailableStatus(tx interface{}, workflow *domain.Workflow, prevStatus *domain.Status) ([]domain.WorkflowStep, error)

	//Returns a list of all the WorkflowSteps that can be applied for a given status and a given
	//user, based on his permissions
	WorkflowStepAvailableUser(tx interface{}, workflow *domain.Workflow, prevStatus *domain.Status) ([]domain.WorkflowStep, error)

	//Loads a WorkflowStep member along with its inner objects (groups and users)
	WorkflowStepMemberLoad(tx interface{}, item *domain.WorkflowStepMember) (*domain.WorkflowStepMember, error)

	//Returns a list of all the groups that are related with a WorkflowStep
	WorkflowStepMemberGroups(tx interface{}, item *domain.WorkflowStep) (selected []domain.Group, unselected []domain.Group, err error)

	//Returns a list of all the users that are related with a WorkflowStep
	WorkflowStepMemberUsers(tx interface{}, item *domain.WorkflowStep) (selected []domain.User, unselected []domain.User, err error)

	//Adds a group or user to a WorkflowStep
	WorkflowStepMemberAdd(tx interface{}, item *domain.WorkflowStepMember) error

	//Removes a group or user from a WorkflowStep
	WorkflowStepMemberRemove(tx interface{}, item *domain.WorkflowStepMember) error

	//Returns all the members (users and groups) for a given WorkflowStep
	WorkflowStepMembers(tx interface{}, item *domain.WorkflowStep) ([]domain.WorkflowStepMember, error)

	WorkflowCreateMeta(tx interface{}, item *domain.Workflow) (*WorkflowMeta, error)
}

type User

type User interface {
	AccountDb() Account
	SetAccountDb(item *Account)

	//Counts the number of sys admin users that are active in database
	CountSystemAdministrators(tx interface{}) (int64, error)

	//Creates a new user in database
	Create(tx interface{}, item *domain.User) error

	//Loads an user and inner objects
	Load(tx interface{}, id string) (*domain.User, error)

	//Removes an user from database
	Remove(tx interface{}, id string) (*domain.User, error)

	//Updates an user in database
	Update(tx interface{}, item *domain.User) error

	//Returns a list of all the users in database
	List(tx interface{}) ([]domain.User, error)

	//Processes a grid query of User objects
	Grid(tx interface{}, grid *tecgrid.NgGrid) error

	//Creates a new group of users
	GroupCreate(tx interface{}, item *domain.Group) (err error)

	//Loads a group from database
	GroupLoad(tx interface{}, id string) (item *domain.Group, err error)

	//Removes a group from database
	GroupRemove(tx interface{}, id string) (item *domain.Group, err error)

	//Updates a group in database
	GroupUpdate(tx interface{}, item *domain.Group) (err error)

	//Returns a list of all the groups in database
	GroupList(tx interface{}) (items []domain.Group, err error)

	//Processes a grid query of groups in database
	GroupGrid(tx interface{}, grid *tecgrid.NgGrid) (err error)

	//Return the selected and unselected groups for a given User object
	UserGroupListGroups(tx interface{}, u *domain.User) (selected []domain.Group, unselected []domain.Group, err error)

	//Returns the selected and unselected users for a given Group object
	UserGroupListUsers(tx interface{}, g *domain.Group) (selected []domain.User, unselected []domain.User, err error)

	//Adds an User to a Group or vice versa
	UserGroupAdd(tx interface{}, u *domain.UserGroup) error

	//Removes an User to a Group
	UserGroupRemove(tx interface{}, u *domain.UserGroup) error

	//Returns true if the user is a member of the group
	UserGroupIsMember(tx interface{}, group *domain.Group, user *domain.User) (ok bool, err error)

	//Creates a new role in database
	RoleCreate(tx interface{}, item *domain.Role) error

	//Updates a role in database
	RoleUpdate(tx interface{}, item *domain.Role) error

	//Loads a role from database
	RoleLoad(tx interface{}, id string) (*domain.Role, error)

	//Returns a list of roles from database
	RoleList(tx interface{}) ([]domain.Role, error)

	//Removes a role from database
	RoleRemove(tx interface{}, id string) (*domain.Role, error)

	//Processes a grid query of roles
	RoleGrid(tx interface{}, grid *tecgrid.NgGrid) error
}

type WorkflowMeta

type WorkflowMeta struct {
	Item     *domain.Workflow      `json:"item"`
	Steps    []domain.WorkflowStep `json:"steps"`
	Statuses []domain.Status       `json:"statuses"`
}

Jump to

Keyboard shortcuts

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