Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
567ff735
authored
Apr 28, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: check user's role when manage user (#30)
parent
3c31997c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
0 deletions
+28
-0
controller/user.go
+28
-0
No files found.
controller/user.go
View file @
567ff735
...
@@ -539,9 +539,23 @@ func ManageUser(c *gin.Context) {
...
@@ -539,9 +539,23 @@ func ManageUser(c *gin.Context) {
switch
req
.
Action
{
switch
req
.
Action
{
case
"disable"
:
case
"disable"
:
user
.
Status
=
common
.
UserStatusDisabled
user
.
Status
=
common
.
UserStatusDisabled
if
user
.
Role
==
common
.
RoleRootUser
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
"无法禁用超级管理员用户"
,
})
return
}
case
"enable"
:
case
"enable"
:
user
.
Status
=
common
.
UserStatusEnabled
user
.
Status
=
common
.
UserStatusEnabled
case
"delete"
:
case
"delete"
:
if
user
.
Role
==
common
.
RoleRootUser
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
"无法删除超级管理员用户"
,
})
return
}
if
err
:=
user
.
Delete
();
err
!=
nil
{
if
err
:=
user
.
Delete
();
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"success"
:
false
,
...
@@ -557,6 +571,13 @@ func ManageUser(c *gin.Context) {
...
@@ -557,6 +571,13 @@ func ManageUser(c *gin.Context) {
})
})
return
return
}
}
if
user
.
Role
>=
common
.
RoleAdminUser
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
"该用户已经是管理员"
,
})
return
}
user
.
Role
=
common
.
RoleAdminUser
user
.
Role
=
common
.
RoleAdminUser
case
"demote"
:
case
"demote"
:
if
user
.
Role
==
common
.
RoleRootUser
{
if
user
.
Role
==
common
.
RoleRootUser
{
...
@@ -566,6 +587,13 @@ func ManageUser(c *gin.Context) {
...
@@ -566,6 +587,13 @@ func ManageUser(c *gin.Context) {
})
})
return
return
}
}
if
user
.
Role
==
common
.
RoleCommonUser
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
"该用户已经是普通用户"
,
})
return
}
user
.
Role
=
common
.
RoleCommonUser
user
.
Role
=
common
.
RoleCommonUser
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment