feat: 添加检查是否为管理员的接口
This commit is contained in:
@@ -155,6 +155,11 @@ type IsSuperAdminReq struct {
|
|||||||
commonApi.Author
|
commonApi.Author
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type IsAdminReq struct {
|
||||||
|
g.Meta `path:"/user/checkIsAdmin" tags:"用户管理" method:"get" summary:"是否是管理员"`
|
||||||
|
commonApi.Author
|
||||||
|
}
|
||||||
|
|
||||||
type IsSuperAdminRes struct {
|
type IsSuperAdminRes struct {
|
||||||
g.Meta `mime:"application/json"`
|
g.Meta `mime:"application/json"`
|
||||||
IsSuperAdmin bool `json:"isSuperAdmin"`
|
IsSuperAdmin bool `json:"isSuperAdmin"`
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ package consts
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
SuperAdminId = 1 // 超级管理员
|
SuperAdminId = 1 // 超级管理员
|
||||||
SalesAgentId = 9 // 销售代理
|
SalesAgentId = 9 // 租户代理管理员
|
||||||
SiteAdminId = 10 // 站点管理员
|
SiteAdminId = 10 // 租户普通管理员
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -135,3 +135,9 @@ func (c *userController) IsSuperAdmin(ctx context.Context, req *system.IsSuperAd
|
|||||||
IsSuperAdminRes.IsSuperAdmin, err = service.SysUser().IsSuperAdmin(ctx, req)
|
IsSuperAdminRes.IsSuperAdmin, err = service.SysUser().IsSuperAdmin(ctx, req)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *userController) IsAdmin(ctx context.Context, req *system.IsAdminReq) (IsSuperAdminRes *system.IsSuperAdminRes, err error) {
|
||||||
|
IsSuperAdminRes = new(system.IsSuperAdminRes)
|
||||||
|
IsSuperAdminRes.IsSuperAdmin, err = service.SysUser().IsAdmin(ctx, req)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ package sysUser
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"gitea.com/red-future/common/beans"
|
"gitea.com/red-future/common/beans"
|
||||||
"gitea.com/red-future/common/utils"
|
"gitea.com/red-future/common/utils"
|
||||||
"github.com/gogf/gf/v2/container/gset"
|
"github.com/gogf/gf/v2/container/gset"
|
||||||
@@ -782,3 +783,28 @@ func (s *sSysUser) IsSuperAdmin(ctx context.Context, req *system.IsSuperAdminReq
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *sSysUser) IsAdmin(ctx context.Context, req *system.IsAdminReq) (isSuperAdmin bool, err error) {
|
||||||
|
_ = req
|
||||||
|
isSuperAdmin = false
|
||||||
|
// 获取用户id
|
||||||
|
getUserInfo, err := utils.GetUserInfo(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
userId := getUserInfo.Id
|
||||||
|
if !g.IsEmpty(userId) {
|
||||||
|
var roleIds []uint
|
||||||
|
roleIds, err = service.SysUser().GetAdminRoleIds(ctx, gconv.Uint64(userId))
|
||||||
|
liberr.ErrIsNil(ctx, err, "获取用户角色失败")
|
||||||
|
for _, v := range roleIds {
|
||||||
|
if v == consts.SuperAdminId || v == consts.SiteAdminId {
|
||||||
|
isSuperAdmin = true
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
isSuperAdmin = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ type (
|
|||||||
Delete(ctx context.Context, ids []int) (err error)
|
Delete(ctx context.Context, ids []int) (err error)
|
||||||
GetUsers(ctx context.Context, ids []int) (users []*model.SysUserSimpleRes, err error)
|
GetUsers(ctx context.Context, ids []int) (users []*model.SysUserSimpleRes, err error)
|
||||||
IsSuperAdmin(ctx context.Context, req *system.IsSuperAdminReq) (isSuperAdmin bool, err error)
|
IsSuperAdmin(ctx context.Context, req *system.IsSuperAdminReq) (isSuperAdmin bool, err error)
|
||||||
|
IsAdmin(ctx context.Context, req *system.IsAdminReq) (isSuperAdmin bool, err error)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user