roles

package
v0.0.0-...-8969935 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

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

*

  • This struct is used

func NewHandler

func NewHandler(userRepo users.Repo, roleRepo Repo) *Handler

*

  • This struct is used

func (*Handler) GetRoutes

func (handler *Handler) GetRoutes() []routing.Route

* Function used to get routes

type PermissionTable

type PermissionTable interface {
	/**
	Get the user with the email.  An error is thrown is not found
	*/
	GetPermissions(roleId int) []string

	//Look up the role id based upon the name
	LookUpRoleId(name string) (int, error)
}

* Define an interface for roles

type PermissionTableJson

type PermissionTableJson struct {
	//Hold a map of the strings
	Roles map[int]Role
}

* Define a struct for Repo for use with users

func NewPermissionTableJson

func NewPermissionTableJson(fileName string) *PermissionTableJson

Provide a method to make a new UserRepoSql

func (*PermissionTableJson) GetPermissions

func (repo *PermissionTableJson) GetPermissions(roleId int) []string

* Get the user with the email. An error is thrown is not found

func (*PermissionTableJson) LookUpRoleId

func (repo *PermissionTableJson) LookUpRoleId(roleLookUp string) (int, error)

* Get the role id for this name

type Permissions

type Permissions struct {
	//Store a list of
	Permissions []string `json:"permissions"`
}

* * This package is used to check for roles

func (*Permissions) AllowedTo

func (perm *Permissions) AllowedTo(tasks ...string) bool

* Check to see if the user has permission to do something

type Repo

type Repo interface {
	/**
	Get the user with the email.  An error is thrown is not found
	*/
	GetPermissions(user users.User) (*Permissions, error)

	/**
	Set the user's roles. Note this wipes out all current roles
	*/
	SetRolesByRoleId(user users.User, roles []int) error

	/**
	Set the user's roles.  Note this wipes out all current roles
	*/
	SetRolesByName(user users.User, roles []string) error
}

* Define an interface for roles

type RepoSql

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

* Define a struct for Repo for use with users

func NewRepoMySql

func NewRepoMySql(db *sql.DB, tableName string, roleRepo PermissionTable) *RepoSql

Provide a method to make a new UserRepoSql

func NewRepoPostgresSql

func NewRepoPostgresSql(db *sql.DB, tableName string, roleRepo PermissionTable) *RepoSql

Provide a method to make a new UserRepoSql

func (*RepoSql) CleanUp

func (repo *RepoSql) CleanUp()

* Clean up the database, nothing much to do

func (*RepoSql) GetPermissions

func (repo *RepoSql) GetPermissions(user users.User) (*Permissions, error)

* Get the user with the email. An error is thrown is not found

func (*RepoSql) GetRoleIds

func (repo *RepoSql) GetRoleIds(user users.User) ([]int, error)

* Get all of the roles

func (*RepoSql) SetRolesByName

func (repo *RepoSql) SetRolesByName(user users.User, roles []string) error

* Set the user's roles. Note this wipes out all current roles

func (*RepoSql) SetRolesByRoleId

func (repo *RepoSql) SetRolesByRoleId(user users.User, roles []int) error

* Get the user with the email. An error is thrown is not found

type Role

type Role struct {
	Name        string
	Permissions []string
}

Simple struct to hold the role

Jump to

Keyboard shortcuts

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