groups

package
v4.1.14 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// AllGroups SQL statement for the issues table
	AllGroups int64 = 0
)

This is the universal token of groups, giving access as if it was all the groups

Variables

This section is empty.

Functions

func DeleteTokenAllGroups

func DeleteTokenAllGroups(groups []int64) []int64

DeleteTokenAllGroups delete the universal token from groups

func GetTokenAllGroups

func GetTokenAllGroups() []int64

GetTokenAllGroups gets the array with the universal token group

func ReplaceGlobals

func ReplaceGlobals(repository Repository) func()

ReplaceGlobals affect a new repository to the global repository singleton

Types

type Group

type Group struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
}

Group user group

func (*Group) IsValid

func (group *Group) IsValid() (bool, error)

IsValid checks if a group definition is valid and has no missing mandatory fields

type GroupOfUser

type GroupOfUser struct {
	ID       int64  `json:"id"`
	Name     string `json:"name"`
	UserRole int64  `json:"groupRole" db:"role"`
}

GroupOfUser group of a user

type Membership

type Membership struct {
	UserID  int64 `json:"userId"`
	GroupID int64 `json:"groupId"`
	Role    int64 `json:"role"`
}

Membership relation between users and groups

func (*Membership) IsValid

func (membership *Membership) IsValid() (bool, error)

IsValid checks if a group definition is valid and has no missing mandatory fields

type PostgresRepository

type PostgresRepository struct {
	// contains filtered or unexported fields
}

PostgresRepository is a repository containing the user groups data based on a PSQL database and implementing the repository interface

func (*PostgresRepository) Create

func (r *PostgresRepository) Create(group Group) (int64, error)

Create creates a new User Group in the repository

func (*PostgresRepository) CreateMembership

func (r *PostgresRepository) CreateMembership(membership Membership) error

CreateMembership creates a new User Membership in the repository

func (*PostgresRepository) Delete

func (r *PostgresRepository) Delete(id int64) error

Delete deletes an User Group in the repository

func (*PostgresRepository) DeleteMembership

func (r *PostgresRepository) DeleteMembership(userID int64, groupID int64) error

DeleteMembership deletes an User Membership in the repository

func (*PostgresRepository) Get

func (r *PostgresRepository) Get(id int64) (Group, bool, error)

Get search and returns an User Group from the repository by its id

func (*PostgresRepository) GetAll

func (r *PostgresRepository) GetAll() (map[int64]Group, error)

GetAll returns all User Groups in the repository

func (*PostgresRepository) GetByName

func (r *PostgresRepository) GetByName(name string) (Group, bool, error)

GetByName search and returns an User Group from the repository by its name

func (*PostgresRepository) GetGroupsOfUser

func (r *PostgresRepository) GetGroupsOfUser(userID int64) ([]GroupOfUser, error)

GetGroupsOfUser returns all User Groups of a User in the repository

func (*PostgresRepository) GetMembership

func (r *PostgresRepository) GetMembership(userID int64, groupID int64) (Membership, bool, error)

GetMembership search and returns an User membership

func (*PostgresRepository) Update

func (r *PostgresRepository) Update(group Group) error

Update updates an User Group in the repository

func (*PostgresRepository) UpdateMembership

func (r *PostgresRepository) UpdateMembership(membership Membership) error

UpdateMembership updates an User Membership in the repository

type Repository

type Repository interface {
	Get(id int64) (Group, bool, error)
	GetByName(name string) (Group, bool, error)
	Create(group Group) (int64, error)
	Update(group Group) error
	Delete(id int64) error
	GetAll() (map[int64]Group, error)

	GetMembership(userID int64, groupID int64) (Membership, bool, error)
	CreateMembership(membership Membership) error
	UpdateMembership(membership Membership) error
	DeleteMembership(userID int64, groupID int64) error

	GetGroupsOfUser(userID int64) ([]GroupOfUser, error)
}

Repository is a storage interface which can be implemented by multiple backend (in-memory map, sql database, in-memory cache, file system, ...) It allows standard CRUD operation on facts

func NewPostgresRepository

func NewPostgresRepository(dbClient *sqlx.DB) Repository

NewPostgresRepository returns a new instance of PostgresRepository

func R

func R() Repository

R is used to access the global repository singleton

type UserWithGroups

type UserWithGroups struct {
	security.User
	Groups []GroupOfUser `json:"groups"`
}

UserWithGroups embed the standard User struct with his groups

Jump to

Keyboard shortcuts

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