Documentation ¶
Index ¶
- Constants
- func GetResourceIDs(permissions []Permission) []string
- func HasPermission(permissions []Permission, required Permission) bool
- func HasPermissionAll(permissions []Permission, requiredAll []Permission) bool
- func HasPermissionAtLeastOne(permissions []Permission, requiredAtLeastOne []Permission) bool
- func ReplaceGlobals(repository Repository) func()
- type Permission
- type PostgresRepository
- func (r *PostgresRepository) Create(permission Permission) (uuid.UUID, error)
- func (r *PostgresRepository) Delete(uuid uuid.UUID) error
- func (r *PostgresRepository) Get(permissionUUID uuid.UUID) (Permission, bool, error)
- func (r *PostgresRepository) GetAll() ([]Permission, error)
- func (r *PostgresRepository) GetAllForRole(roleUUID uuid.UUID) ([]Permission, error)
- func (r *PostgresRepository) GetAllForRoles(roleUUID []uuid.UUID) ([]Permission, error)
- func (r *PostgresRepository) GetAllForUser(userUUID uuid.UUID) ([]Permission, error)
- func (r *PostgresRepository) Update(permission Permission) error
- type Repository
Constants ¶
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" )
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
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