- 重构authz结构

- 角色管理初版完成
This commit is contained in:
gazebo
2019-08-08 17:06:58 +08:00
parent 60f3ec9c3b
commit b51614946f
18 changed files with 161 additions and 98 deletions

View File

@@ -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
}