- 角色管理初版
This commit is contained in:
@@ -2,16 +2,21 @@ package cms
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils/errlist"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/dingding"
|
||||
"git.rosy.net.cn/jx-callback/business/authz"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"git.rosy.net.cn/jx-callback/globals/api2"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -156,3 +161,76 @@ func OnDingDingMsg(msg map[string]interface{}) (callbackResponse *dingdingapi.Ca
|
||||
func GetUsers(ctx *jxcontext.Context, userType int, keyword string, userIDs []string, userID2, mobile string) (userList []*model.User, err error) {
|
||||
return dao.GetUsers(dao.GetDB(), userType, keyword, userIDs, userID2, mobile)
|
||||
}
|
||||
|
||||
func GetMyStoreListNew(ctx *jxcontext.Context) (storeList []*dao.StoreWithCityName, err error) {
|
||||
mobileNum, userID := ctx.GetMobileAndUserID()
|
||||
if mobileNum == "" {
|
||||
return nil, fmt.Errorf("不能得到用户手机号")
|
||||
}
|
||||
roleList, err := api2.RoleMan.GetUserRoleList(userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
storeList, err = dao.GetStoreListByMobileOrStoreIDs(dao.GetDB(), mobileNum, authz.RoleList2StoreIDList(roleList))
|
||||
return storeList, err
|
||||
}
|
||||
|
||||
func GetStoreRoleList(ctx *jxcontext.Context) (roleList []*authz.RoleInfo, err error) {
|
||||
return authz.StoreRoleList, nil
|
||||
}
|
||||
|
||||
func GetUserRoleList(ctx *jxcontext.Context, userID string) (roleList []*authz.RoleInfo, err error) {
|
||||
return api2.RoleMan.GetUserRoleList(userID)
|
||||
}
|
||||
|
||||
func GetRoleUserList(ctx *jxcontext.Context, r *authz.RoleInfo) (userIDList []string, err error) {
|
||||
return api2.RoleMan.GetRoleUserList(r)
|
||||
}
|
||||
|
||||
func AddRoles4User(ctx *jxcontext.Context, userID string, rList []*authz.RoleInfo) (err error) {
|
||||
errList := errlist.New()
|
||||
for _, v := range rList {
|
||||
if err = authz.ValidateRole(v.Name, v.StoreID); err == nil {
|
||||
if err = api2.RoleMan.AddRole4User(userID, v); err != nil {
|
||||
errList.AddErr(err)
|
||||
}
|
||||
} else {
|
||||
errList.AddErr(err)
|
||||
}
|
||||
}
|
||||
return errList.GetErrListAsOne()
|
||||
}
|
||||
|
||||
func DeleteRoles4User(ctx *jxcontext.Context, userID string, rList []*authz.RoleInfo) (err error) {
|
||||
errList := errlist.New()
|
||||
for _, v := range rList {
|
||||
if err = api2.RoleMan.DeleteRole4User(userID, v); err != nil {
|
||||
errList.AddErr(err)
|
||||
}
|
||||
}
|
||||
return errList.GetErrListAsOne()
|
||||
}
|
||||
|
||||
func AddUsers4Role(ctx *jxcontext.Context, r *authz.RoleInfo, userIDList []string) (err error) {
|
||||
if err = authz.ValidateRole(r.Name, r.StoreID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
errList := errlist.New()
|
||||
for _, v := range userIDList {
|
||||
if err = api2.RoleMan.AddRole4User(v, r); err != nil {
|
||||
errList.AddErr(err)
|
||||
}
|
||||
}
|
||||
return errList.GetErrListAsOne()
|
||||
}
|
||||
|
||||
func DeleteUsers4Role(ctx *jxcontext.Context, r *authz.RoleInfo, userIDList []string) (err error) {
|
||||
errList := errlist.New()
|
||||
for _, v := range userIDList {
|
||||
if err = api2.RoleMan.DeleteRole4User(v, r); err != nil {
|
||||
errList.AddErr(err)
|
||||
}
|
||||
}
|
||||
return errList.GetErrListAsOne()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user