Adress all reviewer feedback

This commit is contained in:
Excellencedev committed 2025-12-19 05:39:06 +01:00
1 parent 92506da0ff
commit 8daef631cf
6 files changed
+85 -107

No files matched your search

+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright 2024 The Gitea Authors. All rights reserved.
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package actions
+10 -20
View File
@@ -196,8 +196,8 @@ type ActionsTokenPermissions struct {
Wiki perm.AccessMode `json:"wiki"`
}
// HasRead checks if the permission has read access for the given scope
func (p ActionsTokenPermissions) HasRead(scope string) bool {
// HasAccess checks if the permission meets the required access level for the given scope
func (p ActionsTokenPermissions) HasAccess(scope string, required perm.AccessMode) bool {
var mode perm.AccessMode
switch scope {
case "actions":
@@ -213,27 +213,17 @@ func (p ActionsTokenPermissions) HasRead(scope string) bool {
case "wiki":
mode = p.Wiki
}
return mode >= perm.AccessModeRead
return mode >= required
}
// HasWrite checks if the permission has write access for the given scope
// HasRead checks if the permission has read access for the given scope (convenience wrapper for templates)
func (p ActionsTokenPermissions) HasRead(scope string) bool {
return p.HasAccess(scope, perm.AccessModeRead)
}
// HasWrite checks if the permission has write access for the given scope (convenience wrapper for templates)
func (p ActionsTokenPermissions) HasWrite(scope string) bool {
var mode perm.AccessMode
switch scope {
case "actions":
mode = p.Actions
case "contents":
mode = p.Contents
case "issues":
mode = p.Issues
case "packages":
mode = p.Packages
case "pull_requests":
mode = p.PullRequests
case "wiki":
mode = p.Wiki
}
return mode >= perm.AccessModeWrite
return p.HasAccess(scope, perm.AccessModeWrite)
}
// DefaultActionsTokenPermissions returns the default permissions for permissive mode