Skip to content

Commit abedb9e

Browse files
committed
feat(user): Enhanced role assignment logic
- Imported the `utils` package - Modified the role assignment logic to prevent assigning administrator or guest roles to users
1 parent c64f899 commit abedb9e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

server/handles/user.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package handles
22

33
import (
4-
"github.com/alist-org/alist/v3/pkg/utils"
54
"strconv"
65

6+
"github.com/alist-org/alist/v3/pkg/utils"
7+
78
"github.com/alist-org/alist/v3/internal/model"
89
"github.com/alist-org/alist/v3/internal/op"
910
"github.com/alist-org/alist/v3/server/common"
@@ -97,6 +98,14 @@ func UpdateUser(c *gin.Context) {
9798
return
9899
}
99100
}
101+
102+
if !utils.SliceEqual(user.Role, req.Role) {
103+
if req.IsAdmin() || req.IsGuest() {
104+
common.ErrorStrResp(c, "cannot assign admin or guest role to user", 400, true)
105+
return
106+
}
107+
}
108+
100109
if err := op.UpdateUser(&req); err != nil {
101110
common.ErrorResp(c, err, 500)
102111
} else {

0 commit comments

Comments
 (0)