|
@@ -57,9 +57,9 @@ func (m *AuthorityMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
|
|
result := batchCheck(m.Cbn, roleIds, act, obj)
|
|
|
|
|
|
if result {
|
|
|
- logx.Infow("HTTP/HTTPS Request", logx.Field("UUID", r.Context().Value("userId").(string)),
|
|
|
- logx.Field("path", obj), logx.Field("method", act))
|
|
|
userIdStr := r.Context().Value("userId").(string)
|
|
|
+ logx.Infow("HTTP/HTTPS Request", logx.Field("UUID", userIdStr),
|
|
|
+ logx.Field("path", obj), logx.Field("method", act))
|
|
|
data, err := m.CoreRpc.GetUserById(r.Context(), &core.UUIDReq{Id: userIdStr})
|
|
|
if err != nil {
|
|
|
logx.Errorw("get user info error", logx.Field("detail", err.Error()))
|
|
@@ -69,6 +69,7 @@ func (m *AuthorityMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
|
|
// 将 data.DepartmentID 插入上下文,以供后续接口使用
|
|
|
//fmt.Printf("---------------departmentId----------------: %d\n\n", *data.DepartmentId)
|
|
|
r = r.WithContext(context.WithValue(r.Context(), "organizationId", *data.DepartmentId))
|
|
|
+ r = r.WithContext(context.WithValue(r.Context(), "isAdmin", stringInSlice(roleIds, []string{"001"})))
|
|
|
next(w, r)
|
|
|
return
|
|
|
} else {
|
|
@@ -100,3 +101,14 @@ func batchCheck(cbn *casbin.Enforcer, roleIds, act, obj string) bool {
|
|
|
|
|
|
return false
|
|
|
}
|
|
|
+
|
|
|
+func stringInSlice(roleIds string, list []string) bool {
|
|
|
+ for _, r := range strings.Split(roleIds, ",") {
|
|
|
+ for _, v := range list {
|
|
|
+ if v == r {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|