This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"blazing/cool"
|
||||
|
||||
"blazing/modules/base/config"
|
||||
baseservice "blazing/modules/base/service"
|
||||
|
||||
"github.com/gogf/gf/v2/container/garray"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
@@ -73,7 +74,7 @@ func BaseAuthorityMiddleware(r *ghttp.Request) {
|
||||
cachetoken, _ := cool.CacheManager.Get(ctx, "admin:token:"+gconv.String(admin.UserId))
|
||||
rtoken := cachetoken.String()
|
||||
// 超管拥有所有权限
|
||||
if admin.UserId == 10001 && !admin.IsRefresh {
|
||||
if admin.UserId == baseservice.SuperAdminUserID && !admin.IsRefresh {
|
||||
if tokenString != rtoken && config.Config.Jwt.Sso {
|
||||
|
||||
statusCode = 401
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"blazing/common/rpc"
|
||||
"blazing/cool"
|
||||
"blazing/modules/base/config"
|
||||
baseservice "blazing/modules/base/service"
|
||||
"blazing/modules/config/service"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -181,7 +182,7 @@ func init() {
|
||||
return false
|
||||
}
|
||||
admin := token.Claims.(*cool.Claims)
|
||||
if admin.UserId != 10001 {
|
||||
if admin.UserId != baseservice.SuperAdminUserID {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ func (s *BaseSysLogService) Record(ctx g.Ctx) {
|
||||
// )
|
||||
baseSysLog.Params = r.GetBodyString()
|
||||
m := cool.DBM(s.Model)
|
||||
if baseSysLog.UserID == 10001 {
|
||||
if baseSysLog.UserID == SuperAdminUserID {
|
||||
return
|
||||
}
|
||||
m.Insert(g.Map{
|
||||
@@ -117,7 +117,7 @@ func (s *BaseSysLogService) RecordLog(userid uint32, desc string) {
|
||||
|
||||
baseSysLog.Params = desc
|
||||
m := cool.DBM(s.Model)
|
||||
if baseSysLog.UserID == 10001 {
|
||||
if baseSysLog.UserID == SuperAdminUserID {
|
||||
return
|
||||
}
|
||||
m.Insert(g.Map{
|
||||
@@ -136,7 +136,7 @@ func (s *BaseSysLogService) RecordKick(userid uint32, desc string) {
|
||||
|
||||
baseSysLog.Params = desc
|
||||
m := cool.DBM(s.Model)
|
||||
if baseSysLog.UserID == 10001 {
|
||||
if baseSysLog.UserID == SuperAdminUserID {
|
||||
return
|
||||
}
|
||||
m.Insert(g.Map{
|
||||
|
||||
@@ -29,7 +29,7 @@ func (c *BaseSysPermsService) Permmenu(ctx context.Context, roleIds []string) (r
|
||||
|
||||
res = &permmenu{
|
||||
Perms: baseSysMenuService.GetPerms(roleIds),
|
||||
Menus: baseSysMenuService.GetMenus(admin.RoleIds, admin.UserId == 10001),
|
||||
Menus: baseSysMenuService.GetMenus(admin.RoleIds, admin.UserId == SuperAdminUserID),
|
||||
}
|
||||
|
||||
return
|
||||
@@ -47,7 +47,7 @@ func (c *BaseSysPermsService) RefreshPerms(ctx context.Context, userId uint) (er
|
||||
)
|
||||
cool.CacheManager.Set(ctx, "admin:perms:"+gconv.String(userId), perms, 0)
|
||||
// 更新部门权限
|
||||
departments := baseSysDepartmentService.GetByRoleIds(roleIds, userId == 10001)
|
||||
departments := baseSysDepartmentService.GetByRoleIds(roleIds, userId == SuperAdminUserID)
|
||||
cool.CacheManager.Set(ctx, "admin:department:"+gconv.String(userId), departments, 0)
|
||||
|
||||
return
|
||||
|
||||
@@ -159,7 +159,7 @@ func (s *BaseSysUserService) ModifyBefore(ctx context.Context, method string, pa
|
||||
// 禁止删除超级管理员
|
||||
userIds := garray.NewIntArrayFrom(gconv.Ints(param["ids"]))
|
||||
currentId, found := userIds.Get(0)
|
||||
superAdminId := 10001
|
||||
superAdminId := int(SuperAdminUserID)
|
||||
|
||||
if userIds.Len() == 1 && found && currentId == superAdminId {
|
||||
err = gerror.New("超级管理员不能删除")
|
||||
@@ -167,7 +167,7 @@ func (s *BaseSysUserService) ModifyBefore(ctx context.Context, method string, pa
|
||||
}
|
||||
|
||||
// 删除超级管理员
|
||||
userIds.RemoveValue(10001)
|
||||
userIds.RemoveValue(superAdminId)
|
||||
g.RequestFromCtx(ctx).SetParam("ids", userIds.Slice())
|
||||
}
|
||||
return
|
||||
@@ -419,7 +419,7 @@ func (s *BaseSysUserService) ServiceUpdate(ctx context.Context, req *cool.Update
|
||||
}
|
||||
|
||||
// 禁止禁用超级管理员
|
||||
if userId == 10001 && (!r.Get("status").IsNil() && r.Get("status").Int() == 0) {
|
||||
if userId == SuperAdminUserID && (!r.Get("status").IsNil() && r.Get("status").Int() == 0) {
|
||||
err = gerror.New("禁止禁用超级管理员")
|
||||
return
|
||||
}
|
||||
@@ -545,7 +545,7 @@ func NewBaseSysUserService() *BaseSysUserService {
|
||||
Where: func(ctx context.Context) []g.Array {
|
||||
r := g.RequestFromCtx(ctx).GetMap()
|
||||
return []g.Array{
|
||||
{"id != ?", g.Slice{"10001"}, true}, //排除管理员
|
||||
{"id != ?", g.Slice{gconv.String(SuperAdminUserID)}, true}, //排除管理员
|
||||
{`("departmentId" IN (?))`, gconv.SliceStr(r["departmentIds"])},
|
||||
}
|
||||
},
|
||||
|
||||
3
modules/base/service/super_admin.go
Normal file
3
modules/base/service/super_admin.go
Normal file
@@ -0,0 +1,3 @@
|
||||
package service
|
||||
|
||||
const SuperAdminUserID uint = 1000100
|
||||
Reference in New Issue
Block a user