From 88bde3151590b4110a3c41f6072e8ae30f983ae4 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Fri, 19 May 2023 09:17:48 -0400 Subject: [PATCH] Fix Actions being enabled accidentally (#24802) (#24810) Backport #24802 by @wolfogre Regression of #24536. If the user doesn't explicitly disable Actions, it will be enabled. 1. Gitea will call `loadRepositoryFrom` before `loadActionsFrom`. https://github.com/go-gitea/gitea/blob/25d4f95df25dae5226e96e813dde87b071d9155e/modules/setting/setting.go#L234-L237 2. In `loadRepositoryFrom`, `rootCfg.Section("actions").Key("ENABLED").MustBool(true)` will set `actions.ENABLED` with `true`. https://github.com/go-gitea/gitea/blob/25d4f95df25dae5226e96e813dde87b071d9155e/modules/setting/repository.go#L313-L315 3. In `loadActionsFrom`, `rootCfg.Section("actions")` will get a section with Actions enabled. https://github.com/go-gitea/gitea/blob/25d4f95df25dae5226e96e813dde87b071d9155e/modules/setting/actions.go#L23-L26 Although the cause of the problem was using `true` by copy-paste mistake, it also surprised me that **`rootCfg.Section("actions").Key("ENABLED").MustBool(true)` doesn't only read, but also write.** Co-authored-by: Jason Song (cherry picked from commit b369ed579d438ee3b06ee23eee9fada1d08b49cc) --- modules/setting/repository.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/setting/repository.go b/modules/setting/repository.go index bb133f21ac..2d10f68d27 100644 --- a/modules/setting/repository.go +++ b/modules/setting/repository.go @@ -307,11 +307,11 @@ func loadRepositoryFrom(rootCfg ConfigProvider) { log.Fatal("Failed to map Repository.PullRequest settings: %v", err) } - if !rootCfg.Section("packages").Key("ENABLED").MustBool(true) { + if !rootCfg.Section("packages").Key("ENABLED").MustBool(Packages.Enabled) { Repository.DisabledRepoUnits = append(Repository.DisabledRepoUnits, "repo.packages") } - if !rootCfg.Section("actions").Key("ENABLED").MustBool(true) { + if !rootCfg.Section("actions").Key("ENABLED").MustBool(Actions.Enabled) { Repository.DisabledRepoUnits = append(Repository.DisabledRepoUnits, "repo.actions") }