role

package
v0.0.0-...-01681b2 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRoleNotFound            = errors.New("role not found")
	ErrLeafRoleHasNoSubRole    = errors.New("leaf role has no subrole")
	ErrRootRoleHasNoParent     = errors.New("can't set root role's parent")
	ErrRootRoleCannotBeDeleted = errors.New("can't delete root role")
)
View Source
var (
	ErrAppHasNoRole = errors.New("app has no admin role")
)

Functions

func AddRoleResource

func AddRoleResource(ctx *models.Context, roleId int, resourcesIds []int) error

func CreateAppDefaultRole

func CreateAppDefaultRole(ctx *models.Context, appId int, roleName string, fullName string) (*app.App, error)

func CreateResources

func CreateResources(ctx *models.Context, resources []Resource) error

func DeleteAppRole

func DeleteAppRole(ctx *models.Context, appId int) (*app.App, error)

func DeleteResource

func DeleteResource(ctx *models.Context, id int) error

func DeleteResources

func DeleteResources(ctx *models.Context, ids []int) error

func DeleteRole

func DeleteRole(ctx *models.Context, id int) error

func GetRoleIdByName

func GetRoleIdByName(ctx *models.Context, name string, appId int) (int, error)

func InitDatabase

func InitDatabase(ctx *models.Context)

func IsLeafRole

func IsLeafRole(ctx *models.Context, roleId int) bool

func IsOffspring

func IsOffspring(ctx *models.Context, roleId int, queryId int) (bool, error)

func IsUserInAppAdminRole

func IsUserInAppAdminRole(ctx *models.Context, user iuser.User, appId int) (bool, group.MemberRole)

func IsUserInRole

func IsUserInRole(ctx *models.Context, user iuser.User, role *Role) (bool, group.MemberRole)

func RemoveRoleResource

func RemoveRoleResource(ctx *models.Context, roleId int, resourceIds []int) error

func SetAppRole

func SetAppRole(ctx *models.Context, roleId int, appId int) (*app.App, error)

func UpdateResources

func UpdateResources(ctx *models.Context, resources []Resource) error

func UpdateRoleResource

func UpdateRoleResource(ctx *models.Context, roleId int, resourcesIds []int) error

Types

type Resource

type Resource struct {
	Id          int    `json:"id"`
	Name        string `json:"name"`
	Description string `db:"fullname" json:"description"`
	AppId       int    `db:"app_id" json:"app_id"`
	Data        string `json:"data"`
	Owner       string `json:"owner"`
	Created     string `json:"created"`
	Updated     string `json:"updated"`
}

func CreateResource

func CreateResource(ctx *models.Context, resource *Resource) (*Resource, error)

func GetAllResources

func GetAllResources(ctx *models.Context, appId int) ([]Resource, error)

func GetResource

func GetResource(ctx *models.Context, id int) (*Resource, error)

func GetResources

func GetResources(ctx *models.Context, appId int, user iuser.User) ([]Resource, error)

func GetResourcesByIds

func GetResourcesByIds(ctx *models.Context, ids []int) ([]Resource, error)

func GetResourcesByRoleId

func GetResourcesByRoleId(ctx *models.Context, roleId int) ([]Resource, error)

func GetResourcesByRoleIds

func GetResourcesByRoleIds(ctx *models.Context, roleIds []int) ([]Resource, error)

func UpdateResource

func UpdateResource(ctx *models.Context, id int, name string, desc string, data string) (*Resource, error)

type Role

type Role struct {
	Id          int    `json:"id"`
	Name        string `json:"name"`
	FullName    string `json:"description"`
	SuperRoleId int    `db:"super_id" json:"parent_id"`
	AppId       int    `db:"app_id" json:"app_id"`
	Created     string `json:"created"`
	Updated     string `json:"updated"`
}

func CreateRoleWithGroup

func CreateRoleWithGroup(ctx *models.Context, roleName string, fullName string, appId int, groupId int) (*Role, error)

func CreateRoleWithoutGroup

func CreateRoleWithoutGroup(ctx *models.Context, roleName string, fullName string, appId int, superId int) (*Role, error)

func GetAppAdminRole

func GetAppAdminRole(ctx *models.Context, appId int) (*Role, error)

func GetDirectRoles

func GetDirectRoles(ctx *models.Context, user iuser.User, appId int) ([]*Role, error)

func GetRole

func GetRole(ctx *models.Context, id int) (*Role, error)

func GetRoles

func GetRoles(ctx *models.Context, username string, appId int) ([]Role, error)

func GetRolesByAppId

func GetRolesByAppId(ctx *models.Context, appId int) ([]Role, error)

func GetRolesByGroupIds

func GetRolesByGroupIds(ctx *models.Context, groupIds []int) ([]Role, error)

func GetSubTreeRoles

func GetSubTreeRoles(ctx *models.Context, roleId int) ([]*Role, error)

func UpdateRole

func UpdateRole(ctx *models.Context, id int, name string, fullname string, parent int) (*Role, error)

type RoleMembers

type RoleMembers struct {
	Role
	Type    group.MemberRole `json:"type"`
	Members []group.Member   `json:"members"`
}

func GetAllRoleMembers

func GetAllRoleMembers(ctx *models.Context, user iuser.User, appId int) ([]*RoleMembers, error)

func GetDirectRoleMembers

func GetDirectRoleMembers(ctx *models.Context, user iuser.User, appId int) ([]*RoleMembers, error)

type RoleResources

type RoleResources struct {
	RoleId    int        `json:"role_id"`
	Resources []Resource `json:"resources"`
}

func GetResourcesForRole

func GetResourcesForRole(ctx *models.Context, appId int) ([]RoleResources, error)

func GetResourcesForRoleByUser

func GetResourcesForRoleByUser(ctx *models.Context, appId int, user iuser.User) ([]RoleResources, error)

Jump to

Keyboard shortcuts

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