pkg

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: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignDefaultRolePermissions

func AssignDefaultRolePermissions(db *gorm.DB, roleID uint, userID uint) []string

AssignDefaultRolePermissions assigns default role permissions to a user.

It takes in three parameters: db of type *gorm.DB, roleID of type uint and userID of type uint and returns an error object. It further delegates the permissions assigning with AssignUserPermissions function.

func AssignDefaultRolePermissionsUUID

func AssignDefaultRolePermissionsUUID(db *gorm.DB, roleID uint, userID uuid.UUID) []string

AssignDefaultRolePermissionsUUID assigns default role permissions to a user.

It takes in three parameters: db of type *gorm.DB, roleID of type uint and userID of type uuid.UUID and returns an error object. It further delegates the permissions assigning with AssignUserPermissionsUUID function.

func AssignPermissionsToCategory

func AssignPermissionsToCategory(db *gorm.DB, categoryID uint, permissions []uint) []string

AssignPermissionsToCategory associates permission(s) with a category.

It takes in three parameters: db of type *gorm.DB, categoryID of type uint and permissions of type slice of uint and returns and returns an error object.

func AssignRole

func AssignRole(db *gorm.DB, userID uint, roleID uint) error

AssignRole assigns a role to a user.

It takes in three parameters: db of type *gorm.DB, userID of type uint and roleID of type uint and returns an error object. It returns an error object if the user is already assigned with the role.

func AssignRolePermissions

func AssignRolePermissions(db *gorm.DB, roleID uint, permissionIDs []uint) []string

AssignRolePermissions assigns a list of permissions to a specified role.

It takes in three parameters: db of type *gorm.DB, roleID of type uint and permissionIDs of type slice of uint with ids of permissions. It returns an error object. It immediately returns with an err object if a requested permission is not found, else create new relationship record of role with the permission.

func AssignRoleUUID

func AssignRoleUUID(db *gorm.DB, userID uuid.UUID, roleID uint) error

AssignRole assigns a role to a user.

It takes in three parameters: db of type *gorm.DB, userID of type uuid.UUID and roleID of type uint and returns an error object. It returns an error object if the user is already assigned with the role.

func AssignUserPermissions

func AssignUserPermissions(db *gorm.DB, userID uint, permissionIDs []uint) []string

AssignUserPermissions assigns a list of permission to a user.

It takes in three parameters: db of type *gorm.DB, userID of type uint and permissionIDs of type slice of uint and returns an error object.

func AssignUserPermissionsUUID

func AssignUserPermissionsUUID(db *gorm.DB, userID uuid.UUID, permissionIDs []uint) []string

AssignUserPermissionsUUID assigns a list of permission to a user.

It takes in three parameters: db of type *gorm.DB, userID of type uuid.UUID and permissionIDs of type slice of uint and returns an error object.

func CheckPermission

func CheckPermission(db *gorm.DB, userID uint, permissionID uint) (bool, error)

CheckPermission checks if a permission with the specified id is assigned to a user.

It takes in three parameters: db of type *gorm.DB, userID of type uint and permmissionID of type uint. It returns a boolean to specify if the permission is assigned to the user and an error object.

func CheckPermissionUUID

func CheckPermissionUUID(db *gorm.DB, userID uuid.UUID, permName string) (bool, error)

CheckPermissionUUID checks if a permission with the specified name is assigned to a user.

It takes in three parameters: db of type *gorm.DB, userID of type uuid.UUID and permName of type string. It returns a boolean to specify if the permission is assigned to the user and an error object.

func CheckRole

func CheckRole(db *gorm.DB, userID uint, roleID uint) (bool, error)

CheckRole checks if the role with the specified id is assigned to the user.

It takes in three parameters: db of type *gorm.DB, userID of type uint and roleID of type uint. It returns a boolean to specify if the role is assigned to the user and an error object.

func CheckRolePermission

func CheckRolePermission(db *gorm.DB, roleID uint, permissionID uint) (bool, error)

CheckRolePermission checks if a role has a specific permission.

It takes in three parameters: db of type *gorm.DB, roleID of type uint and permissionID of type uint. It returns a boolean to specify if the role has the permission and an error object.

func CheckRoleUUID

func CheckRoleUUID(db *gorm.DB, userID uuid.UUID, roleID uint) (bool, error)

CheckRoleUUID checks if the role with the specified id is assigned to the user.

It takes in three parameters: db of type *gorm.DB, userID of type uuid.UUID and roleID of type uint. It returns a boolean to specify if the role is assigned to the user and an error object.

func CheckUserPermissionUrl

func CheckUserPermissionUrl(db *gorm.DB, userID uint, permissionPath string) (bool, error)

CheckUserPermissionUrl checks if a user has permission to a url path.

It takes in three parameters: db of type *gorm.DB, userID of type uint and permissionPath of type string. It returns a bool to indicate if a user has the permission to the url path and an error object.

func CheckUserPermissionUrlUUID

func CheckUserPermissionUrlUUID(db *gorm.DB, userID uuid.UUID, permissionPath string) (bool, error)

CheckUserPermissionUrl checks if a user has permission to a url path.

It takes in three parameters: db of type *gorm.DB, userID of type uuid.UUID and permissionPath of type string. It returns a bool to indicate if a user has the permission to the url path and an error object.

func CreateCategory

func CreateCategory(db *gorm.DB, categoryName string) error

CreateCategory creates a new category in the database with the specified category name.

It takes in two parameters: db of type *gorm.DB and categoryName of type string and returns an error object.

func CreatePermission

func CreatePermission(db *gorm.DB, permissionName string, description string, urlID uint) error

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

It takes in three parameters: db of type *gorm.DB and permissionName and description of type string and returns an error object.

func CreateRole

func CreateRole(db *gorm.DB, roleName string) error

CreateRole creates a new role in the database with the specified role name.

It takes in two parameters: db of type *gorm.DB and roleName of type string and returns an error object.

func CreateStaticPermission

func CreateStaticPermission(db *gorm.DB, permissionID uint, permissionData []string) error

CreateStaticPermission creates a new permission with the specified ID and permission data.

It takes in three parameters: db of type *gorm.DB and permissionID of type uint and permissionData of type slice of string (includes permission name and desription) and returns an error object.

func CreateStaticPermissionCategory

func CreateStaticPermissionCategory(db *gorm.DB, categoryID uint, categoryName string) error

CreateStaticCategory creates a new category with the specified ID and category name.

It takes in three parameters: db of type *gorm.DB and categoryID of type uint and categoryName of type string and returns an error object.

func CreateStaticPermissionUrl

func CreateStaticPermissionUrl(db *gorm.DB, urlID uint, urlPath string) error

CreateStaticPermissionUrl creates a new url with the specified ID and url path name.

It takes in three parameters: db of type *gorm.DB, urlID of type uint and urlPath of type string and returns an error object.

func CreateStaticRole

func CreateStaticRole(db *gorm.DB, roleID uint, roleName string) error

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

It takes in three parameters: db of type *gorm.DB, roleID of type uint and roleName of type string and returns an error object.

func CreateUrl

func CreateUrl(db *gorm.DB, path string) error

CreateUrl creates a new url in the database with the specified url path name.

It takes in two parameters: db of type *gorm.DB and path of type string and returns an error object.

func DeleteCategory

func DeleteCategory(db *gorm.DB, categoryID uint) error

DeleteCategory deletes a category with the given id.

It takes in two parameters: db of type *gorm.DB and categoryID of type uint and returns an error object. It also deletes the association of permissions from the category before deleting it.

func DeletePermission

func DeletePermission(db *gorm.DB, permissionID uint) error

DeletePermission deletes a permission with the given id.

It takes in two parameters: db of type *gorm.DB and permissionID of type uint and returns an error object.

func DeleteRole

func DeleteRole(db *gorm.DB, roleID uint) error

DeleteRole deletes a role with the given id.

It takes in two parameters: db of type *gorm.DB and roleID of type uint and returns an error object. It returns immediately if the role has been assigned to an user. It also revokes the association of permissions from the role before deleting it.

func DeleteUrl

func DeleteUrl(db *gorm.DB, urlID uint) error

DeleteUrl deletes an url with the given id along with its associated object.

It takes in two parameters: db of type *gorm.DB and urlID of type uint and returns an error object. It also deletes the association of url with the permission and also user permission before deleting it.

func GetAllCategoryPermissions

func GetAllCategoryPermissions(db *gorm.DB) ([]domain.CategoryPermissionsResponse, error)

GetAllCategoryPermissions retrieves all the permissions associated with each of the category in the database.

It takes in an object of database of type *gorm.DB as parameter and returns data of type slice of domain.CategoryPermissionsResponse and an error object.

func GetCategories

func GetCategories(db *gorm.DB) ([]models.Category, error)

GetCategories retrieves a list of category objects from the database.

It takes in a database parameter db of type *gorm.DB to query and retrieve all the categories from the database. It returns a slice of category objects and an error object.

func GetCategoryByID

func GetCategoryByID(db *gorm.DB, categoryID uint) (category models.Category, err error)

GetCategoryByID retrieves a category from the database by its id.

It takes in two parameters: db of type *gorm.DB and categoryID of type uint. It returns a category object if found and an error object.

func GetCategoryByName

func GetCategoryByName(db *gorm.DB, categoryName string) (category models.Category, err error)

GetCategoryByName retrieves a category from the database by its name.

It takes in two parameters: db of type *gorm.DB and categoryName of type string. It returns a category object if found and an error object.

func GetPermissionByID

func GetPermissionByID(db *gorm.DB, permissionID uint) (permission models.Permission, err error)

GetPermissionByID retrieves a permission from the database by its id.

It takes in two parameters: db of type *gorm.DB and permissionID of type uint. It returns a permission object if found and an error object.

func GetPermissionByName

func GetPermissionByName(db *gorm.DB, permissionName string) (permission models.Permission, err error)

GetPermissionByName retrieves a permission from the database by its name.

It takes in two parameters: db of type *gorm.DB and permissionName of type string. It returns a permission object if found and an error object.

func GetPermissionByUrl

func GetPermissionByUrl(db *gorm.DB, permissionPath string) (permission models.Permission, err error)

GetPermissionByUrl retrieves a permission from the database by its url path.

It takes in two parameters: db of type *gorm.DB and permissionUrl of type string. It returns a permission object if found and an error object.

func GetPermissions

func GetPermissions(db *gorm.DB) ([]models.Permission, error)

GetPermissions retrieves a list of permission names from the database.

It takes in a database parameter db of type *gorm.DB to query and retrieve all the permissions from the database. It returns a slice of string with the name of the permissions and an error object.

func GetPermissionsByCategory

func GetPermissionsByCategory(db *gorm.DB, categoryID uint) ([]models.Permission, error)

GetPermissionsByCategory retrieves the list permissions associated with a category.

It takes in two parameters: db of type *gorm.DB and categoryID of type uint. It returns a slice of permissions with the given category id and an error object.

func GetRoleByID

func GetRoleByID(db *gorm.DB, roleID uint) (role models.Role, err error)

GetRoleByID retrieves a role from the database with the specified id.

It takes in two parameters: db of type *gorm.DB and roleID of type uint. It returns a role object if found and an error object.

func GetRoleByName

func GetRoleByName(db *gorm.DB, roleName string) (role models.Role, err error)

GetRoleByName retrieves a role from the database by its name.

It takes in two parameters: db of type *gorm.DB and roleName of type string. It returns a role object if found and an error object.

func GetRoles

func GetRoles(db *gorm.DB) (roles []models.Role, err error)

GetRoles retrieves a list of role names from the database.

It takes in a database parameter db of type *gorm.DB to query and retrieve all the roles from the database. It returns a slice of string with the name of the roles and an error object.

func GetUrlByID

func GetUrlByID(db *gorm.DB, urlID uint) (url models.Url, err error)

GetUrlByID retrieves an url from the database with the specified id.

It takes in two parameters: db of type *gorm.DB and urlID of type uint. It returns an url object if found and an error object.

func GetUrlByPath

func GetUrlByPath(db *gorm.DB, path string) (url models.Url, err error)

GetUrlByPath retrieves an url from the database by its path.

It takes in two parameters: db of type *gorm.DB and path of type string. It returns an url object if found and an error object.

func GetUrls

func GetUrls(db *gorm.DB) ([]models.Url, error)

GetUrls retrieves a list of urls from the database.

It takes in a database parameter db of type *gorm.DB to query and retrieve all the urls from the database. It returns a slice of url objects and an error object.

func GetUserRoles

func GetUserRoles(db *gorm.DB, userID uint) ([]models.Role, error)

GetUserRoles retrieves the roles assigned to a user.

It takes in two parameters: db of type *gorm.DB and userID of type uint. It returns a slice of strings with the name of the roles and an error object.

func GetUserRolesUUID

func GetUserRolesUUID(db *gorm.DB, userID uuid.UUID) ([]models.Role, error)

GetUserRolesUUID retrieves the roles assigned to a user.

It takes in two parameters: db of type *gorm.DB and userID of type uuid.UUID. It returns a slice of strings with the name of the roles and an error object.

func RevokePermission

func RevokePermission(db *gorm.DB, userID uint, permName string) error

RevokePermission revokes a permission from a user role.

It takes in three parameters: db of type *gorm.DB, userID of type uint and permName of type string and returns an error object.

func RevokePermissionUUID

func RevokePermissionUUID(db *gorm.DB, userID uuid.UUID, permName string) error

RevokePermissionUUID revokes a permission from a user role.

It takes in three parameters: db of type *gorm.DB, userID of type uuid.UUID and permName of type string and returns an error object.

func RevokeRole

func RevokeRole(db *gorm.DB, userID uint, roleID uint) error

RevokeRole revokes a role from a user.

It takes in three parameters: db of type *gorm.DB, userID of type uint and roleID of type uint and returns an error object.

func RevokeRolePermission

func RevokeRolePermission(db *gorm.DB, roleID uint, permissionID uint) error

RevokeRolePermission revokes a permission from a specified role.

It takes in three parameters: db of type *gorm.DB, roleID of type uint and permissionID of type uint and returns an error object.

func RevokeRoleUUID

func RevokeRoleUUID(db *gorm.DB, userID uuid.UUID, roleID uint) error

RevokeRole revokes a role from a user.

It takes in three parameters: db of type *gorm.DB, userID of type uuid.UUID and roleID of type uint and returns an error object.

func UpdateCategory

func UpdateCategory(db *gorm.DB, categoryID uint, categoryName string) error

UpdateCategory updates a category with the specified category id.

It takes in three parameters: db of type *gorm.DB, categoryID of type uint, categoryName of type string and returns an error object.

func UpdatePermission

func UpdatePermission(db *gorm.DB, permissionID uint, permissionName string, description string, urlID uint) error

UpdatePermission updates an existing permission for the specified permission id with the given data.

It takes in four parameters: db of type *gorm.DB, permissionID of type uint and two string type, permissionName and description and returns an error object.

func UpdateRole

func UpdateRole(db *gorm.DB, roleID uint, roleName string) error

UpdateRole updates an existing role in the database for the specified role id with the given role name.

It takes in three parameters: db of type *gorm.DB, roleID of type uint and roleName of type string and returns an error object.

func UpdateUrl

func UpdateUrl(db *gorm.DB, urlID uint, path string) error

UpdateUrl updates an existing url in the database for the specified url id with the given url path.

It takes in three parameters: db of type *gorm.DB, urlID of type uint and path of type string and returns an error object.

Types

This section is empty.

Jump to

Keyboard shortcuts

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