mirror of https://github.com/Xhofe/alist
refactor (auth): Optimize permission path processing logic
- Changed permission path collection from map to slice to improve code readability - Removed redundant path checks to improve path addition efficiency - Restructured the loop logic for path processing to simplify the path permission assignment processpull/9320/head
parent
fcbc79cb24
commit
d59743867a
|
@ -165,25 +165,25 @@ func CurrentUser(c *gin.Context) {
|
||||||
|
|
||||||
var roleNames []string
|
var roleNames []string
|
||||||
permMap := map[string]int32{}
|
permMap := map[string]int32{}
|
||||||
addedPaths := map[string]bool{}
|
paths := make([]string, 0)
|
||||||
|
|
||||||
for _, role := range user.RolesDetail {
|
for _, role := range user.RolesDetail {
|
||||||
roleNames = append(roleNames, role.Name)
|
roleNames = append(roleNames, role.Name)
|
||||||
for _, entry := range role.PermissionScopes {
|
for _, entry := range role.PermissionScopes {
|
||||||
cleanPath := path.Clean("/" + strings.TrimPrefix(entry.Path, "/"))
|
cleanPath := path.Clean("/" + strings.TrimPrefix(entry.Path, "/"))
|
||||||
|
if _, ok := permMap[cleanPath]; !ok {
|
||||||
|
paths = append(paths, cleanPath)
|
||||||
|
}
|
||||||
permMap[cleanPath] |= entry.Permission
|
permMap[cleanPath] |= entry.Permission
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
userResp.RoleNames = roleNames
|
userResp.RoleNames = roleNames
|
||||||
|
|
||||||
for fullPath, perm := range permMap {
|
for _, fullPath := range paths {
|
||||||
if !addedPaths[fullPath] {
|
userResp.Permissions = append(userResp.Permissions, model.PermissionEntry{
|
||||||
userResp.Permissions = append(userResp.Permissions, model.PermissionEntry{
|
Path: fullPath,
|
||||||
Path: fullPath,
|
Permission: permMap[fullPath],
|
||||||
Permission: perm,
|
})
|
||||||
})
|
|
||||||
addedPaths[fullPath] = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
common.SuccessResp(c, userResp)
|
common.SuccessResp(c, userResp)
|
||||||
|
|
Loading…
Reference in New Issue