- 重构authz结构
- 角色管理初版完成
This commit is contained in:
@@ -1,5 +1,37 @@
|
||||
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)
|
||||
@@ -7,3 +39,15 @@ type IAuthz interface {
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user