permissions

package
v5.5.4 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	All          = "*"
	ActionList   = "list"
	ActionGet    = "get"
	ActionCreate = "create"
	ActionUpdate = "update"
	ActionDelete = "delete"
	ActionSearch = "search"
	ActionAccess = "access"

	TypeUser              = "user"
	TypePermission        = "permission"
	TypeRole              = "role"
	TypeFact              = "fact"
	TypeRule              = "rule"
	TypeSituation         = "situation"
	TypeSituationInstance = "situation_instance"
	TypeSituationFacts    = "situation_fact"
	TypeSituationRules    = "situation_rule"
	TypeSituationIssues   = "situation_issue"
	TypeScheduler         = "scheduler"
	TypeCalendar          = "calendar"
	TypeModel             = "model"
	TypeFrontend          = "frontend"
	TypeExport            = "export"
	TypeService           = "service"
)

Variables

This section is empty.

Functions

func GetResourceIDs added in v5.3.6

func GetResourceIDs(permissions []Permission) []string

GetResourceIDs returns a list of resource IDs from a list of permissions

func HasPermission

func HasPermission(permissions []Permission, required Permission) bool

HasPermission checks if the user has the required permission

func HasPermissionAll

func HasPermissionAll(permissions []Permission, requiredAll []Permission) bool

HasPermissionAll checks if the user has all the required permissions

func HasPermissionAtLeastOne

func HasPermissionAtLeastOne(permissions []Permission, requiredAtLeastOne []Permission) bool

HasPermissionAtLeastOne checks if the user has at least one of the required permissions

func ReplaceGlobals

func ReplaceGlobals(repository Repository) func()

ReplaceGlobals affect a new repository to the global repository singleton

Types

type Permission

type Permission struct {
	ID           uuid.UUID `json:"id"`
	ResourceType string    `json:"resourceType"`
	ResourceID   string    `json:"resourceId"`
	Action       string    `json:"action"`
}

func ListMatchingPermissions

func ListMatchingPermissions(permissions []Permission, match Permission) []Permission

ListMatchingPermissions returns a list of permissions matching the given permission

func New

func New(resourceType string, resourceID string, action string) Permission

New returns a new Permission

type PostgresRepository

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

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

func (*PostgresRepository) Create

func (r *PostgresRepository) Create(permission Permission) (uuid.UUID, error)

Create creates a new User Permission in the repository

func (*PostgresRepository) Delete

func (r *PostgresRepository) Delete(uuid uuid.UUID) error

Delete deletes an User Permission in the repository

func (*PostgresRepository) Get

func (r *PostgresRepository) Get(permissionUUID uuid.UUID) (Permission, bool, error)

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

func (*PostgresRepository) GetAll

func (r *PostgresRepository) GetAll() ([]Permission, error)

GetAll returns all User Permissions in the repository

func (*PostgresRepository) GetAllForRole

func (r *PostgresRepository) GetAllForRole(roleUUID uuid.UUID) ([]Permission, error)

GetAll returns all User Permissions in the repository

func (*PostgresRepository) GetAllForRoles

func (r *PostgresRepository) GetAllForRoles(roleUUID []uuid.UUID) ([]Permission, error)

func (*PostgresRepository) GetAllForUser

func (r *PostgresRepository) GetAllForUser(userUUID uuid.UUID) ([]Permission, error)

func (*PostgresRepository) Update

func (r *PostgresRepository) Update(permission Permission) error

Update updates an User Permission in the repository

type Repository

type Repository interface {
	Get(uuid uuid.UUID) (Permission, bool, error)
	Create(permission Permission) (uuid.UUID, error)
	Update(permission Permission) error
	Delete(uuid uuid.UUID) error
	GetAll() ([]Permission, error)

	GetAllForRole(roleUUID uuid.UUID) ([]Permission, error)
	GetAllForRoles(roleUUID []uuid.UUID) ([]Permission, error)
	GetAllForUser(userUUID uuid.UUID) ([]Permission, 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

Jump to

Keyboard shortcuts

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