Skip to content

Commit 49bfec4

Browse files
authored
refactor: use slices.Contains to check the permission (#3940)
Signed-off-by: chlins <chlins.zhang@gmail.com>
1 parent e8166e4 commit 49bfec4

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

manager/middlewares/personal_access_token.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"net/http"
2222
"regexp"
23+
"slices"
2324
"strings"
2425
"time"
2526

@@ -127,13 +128,7 @@ func hasPermission(permissions []string, requiredPermission string) bool {
127128
return true
128129
}
129130

130-
for _, permission := range permissions {
131-
if permission == requiredPermission {
132-
return true
133-
}
134-
}
135-
136-
return false
131+
return slices.Contains(permissions, requiredPermission)
137132
}
138133

139134
// requiredPermission extracts the resource type from the path and returns the required permission.

0 commit comments

Comments
 (0)