Documentation ¶
Index ¶
- type Authority
- func (a *Authority) AssignPermissions(roleName string, permNames []string) error
- func (a *Authority) AssignRole(userID primitive.ObjectID, roleName string) error
- func (a *Authority) CheckPermission(userID primitive.ObjectID, permName string) bool
- func (a *Authority) CheckRole(userID primitive.ObjectID, roleName string) bool
- func (a *Authority) CheckRolePermission(roleName string, permName string) bool
- func (a *Authority) CreatePermission(permName string) error
- func (a *Authority) CreateRole(roleName string) error
- func (a *Authority) DeletePermission(permName string) error
- func (a *Authority) DeleteRole(roleName string) error
- func (a *Authority) GetPermissionTableName() string
- func (a *Authority) GetPermissions() []string
- func (a *Authority) GetRolePermissionTableName() string
- func (a *Authority) GetRoleTableName() string
- func (a *Authority) GetRoles() ([]string, error)
- func (a *Authority) GetUserRoleTableName() string
- func (a *Authority) GetUserRoles(userID primitive.ObjectID) []string
- func (a *Authority) RevokePermission(userID primitive.ObjectID, permName string) error
- func (a *Authority) RevokeRole(userID primitive.ObjectID, roleName string) error
- func (a *Authority) RevokeRolePermission(roleName string, permName string) error
- type Options
- type Permission
- type Role
- type RolePermission
- type UserRole
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authority ¶
Authority helps deal with permissions
func (*Authority) AssignPermissions ¶
AssignPermissions assigns a group of permissions to a given role it accepts in the first parameter the role name, it returns an error if there is not matching record of the role name in the database. the second parameter is a slice of strings which represents a group of permissions to be assigned to the role if any of these permissions doesn't have a matching record in the database the operations stops, changes reverted and error is returned in case of success nothing is returned
func (*Authority) AssignRole ¶
AssignRole assigns a given role to a user the first parameter is the user id, the second parameter is the role name if the role name doesn't have a matching record in the data base an error is returned if the user have already a role assigned to him an error is returned
func (*Authority) CheckPermission ¶
CheckPermission checks if a permission is assigned to the role that's assigned to the user. it accepts the user id as the first parameter the permission as the second parameter it returns an error if the permission is not present in the database
func (*Authority) CheckRole ¶
CheckRole checks if a role is assigned to a user it accepts the user id as the first parameter the role as the second parameter it returns an error if the role is not present in database
func (*Authority) CheckRolePermission ¶
CheckRolePermission checks if a role has the permission assigned it accepts the role as the first parameter it accepts the permission as the second parameter it returns an error if the role is not present in database it returns an error if the permission is not present in database
func (*Authority) CreatePermission ¶
CreatePermission stores a permission in the database it accepts the permission name. it returns an error in case of any
func (*Authority) CreateRole ¶
CreateRole stores a role in the database it accepts the role name. it returns an error inCase of any
func (*Authority) DeletePermission ¶
DeletePermission deletes a given permission if the permission is assigned to a role it returns an error
func (*Authority) DeleteRole ¶
DeleteRole deletes a given role if the role is assigned to a user it returns an error
func (*Authority) GetPermissionTableName ¶ added in v1.0.5
func (*Authority) GetPermissions ¶
GetPermissions returns all stored permissions
func (*Authority) GetRolePermissionTableName ¶ added in v1.0.5
func (*Authority) GetRoleTableName ¶ added in v1.0.5
func (*Authority) GetUserRoleTableName ¶ added in v1.0.5
func (*Authority) GetUserRoles ¶
GetUserRoles returns all user assigned roles
func (*Authority) RevokePermission ¶
RevokePermission revokes a permission from the user's assigned role it returns an error in case of any
func (*Authority) RevokeRole ¶
RevokeRole revokes a user's role it returns a error in case of any
type Permission ¶
Permission represents the database model of permissions
type RolePermission ¶
type RolePermission struct { ID primitive.ObjectID `bson:"_id"` RoleID primitive.ObjectID `bson:"role_id"` PermissionID primitive.ObjectID `bson:"permission_id"` }
RolePermission stores the relationship between roles and permissions
func (RolePermission) TableName ¶
func (r RolePermission) TableName() string
TableName sets the table name