Documentation ¶
Index ¶
- Variables
- type Authority
- func (a *Authority) AssignPermissionsToRole(roleSlug string, permSlugs []string) error
- func (a *Authority) AssignRoleToUser(userID interface{}, roleSlug string) error
- func (a *Authority) BeginTX() *Authority
- func (a *Authority) CheckRolePermission(roleSlug string, permSlug string) (bool, error)
- func (a *Authority) CheckUserPermission(userID interface{}, permSlug string) (bool, error)
- func (a *Authority) CheckUserRole(userID interface{}, roleSlug string) (bool, error)
- func (a *Authority) Commit() error
- func (a *Authority) CreatePermission(p Permission) error
- func (a *Authority) CreateRole(r Role) error
- func (a *Authority) DeletePermission(permSlug string) error
- func (a *Authority) DeleteRole(roleSlug string) error
- func (a *Authority) GetAllPermissions() ([]Permission, error)
- func (a *Authority) GetAllRoles() ([]Role, error)
- func (a *Authority) GetRolePermissions(roleSlug string) ([]Permission, error)
- func (a *Authority) GetUserRoles(userID interface{}) ([]Role, error)
- func (a *Authority) RevokeRolePermission(roleSlug string, permSlug string) error
- func (a *Authority) RevokeUserRole(userID interface{}, roleSlug string) error
- func (a *Authority) Rollback() error
- type Options
- type Permission
- type Role
- type RolePermission
- type UserRole
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Authority ¶
Authority helps deal with permissions
func (*Authority) AssignPermissionsToRole ¶
Assigns a group of permissions to a given role it accepts the the role slug as the first parameter the second parameter is a slice of permission slugs (strings) to be assigned to the role it returns an error in case of any it returns an error in case the role does not exists it returns an error in case any of the permissions does not exists it returns an error in case any of the permissions is already assigned
func (*Authority) AssignRoleToUser ¶
Assigns a role to a given user it accepts the user id as the first parameter the second parameter the role slug it returns an error in case of any it returns an error in case the role does not exists it returns an error in case the role is already assigned
func (*Authority) CheckRolePermission ¶
Checks if a permission is assigned to a role it accepts in the role slug as the first parameter the second parameter the permission slug it returns two parameters the first parameter of the return is a boolean represents whether the permission is assigned or not the second is an error in case of any in case the role does not exists, an error is returned in case the permission does not exists, an error is returned
func (*Authority) CheckUserPermission ¶
Checks if a permission is assigned to a user it accepts in the user id as the first parameter the second parameter the role slug it returns two parameters the first parameter of the return is a boolean represents whether the role is assigned or not the second is an error in case of any in case the role does not exists, an error is returned
func (*Authority) CheckUserRole ¶
Checks if a role is assigned to a user it accepts the user id as the first parameter the second parameter the role slug it returns two parameters the first parameter of the return is a boolean represents whether the role is assigned or not the second is an error in case of any in case the role does not exists, an error is returned
func (*Authority) CreatePermission ¶
func (a *Authority) CreatePermission(p Permission) error
Add a new permission to the database it accepts the Permission struct as a parameter it returns an error in case of any it returns an error if the permission is already exists
func (*Authority) CreateRole ¶
Add a new role to the database it accepts the Role struct as a parameter it returns an error in case of any it returns an error if the role is already exists
func (*Authority) DeletePermission ¶
Deletes a given permission it accepts the permission slug as a parameter it returns an error in case of any if the permission is assigned to a role it returns an error
func (*Authority) DeleteRole ¶
Deletes a given role even if it's has assigned permissions it first deassign the permissions and then proceed with deleting the role it accepts the role slug as a parameter it returns an error in case of any if the role is assigned to a user it returns an error
func (*Authority) GetAllPermissions ¶
func (a *Authority) GetAllPermissions() ([]Permission, error)
Returns all stored permissions it returns an error in case of any
func (*Authority) GetAllRoles ¶
Returns all stored roles it returns an error in case of any
func (*Authority) GetRolePermissions ¶
func (a *Authority) GetRolePermissions(roleSlug string) ([]Permission, error)
Returns all role assigned permissions it returns an error in case of any
func (*Authority) GetUserRoles ¶
Returns all user assigned roles it returns an error in case of any
func (*Authority) RevokeRolePermission ¶
Revokes a roles's permission it returns a error in case of any in case the role does not exists, an error is returned in case the permission does not exists, an error is returned
func (*Authority) RevokeUserRole ¶
Revokes a user's role it returns a error in case of any in case the role does not exists, an error is returned
type Permission ¶
type Permission struct { ID uint // The permission id (it gets set automatically by the database) Name string // The permission name Slug string // String based unique identifier of the permission, (use hyphen seperated permission name '-', instead of space) }
Permission represents the database model of permissions
type Role ¶
type Role struct { ID uint // The role id (it gets set automatically by the database) Name string // The name of the role Slug string // String based unique identifier of the role, (use hyphen seperated role name '-', instead of space) }
The database model of a role
type RolePermission ¶
type RolePermission struct { ID uint // Unique id (it gets set automatically by the database) RoleID uint // Role id PermissionID uint // Permission id }
The link between the roles and permissions
func (RolePermission) TableName ¶
func (r RolePermission) TableName() string
TableName sets the table name