用户接口调整
This commit is contained in:
@@ -29,7 +29,7 @@ func Routers() []services.RouterItem {
|
||||
rs := [...]services.RouterItem{
|
||||
{
|
||||
Method: "GET",
|
||||
Pattern: "/userManage/{apiVersion}/list",
|
||||
Pattern: "/users",
|
||||
Handler: apis.List,
|
||||
Middleware: midware.Authorize(map[string][]string{
|
||||
"hasPerms": {"system:user:list"},
|
||||
@@ -37,7 +37,7 @@ func Routers() []services.RouterItem {
|
||||
},
|
||||
{
|
||||
Method: "GET",
|
||||
Pattern: "/userManage/{apiVersion}/info/{userId}",
|
||||
Pattern: "/user/{userId}",
|
||||
Handler: apis.Info,
|
||||
Middleware: midware.Authorize(map[string][]string{
|
||||
"hasPerms": {"system:user:query"},
|
||||
@@ -45,7 +45,7 @@ func Routers() []services.RouterItem {
|
||||
},
|
||||
{
|
||||
Method: "POST",
|
||||
Pattern: "/userManage/{apiVersion}/add",
|
||||
Pattern: "/user",
|
||||
Handler: apis.Add,
|
||||
Middleware: midware.Authorize(map[string][]string{
|
||||
"hasPerms": {"system:user:add"},
|
||||
@@ -53,7 +53,7 @@ func Routers() []services.RouterItem {
|
||||
},
|
||||
{
|
||||
Method: "PUT",
|
||||
Pattern: "/userManage/{apiVersion}/edit",
|
||||
Pattern: "/user",
|
||||
Handler: apis.Edit,
|
||||
Middleware: midware.Authorize(map[string][]string{
|
||||
"hasPerms": {"system:user:edit"},
|
||||
@@ -61,7 +61,7 @@ func Routers() []services.RouterItem {
|
||||
},
|
||||
{
|
||||
Method: "DELETE",
|
||||
Pattern: "/userManage/{apiVersion}/del/{userIds}",
|
||||
Pattern: "/user/{userIds}",
|
||||
Handler: apis.Remove,
|
||||
Middleware: midware.Authorize(map[string][]string{
|
||||
"hasPerms": {"system:user:edit"},
|
||||
@@ -73,7 +73,7 @@ func Routers() []services.RouterItem {
|
||||
// 生成两组前缀路由
|
||||
rsPrefix := []services.RouterItem{}
|
||||
for _, v := range rs {
|
||||
path := v.Pattern
|
||||
path := "/userManage/{apiVersion}" + v.Pattern
|
||||
// 固定前缀
|
||||
v.Pattern = config.DefaultUriPrefix + path
|
||||
rsPrefix = append(rsPrefix, v)
|
||||
@@ -139,7 +139,6 @@ func (s *SysUserApi) Info(w http.ResponseWriter, r *http.Request) {
|
||||
ctx.JSON(w, 200, result.OkData(map[string]any{
|
||||
"user": map[string]any{},
|
||||
"roleIds": []string{},
|
||||
"postIds": []string{},
|
||||
"roles": roles,
|
||||
}))
|
||||
return
|
||||
@@ -177,9 +176,9 @@ func (s *SysUserApi) Add(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// 检查用户登录账号是否唯一
|
||||
uniqueUserName := s.sysUserService.CheckUniqueUserName(body.Name, "")
|
||||
uniqueUserName := s.sysUserService.CheckUniqueUserName(body.AccountId, "")
|
||||
if !uniqueUserName {
|
||||
msg := fmt.Sprintf("新增用户【%s】失败,登录账号已存在", body.Name)
|
||||
msg := fmt.Sprintf("新增用户【%s】失败,登录账号已存在", body.AccountId)
|
||||
ctx.JSON(w, 200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
@@ -204,10 +203,10 @@ func (s *SysUserApi) Edit(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// 检查是否管理员用户
|
||||
if conf.IsAdmin(body.Id) {
|
||||
ctx.JSON(w, 200, result.ErrMsg("不允许操作管理员用户"))
|
||||
return
|
||||
}
|
||||
// if conf.IsAdmin(body.Id) {
|
||||
// ctx.JSON(w, 200, result.ErrMsg("不允许操作管理员用户"))
|
||||
// return
|
||||
// }
|
||||
|
||||
user := s.sysUserService.SelectUserById(body.Id)
|
||||
if user.Id != body.Id {
|
||||
@@ -216,15 +215,15 @@ func (s *SysUserApi) Edit(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// 检查用户登录账号是否唯一
|
||||
uniqueUserName := s.sysUserService.CheckUniqueUserName(body.Name, body.Id)
|
||||
uniqueUserName := s.sysUserService.CheckUniqueUserName(body.AccountId, body.Id)
|
||||
if !uniqueUserName {
|
||||
msg := fmt.Sprintf("修改用户【%s】失败,登录账号已存在", body.Name)
|
||||
msg := fmt.Sprintf("修改用户【%s】失败,登录账号已存在", body.AccountId)
|
||||
ctx.JSON(w, 200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
body.Name = "" // 忽略修改登录用户名称
|
||||
body.Password = "" // 忽略修改密码
|
||||
body.AccountId = "" // 忽略修改登录用户名称
|
||||
// body.Password = "" // 忽略修改密码
|
||||
rows := s.sysUserService.UpdateUserAndRolePost(body)
|
||||
if rows > 0 {
|
||||
ctx.JSON(w, 200, result.Ok(nil))
|
||||
|
||||
Reference in New Issue
Block a user