diff --git a/models/actions/config.go b/models/actions/config.go
index bb04f8a3ca..7bd64b74d4 100644
--- a/models/actions/config.go
+++ b/models/actions/config.go
@@ -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
diff --git a/models/repo/repo_unit.go b/models/repo/repo_unit.go
index 4c3b212f7b..e84a52439c 100644
--- a/models/repo/repo_unit.go
+++ b/models/repo/repo_unit.go
@@ -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
diff --git a/templates/org/settings/actions_general.tmpl b/templates/org/settings/actions_general.tmpl
index 4c3c5cd266..e56925bcff 100644
--- a/templates/org/settings/actions_general.tmpl
+++ b/templates/org/settings/actions_general.tmpl
@@ -43,11 +43,11 @@
@@ -57,11 +57,11 @@
@@ -71,11 +71,11 @@
@@ -85,11 +85,11 @@
@@ -99,11 +99,11 @@
@@ -113,11 +113,11 @@
@@ -148,11 +148,11 @@
@@ -162,11 +162,11 @@
@@ -176,11 +176,11 @@
@@ -190,11 +190,11 @@
@@ -204,11 +204,11 @@
@@ -218,11 +218,11 @@
@@ -232,22 +232,3 @@
{{template "org/settings/layout_footer" .}}
-
-
diff --git a/templates/repo/settings/actions_general.tmpl b/templates/repo/settings/actions_general.tmpl
index 93d3da6a89..4b801936a7 100644
--- a/templates/repo/settings/actions_general.tmpl
+++ b/templates/repo/settings/actions_general.tmpl
@@ -113,11 +113,11 @@
@@ -127,11 +127,11 @@
@@ -141,11 +141,11 @@
@@ -155,11 +155,11 @@
@@ -169,11 +169,11 @@
@@ -183,11 +183,11 @@
@@ -204,11 +204,11 @@
@@ -218,11 +218,11 @@
@@ -232,11 +232,11 @@
@@ -246,11 +246,11 @@
@@ -260,11 +260,11 @@
@@ -274,11 +274,11 @@
@@ -296,22 +296,3 @@
{{end}}
-
-
diff --git a/web_src/js/features/repo-settings-actions.ts b/web_src/js/features/repo-settings-actions.ts
new file mode 100644
index 0000000000..3b0f93ba57
--- /dev/null
+++ b/web_src/js/features/repo-settings-actions.ts
@@ -0,0 +1,24 @@
+export function initRepoSettingsActionsPermissions(): void {
+ const radios = document.querySelectorAll(
+ 'input[name="token_permission_mode"]',
+ );
+ if (!radios.length) return;
+
+ function toggleCustom(): void {
+ const customPerms = document.querySelector('#custom-permissions');
+ if (!customPerms) return;
+
+ const selected = document.querySelector(
+ 'input[name="token_permission_mode"]:checked',
+ );
+
+ customPerms.style.display =
+ selected?.value === 'custom' ? 'block' : 'none';
+ }
+
+ for (const radio of radios) {
+ radio.addEventListener('change', toggleCustom);
+ }
+
+ toggleCustom();
+}
diff --git a/web_src/js/index-domready.ts b/web_src/js/index-domready.ts
index 660e5c0989..da1f3f80d0 100644
--- a/web_src/js/index-domready.ts
+++ b/web_src/js/index-domready.ts
@@ -64,6 +64,7 @@ import {initGlobalButtonClickOnEnter, initGlobalButtons, initGlobalDeleteButton}
import {initGlobalComboMarkdownEditor, initGlobalEnterQuickSubmit, initGlobalFormDirtyLeaveConfirm} from './features/common-form.ts';
import {callInitFunctions} from './modules/init.ts';
import {initRepoViewFileTree} from './features/repo-view-file-tree.ts';
+import {initRepoSettingsActionsPermissions} from './features/repo-settings-actions.ts';
const initStartTime = performance.now();
const initPerformanceTracer = callInitFunctions([
@@ -158,6 +159,7 @@ const initPerformanceTracer = callInitFunctions([
initOAuth2SettingsDisableCheckbox,
initRepoFileView,
+ initRepoSettingsActionsPermissions,
]);
// it must be the last one, then the "querySelectorAll" only needs to be executed once for global init functions.