Documentation ¶
Overview ¶
Package baseuser is a domain package wich contains the common users features and behavior.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidBaseUsrImplementation = errors.New("invalid base user implementation")
Functions ¶
Types ¶
type ACL ¶
type ACL interface { // CanRead will check if the current user can read the resource CanRead(resource Resource) bool // CanWrite will check if the current user can write the resource CanWrite(resource Resource) bool // FullAccess will check if the current user can read and write the resource FullAccess(resource Resource) bool // GetResources will return two slices from resources. // Readable resources and Writable resources in order. GetResources() ([]Resource, []Resource) }
ACL will provide the access control list for the current user and the resources that can be accessed by the current user
func NewACL ¶
func NewACL(opts ...ACLOptions) ACL
NewACL returns a new ACL with permissions configured by the given options.
func ProducerACL ¶
func ProducerACL() ACL
ProducerACL is the ACL for a producer.
The ACL preconfigured for a producer.
func StudentACL ¶
func StudentACL() ACL
StudentACL is the ACL for a student.
The ACL preconfigured for a student.
type ACLOptions ¶
type ACLOptions func(a *acl)
ACLOptions is a function that will be used to configure the ACL
func CanRead ¶
func CanRead(resource Resource) ACLOptions
CanRead set ACLOptions to allow read access to the given resource.
func CanWrite ¶
func CanWrite(resource Resource) ACLOptions
CanWrite set ACLOptions to allow write access to the given resource.
func FullAccess ¶
func FullAccess(resource Resource) ACLOptions
FullAccess set ACLOptions to allow read and write access to the given resource.
type BaseUser ¶
type BaseUser interface { // GetID will return the current user id GetID() string // GetEmail will return the current user email GetEmail() string // GetPassword will return the current user password GetPassword() string // GetScope will return the user scope GetScope() Scope // GetACL will return ACL for the current user GetACL() ACL // SyncData receives an array of options and applies them to the current user SyncData(usrOption ...Option) error // IsPasswordValid will check if the user password received // is valid password for the current user IsPasswordValid(password string) bool // HashPassword will hash the password received and return the hash // // It should have a password, else it will return an error HashPassword() error // AddScope will add current scope to current user. // // Looks possible cases: // // student.AddScope(PRODUCER) // student.GetScope() => BOTH // producer.AddScope(STUDENT) // producer.GetScope() => BOTH // student.AddScope(STUDENT) // student.GetScope() => STUDENT // producer.AddScope(PRODUCER) // producer.GetScope() => PRODUCER // student.AddScope(BOTH) // student.GetScope() => BOTH // producer.AddScope(BOTH) // producer.GetScope() => BOTH // // If user scope is `student` and call `AddScope(PRODUCER)`, it // will make user scope as `BOTH`. // // If user scope is `producer` and call `AddScope(STUDENT)`, it // will make user scope as `BOTH` too. // // If current scope matches with call `AddScope`. Nothing happens AddScope(Scope) }
type Option ¶
Option is a optional function argument for BaseUser
It will be used to configure the BaseUser instance