From d59743867a32576900247ede032218ffe284b114 Mon Sep 17 00:00:00 2001 From: okatu-loli Date: Thu, 11 Sep 2025 19:15:42 +0800 Subject: [PATCH] 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 process --- server/handles/auth.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/server/handles/auth.go b/server/handles/auth.go index dd7d202b..3520a459 100644 --- a/server/handles/auth.go +++ b/server/handles/auth.go @@ -165,25 +165,25 @@ func CurrentUser(c *gin.Context) { var roleNames []string permMap := map[string]int32{} - addedPaths := map[string]bool{} + paths := make([]string, 0) for _, role := range user.RolesDetail { roleNames = append(roleNames, role.Name) for _, entry := range role.PermissionScopes { cleanPath := path.Clean("/" + strings.TrimPrefix(entry.Path, "/")) + if _, ok := permMap[cleanPath]; !ok { + paths = append(paths, cleanPath) + } permMap[cleanPath] |= entry.Permission } } userResp.RoleNames = roleNames - for fullPath, perm := range permMap { - if !addedPaths[fullPath] { - userResp.Permissions = append(userResp.Permissions, model.PermissionEntry{ - Path: fullPath, - Permission: perm, - }) - addedPaths[fullPath] = true - } + for _, fullPath := range paths { + userResp.Permissions = append(userResp.Permissions, model.PermissionEntry{ + Path: fullPath, + Permission: permMap[fullPath], + }) } common.SuccessResp(c, userResp)