Documentation ¶
Index ¶
- func ReplaceGlobals(repository Repository) func()
- type PostgresRepository
- func (r *PostgresRepository) Create(user UserWithPassword) (uuid.UUID, error)
- func (r *PostgresRepository) Delete(uuid uuid.UUID) error
- func (r *PostgresRepository) Get(userUUID uuid.UUID) (User, bool, error)
- func (r *PostgresRepository) GetAll() ([]User, error)
- func (r *PostgresRepository) GetAllForRole(roleUUID uuid.UUID) ([]User, error)
- func (r *PostgresRepository) SetUserRoles(userUUID uuid.UUID, roleUUIDs []uuid.UUID) error
- func (r *PostgresRepository) Update(user User) error
- func (r *PostgresRepository) UpdateWithPassword(user UserWithPassword) error
- type Repository
- type User
- type UserWithPassword
- type UserWithPermissions
- func (u UserWithPermissions) GetMatchingResourceIDs(match permissions.Permission) []string
- func (u UserWithPermissions) GetMatchingResourceIDsInt64(match permissions.Permission) []int64
- func (u UserWithPermissions) GetPermissionUUIDs() []uuid.UUID
- func (u UserWithPermissions) GetRolesUUIDs() []uuid.UUID
- func (u UserWithPermissions) HasPermission(required permissions.Permission) bool
- func (u UserWithPermissions) HasPermissionAll(requiredAll []permissions.Permission) bool
- func (u UserWithPermissions) HasPermissionAtLeastOne(requiredAtLeastOne []permissions.Permission) bool
- func (u UserWithPermissions) ListMatchingPermissions(match permissions.Permission) []permissions.Permission
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReplaceGlobals ¶
func ReplaceGlobals(repository Repository) func()
ReplaceGlobals affect a new repository to the global repository singleton
Types ¶
type PostgresRepository ¶
type PostgresRepository struct {
// contains filtered or unexported fields
}
PostgresRepository is a repository containing the user users data based on a PSQL database and implementing the repository interface
func (*PostgresRepository) Create ¶
func (r *PostgresRepository) Create(user UserWithPassword) (uuid.UUID, error)
Create creates a new User in the repository
func (*PostgresRepository) Delete ¶
func (r *PostgresRepository) Delete(uuid uuid.UUID) error
Delete deletes an User in the repository
func (*PostgresRepository) GetAll ¶
func (r *PostgresRepository) GetAll() ([]User, error)
GetAll returns all Users in the repository
func (*PostgresRepository) GetAllForRole ¶
func (r *PostgresRepository) GetAllForRole(roleUUID uuid.UUID) ([]User, error)
GetAll returns all Users in the repository
func (*PostgresRepository) SetUserRoles ¶
func (*PostgresRepository) Update ¶
func (r *PostgresRepository) Update(user User) error
Update updates an User in the repository
func (*PostgresRepository) UpdateWithPassword ¶
func (r *PostgresRepository) UpdateWithPassword(user UserWithPassword) error
Update updates an User in the repository
type Repository ¶
type Repository interface { Get(uuid uuid.UUID) (User, bool, error) Create(user UserWithPassword) (uuid.UUID, error) Update(user User) error UpdateWithPassword(user UserWithPassword) error Delete(uuid uuid.UUID) error GetAll() ([]User, error) GetAllForRole(roleUUID uuid.UUID) ([]User, error) SetUserRoles(userUUID uuid.UUID, roleUUIDs []uuid.UUID) 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
type User ¶
type User struct { ID uuid.UUID `json:"id"` Login string `json:"login"` // is the unique identifier of the user, through the different connection modes Created time.Time `json:"created"` LastName string `json:"lastName"` FirstName string `json:"firstName"` Email string `json:"email"` Phone string `json:"phone"` }
User is used as the main user struct
type UserWithPassword ¶
UserWithPassword is used to log in the user (and only this use case) The standard User struct must be used if the password is not required
func (*UserWithPassword) IsValid ¶
func (user *UserWithPassword) IsValid() (bool, error)
IsValid checks if a user with password is valid and has no missing mandatory fields * User must be valid (see User struct) * Password must not be empty * Password must not be shorter than 6 characters
type UserWithPermissions ¶
type UserWithPermissions struct { User Roles []roles.Role `json:"roles"` Permissions []permissions.Permission `json:"permissions"` }
func (UserWithPermissions) GetMatchingResourceIDs ¶
func (u UserWithPermissions) GetMatchingResourceIDs(match permissions.Permission) []string
func (UserWithPermissions) GetMatchingResourceIDsInt64 ¶
func (u UserWithPermissions) GetMatchingResourceIDsInt64(match permissions.Permission) []int64
func (UserWithPermissions) GetPermissionUUIDs ¶
func (u UserWithPermissions) GetPermissionUUIDs() []uuid.UUID
func (UserWithPermissions) GetRolesUUIDs ¶
func (u UserWithPermissions) GetRolesUUIDs() []uuid.UUID
func (UserWithPermissions) HasPermission ¶
func (u UserWithPermissions) HasPermission(required permissions.Permission) bool
func (UserWithPermissions) HasPermissionAll ¶
func (u UserWithPermissions) HasPermissionAll(requiredAll []permissions.Permission) bool
func (UserWithPermissions) HasPermissionAtLeastOne ¶
func (u UserWithPermissions) HasPermissionAtLeastOne(requiredAtLeastOne []permissions.Permission) bool
func (UserWithPermissions) ListMatchingPermissions ¶
func (u UserWithPermissions) ListMatchingPermissions(match permissions.Permission) []permissions.Permission