Files
jx-callback/business/authz/authz.go
gazebo b51614946f - 重构authz结构
- 角色管理初版完成
2019-08-08 17:06:58 +08:00

54 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package authz
import (
"strings"
"git.rosy.net.cn/baseapi/utils"
)
const (
StoreRoleBoss = "StoreBoss"
RoleNameSep = "/"
RolePrefix = "Role"
StoreRolePrefix = "Store"
)
type RoleInfo struct {
Name string `json:"name"`
Description string `json:"description"`
StoreID int `json:"storeID,omitempty"` // 如果这个值非0表示门店角色
}
var (
StoreRoleDescriptionMap = map[string]string{
StoreRoleBoss: "门店老板",
}
StoreRoleList = []*RoleInfo{
&RoleInfo{
Name: StoreRoleBoss,
Description: StoreRoleDescriptionMap[StoreRoleBoss],
},
}
)
type IAuthz interface {
AddRole4User(userID string, r *RoleInfo) (err error)
DeleteRole4User(userID string, r *RoleInfo) (err error)
GetUserRoleList(userID string) (roleList []*RoleInfo, err error)
GetRoleUserList(r *RoleInfo) (userIDList []string, err error)
// GetAllRoleList() (roleList []*RoleInfo)
}
func (r *RoleInfo) GetFullName() (fullRoleName string) {
strList := []string{
RolePrefix,
r.Name,
}
if r.StoreID > 0 {
strList = append(strList, StoreRolePrefix, utils.Int2Str(r.StoreID))
}
fullRoleName = strings.Join(strList, RoleNameSep)
return fullRoleName
}