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 <teabot@gitea.io>
This commit is contained in:
Denys Konovalov 2024-03-04 21:49:21 +01:00 committed by GitHub
parent da3b7f5039
commit 1f0625a277
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 9 deletions

View File

@ -520,7 +520,6 @@
id: 75 id: 75
repo_id: 1 repo_id: 1
type: 8 type: 8
config: "{\"ProjectsMode\":\"all\"}"
created_unix: 946684810 created_unix: 946684810
- -

View File

@ -412,9 +412,11 @@ func (repo *Repository) MustGetUnit(ctx context.Context, tp unit.Type) *RepoUnit
Config: new(ActionsConfig), Config: new(ActionsConfig),
} }
} else if tp == unit.TypeProjects { } else if tp == unit.TypeProjects {
cfg := new(ProjectsConfig)
cfg.ProjectsMode = ProjectsModeNone
return &RepoUnit{ return &RepoUnit{
Type: tp, Type: tp,
Config: new(ProjectsConfig), Config: cfg,
} }
} }

View File

@ -236,7 +236,7 @@ func (cfg *ProjectsConfig) GetProjectsMode() ProjectsMode {
return cfg.ProjectsMode return cfg.ProjectsMode
} }
return ProjectsModeNone return ProjectsModeAll
} }
func (cfg *ProjectsConfig) IsProjectsAllowed(m ProjectsMode) bool { func (cfg *ProjectsConfig) IsProjectsAllowed(m ProjectsMode) bool {

View File

@ -460,19 +460,19 @@
</p> </p>
<div class="ui dropdown selection"> <div class="ui dropdown selection">
<select name="projects_mode"> <select name="projects_mode">
<option value="repo" {{if or (not $isProjectsEnabled) (eq $projectsUnit.ProjectsConfig.ProjectsMode "repo")}}selected{{end}}>{{ctx.Locale.Tr "repo.settings.projects_mode_repo"}}</option> <option value="repo" {{if or (not $isProjectsEnabled) (eq $projectsUnit.ProjectsConfig.GetProjectsMode "repo")}}selected{{end}}>{{ctx.Locale.Tr "repo.settings.projects_mode_repo"}}</option>
<option value="owner" {{if or (not $isProjectsEnabled) (eq $projectsUnit.ProjectsConfig.ProjectsMode "owner")}}selected{{end}}>{{ctx.Locale.Tr "repo.settings.projects_mode_owner"}}</option> <option value="owner" {{if or (not $isProjectsEnabled) (eq $projectsUnit.ProjectsConfig.GetProjectsMode "owner")}}selected{{end}}>{{ctx.Locale.Tr "repo.settings.projects_mode_owner"}}</option>
<option value="all" {{if or (not $isProjectsEnabled) (eq $projectsUnit.ProjectsConfig.ProjectsMode "all")}}selected{{end}}>{{ctx.Locale.Tr "repo.settings.projects_mode_all"}}</option> <option value="all" {{if or (not $isProjectsEnabled) (eq $projectsUnit.ProjectsConfig.GetProjectsMode "all")}}selected{{end}}>{{ctx.Locale.Tr "repo.settings.projects_mode_all"}}</option>
</select> </select>
{{svg "octicon-triangle-down" 14 "dropdown icon"}} {{svg "octicon-triangle-down" 14 "dropdown icon"}}
<div class="default text"> <div class="default text">
{{if (eq $projectsUnit.ProjectsConfig.ProjectsMode "repo")}} {{if (eq $projectsUnit.ProjectsConfig.GetProjectsMode "repo")}}
{{ctx.Locale.Tr "repo.settings.projects_mode_repo"}} {{ctx.Locale.Tr "repo.settings.projects_mode_repo"}}
{{end}} {{end}}
{{if (eq $projectsUnit.ProjectsConfig.ProjectsMode "owner")}} {{if (eq $projectsUnit.ProjectsConfig.GetProjectsMode "owner")}}
{{ctx.Locale.Tr "repo.settings.projects_mode_owner"}} {{ctx.Locale.Tr "repo.settings.projects_mode_owner"}}
{{end}} {{end}}
{{if (eq $projectsUnit.ProjectsConfig.ProjectsMode "all")}} {{if (eq $projectsUnit.ProjectsConfig.GetProjectsMode "all")}}
{{ctx.Locale.Tr "repo.settings.projects_mode_all"}} {{ctx.Locale.Tr "repo.settings.projects_mode_all"}}
{{end}} {{end}}
</div> </div>