users

package
v4.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

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) Get

func (r *PostgresRepository) Get(userUUID uuid.UUID) (User, bool, error)

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

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 (r *PostgresRepository) SetUserRoles(userUUID uuid.UUID, roleUUIDs []uuid.UUID) error

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

func R

func R() Repository

R is used to access the global repository singleton

type User

type User struct {
	ID        uuid.UUID `json:"id"`
	Login     string    `json:"login"`
	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

func (*User) IsValid

func (user *User) IsValid() (bool, error)

IsValid checks if an user is valid and has no missing mandatory fields * Login must not be empty * Login must not be shorter than 3 characters * Role must not be empty (or 0 value) * LastName must not be empty

type UserWithPassword

type UserWithPassword struct {
	User
	Password string `json:"password" db:"password"`
}

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

Jump to

Keyboard shortcuts

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