authority

package
v0.0.0-...-cc52b3d Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDB

func GetDB(opts Options) *gorm.DB

func MigrateTables

func MigrateTables(opts Options)

Types

type Authority

type Authority struct {
	DB *gorm.DB
}

Authority helps deal with permissions

func New

func New(opts Options) *Authority

New initiates authority

func Resolve

func Resolve() *Authority

Resolve returns the initiated instance

func (*Authority) AssignDefaultRolePermissions

func (a *Authority) AssignDefaultRolePermissions(roleID uint, userID uint) []string

AssignDefaultRolePermissions assigns the default permissions associated with the role to a user.

It takes in two uint parameters: roleID and userID and returns an error object.

func (*Authority) AssignDefaultRolePermissionsUUID

func (a *Authority) AssignDefaultRolePermissionsUUID(roleID uint, userID uuid.UUID) []string

AssignDefaultRolePermissions assigns the default permissions associated with the role to a user.

It takes in two parameters: roleID of type uint and userID of type uuid.UUID and returns an error object.

func (*Authority) AssignPermissionsToCategory

func (a *Authority) AssignPermissionsToCategory(categoryID uint, permissions []uint) []string

AssignPermissionsToCategory associates permission(s) with a category.

It takes in two parameters: categoryID of type uint and permissions of type slice of uint and returns an error object.

func (*Authority) AssignRole

func (a *Authority) AssignRole(userID uint, roleID uint) error

AssignRole associates a user with the role with the given role id.

It takes in two uint type parameters: userID and roleID and returns an error object.

func (*Authority) AssignRolePermissions

func (a *Authority) AssignRolePermissions(roleID uint, permissionIDs []uint) []string

AssignRolePermissions assign a list of permissions to a specified role.

It takes in two parameters: roleID of type uint and permissionIDs of type slice of uint and return an error object.

func (*Authority) AssignRoleUUID

func (a *Authority) AssignRoleUUID(userID uuid.UUID, roleID uint) error

AssignRoleUUID associates a user with the role with the given role id.

It takes in userID, a uuid.UUID and roleID, an uint and returns an error object.

func (*Authority) AssignUserPermissions

func (a *Authority) AssignUserPermissions(userID uint, permissionIDs []uint) []string

AssignUserPermissions assigns permission(s) to a specified user.

It takes in two parameters: userID of type uint and permissionIDs of type slice of uint and returns an error object.

func (*Authority) AssignUserPermissionsUUID

func (a *Authority) AssignUserPermissionsUUID(userID uuid.UUID, permissionIDs []uint) []string

AssignUserPermissions assigns permission(s) to a specified user.

It takes in two parameters: userID of type uuid.UUID and permissionIDs of type slice of uint and returns an error object.

func (*Authority) CheckPermission

func (a *Authority) CheckPermission(userID uint, permissionID uint) (bool, error)

CheckPermission checks if a user has a specified permission.

It takes in two parameters: userID of type uint and permName of type string. It returns a boolean and an error object.

func (*Authority) CheckPermissionUUID

func (a *Authority) CheckPermissionUUID(userID uuid.UUID, permName string) (bool, error)

CheckPermission checks if a user has a specified permission.

It takes in two parameters: userID of type uuid.UUID and permName of type string. It returns a boolean and an error object.

func (*Authority) CheckRole

func (a *Authority) CheckRole(userID uint, roleID uint) (bool, error)

CheckRole checks if a role is assigned to a user.

It takes in two uint parameters: userID and roleID. It returns a boolean to specify that a role is assigned to a user and an error object.

func (*Authority) CheckRolePermission

func (a *Authority) CheckRolePermission(roleID uint, permissionID uint) (bool, error)

CheckRolePermission checks if a permission is associated the role.

It takes in two uint parameters: roleID and permissionID. It returns a boolean and an error object.

func (*Authority) CheckRoleUUID

func (a *Authority) CheckRoleUUID(userID uuid.UUID, roleID uint) (bool, error)

CheckRole checks if a role is assigned to a user.

It takes in two parameters: userID of type uuid.UUID and roleID of type uint. It returns a boolean to specify that a role is assigned to a user and an error object.

func (*Authority) CreateCategory

func (a *Authority) CreateCategory(categoryName string) error

CreateCategory creates a new category with the specified name.

It takes a string parameter, categoryName and returns an error object.

func (*Authority) CreatePermission

func (a *Authority) CreatePermission(permissionName string, description string, url_id uint) error

CreatePermission creates a new permission with the specified permission name and description.

It takes two string parameter, permissionName and description and returns an error object.

func (*Authority) CreateRole

func (a *Authority) CreateRole(roleName string) error

CreateRole creates a new role with the specified role name.

It takes a string parameter, roleName and returns an error object.

func (*Authority) CreateStaticPermission

func (a *Authority) CreateStaticPermission(permissionID uint, permissionData []string) error

CreateStaticPermission creates a new permission with the specified id and permission data. (Prefer using this function only if a self-defined uint type ID needs to be passed to create a permission.)

It takes two parameters: permissionID of uint type and permissionData which includes name and description for a new permission and returns an error object.

func (*Authority) CreateStaticPermissionCategory

func (a *Authority) CreateStaticPermissionCategory(categoryID uint, categoryName string) error

CreateStaticPermissionCategory creates a new category with the specified id and name. (Prefer using this function only if a self-defined uint type ID needs to be passed to create a category.)

It takes two parameters: categoryID of uint type and categoryName of type string and returns an error object.

func (*Authority) CreateStaticPermissionUrl

func (a *Authority) CreateStaticPermissionUrl(urlID uint, urlPath string) error

CreateStaticPermissionUrl creates a new url with the specified id and permission url path. (Prefer using this function only if a self-defined uint type ID needs to be passed to create a url.)

It takes two parameters: urlID of uint type and urlPath of string type and returns an error object.

func (*Authority) CreateStaticRole

func (a *Authority) CreateStaticRole(roleID uint, roleName string) error

CreateStaticRole creates a new role with the specified id and role name.

It takes two paraeters: roleID of uint type and roleName of string type and returns an error object. (Prefer using this function only if a self-defined uint type ID needs to be passed to create a role.)

func (*Authority) DeleteCategory

func (a *Authority) DeleteCategory(categoryID uint) error

DeleteCategory deletes a category with the specified category id.

It takes an uint parameter, categoryID and returns an error object.

func (*Authority) DeletePermission

func (a *Authority) DeletePermission(permissionID uint) error

DeletePermission deletes a permission with the specified permission id.

It takes an uint parameter, permissionID and returns an error object.

func (*Authority) DeleteRole

func (a *Authority) DeleteRole(roleID uint) error

DeleteRole deletes a role with the specified role id, roleID.

It takes an uint parameter, roleID and returns an error object.

func (*Authority) GetCategories

func (a *Authority) GetCategories() ([]models.Category, error)

GetCategories retrieves all the categories in the database.

It retuns a slice of uint with category id and an error object.

func (*Authority) GetCategoryPermissions

func (a *Authority) GetCategoryPermissions() ([]domain.CategoryPermissionsResponse, error)

GetCategoryPermissions retrieves the permissions associated with all the categories in the database.

It returns a slice of domain.CategoryPermissionsResponse and an error object.

func (*Authority) GetPermissions

func (a *Authority) GetPermissions() ([]models.Permission, error)

GetPermissions retrieves all the permissions in the database.

It retuns a slice of string with permission names and an error object.

func (*Authority) GetPermissionsByCategory

func (a *Authority) GetPermissionsByCategory(categoryID uint) ([]models.Permission, error)

GetPermissionsByCategory retrieves the list of permissions associated with a category.

It takes an uint parameter, categoryID. It returns a slice of permission objects associated with the category and an error object.

func (*Authority) GetRoles

func (a *Authority) GetRoles() ([]models.Role, error)

GetRoles retrieves all the roles in the database.

It retuns a slice of role objects and an error object.

func (*Authority) GetUserRoles

func (a *Authority) GetUserRoles(userID uint) ([]models.Role, error)

GetUserRoles retrieves all the roles assigned to a user.

It takes in an uint, userID and returns a slice of role objects and an error object.

func (*Authority) GetUserRolesUUID

func (a *Authority) GetUserRolesUUID(userID uuid.UUID) ([]models.Role, error)

GetUserRolesUUID retrieves all the roles assigned to a user.

It takes in an uuid.UUID, userID and returns a slice of role objects and an error object.

func (*Authority) RevokePermission

func (a *Authority) RevokePermission(userID uint, permName string) error

RevokePermission revokes a permission from the user.

It takes in two parameters: userID of type uint and permName of type string and returns an error object.

func (*Authority) RevokePermissionUUID

func (a *Authority) RevokePermissionUUID(userID uuid.UUID, permName string) error

RevokePermissionUUID revokes a permission from the user.

It takes in two parameters: userID of type uuid.UUID and permName of type string and returns an error object.

func (*Authority) RevokeRole

func (a *Authority) RevokeRole(userID uint, roleID uint) error

RevokeRole revokes a role from the user.

It takes in two uint parameters: userID and roleID and returns an error object.

func (*Authority) RevokeRolePermission

func (a *Authority) RevokeRolePermission(roleID uint, permissionID uint) error

RevokeRolePermission revokes a permission from a role.

It takes in two uint parameters: roleID and permissionID and returns an error object.

func (*Authority) RevokeRoleUUID

func (a *Authority) RevokeRoleUUID(userID uuid.UUID, roleID uint) error

RevokeRole revokes a role from the user.

It takes in two parameters: userID of type uuid.UUID and roleID of type uint and returns an error object.

func (*Authority) UpdateCategory

func (a *Authority) UpdateCategory(categoryID uint, categoryName string) error

UpdateCategory updates a category of the given category id with specified category name.

It takes in two parameters: categoryID of type uint and categoryName of type string and returns an error object.

type Options

type Options struct {
	DB        *gorm.DB
	UserIDInt bool
}

Options has the options for initiating the package

Jump to

Keyboard shortcuts

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