From 1f0625a277e6ce19e5633a2624fcb7e044d04a29 Mon Sep 17 00:00:00 2001
From: Denys Konovalov
Date: Mon, 4 Mar 2024 21:49:21 +0100
Subject: [PATCH] Fix projects mode bugs (#29593)
Fix for regressions introduced by #28805
Enabled projects on repos created before the PR weren't detected. Also,
the way projects mode was detected in settings didn't match the way it
was detected on permission check, which leads to confusion.
Co-authored-by: Giteabot
---
models/fixtures/repo_unit.yml | 1 -
models/repo/repo.go | 4 +++-
models/repo/repo_unit.go | 2 +-
templates/repo/settings/options.tmpl | 12 ++++++------
4 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/models/fixtures/repo_unit.yml b/models/fixtures/repo_unit.yml
index 6714294e2b..8a22db0445 100644
--- a/models/fixtures/repo_unit.yml
+++ b/models/fixtures/repo_unit.yml
@@ -520,7 +520,6 @@
id: 75
repo_id: 1
type: 8
- config: "{\"ProjectsMode\":\"all\"}"
created_unix: 946684810
-
diff --git a/models/repo/repo.go b/models/repo/repo.go
index ad2e21b66b..f6758f1591 100644
--- a/models/repo/repo.go
+++ b/models/repo/repo.go
@@ -412,9 +412,11 @@ func (repo *Repository) MustGetUnit(ctx context.Context, tp unit.Type) *RepoUnit
Config: new(ActionsConfig),
}
} else if tp == unit.TypeProjects {
+ cfg := new(ProjectsConfig)
+ cfg.ProjectsMode = ProjectsModeNone
return &RepoUnit{
Type: tp,
- Config: new(ProjectsConfig),
+ Config: cfg,
}
}
diff --git a/models/repo/repo_unit.go b/models/repo/repo_unit.go
index 6b9dde7faf..5a841f4d31 100644
--- a/models/repo/repo_unit.go
+++ b/models/repo/repo_unit.go
@@ -236,7 +236,7 @@ func (cfg *ProjectsConfig) GetProjectsMode() ProjectsMode {
return cfg.ProjectsMode
}
- return ProjectsModeNone
+ return ProjectsModeAll
}
func (cfg *ProjectsConfig) IsProjectsAllowed(m ProjectsMode) bool {
diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl
index 376cfe7607..0de42b34ea 100644
--- a/templates/repo/settings/options.tmpl
+++ b/templates/repo/settings/options.tmpl
@@ -460,19 +460,19 @@
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
- {{if (eq $projectsUnit.ProjectsConfig.ProjectsMode "repo")}}
+ {{if (eq $projectsUnit.ProjectsConfig.GetProjectsMode "repo")}}
{{ctx.Locale.Tr "repo.settings.projects_mode_repo"}}
{{end}}
- {{if (eq $projectsUnit.ProjectsConfig.ProjectsMode "owner")}}
+ {{if (eq $projectsUnit.ProjectsConfig.GetProjectsMode "owner")}}
{{ctx.Locale.Tr "repo.settings.projects_mode_owner"}}
{{end}}
- {{if (eq $projectsUnit.ProjectsConfig.ProjectsMode "all")}}
+ {{if (eq $projectsUnit.ProjectsConfig.GetProjectsMode "all")}}
{{ctx.Locale.Tr "repo.settings.projects_mode_all"}}
{{end}}