From 003b4e209ce27e21e68b6a48ad2a7f6a1bcb17fb Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 12 Dec 2022 13:29:27 +0800 Subject: [PATCH] Allow disable code tab (#20805) I know some users created a repository in an organization but just use issues and projects to handle the whole organizations issues. So that `Code` could be disabled per repository. image It could also become a wiki repository. image Co-authored-by: delvh --- routers/web/repo/setting.go | 9 +++++++++ services/forms/repo_form.go | 1 + templates/repo/settings/options.tmpl | 13 +++++++++++++ 3 files changed, 23 insertions(+) diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index 8ba5fc9e34..f35adcaa10 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -397,6 +397,15 @@ func SettingsPost(ctx *context.Context) { repoChanged = true } + if form.EnableCode && !unit_model.TypeCode.UnitGlobalDisabled() { + units = append(units, repo_model.RepoUnit{ + RepoID: repo.ID, + Type: unit_model.TypeCode, + }) + } else if !unit_model.TypeCode.UnitGlobalDisabled() { + deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeCode) + } + if form.EnableWiki && form.EnableExternalWiki && !unit_model.TypeExternalWiki.UnitGlobalDisabled() { if !validation.IsValidExternalURL(form.ExternalWikiURL) { ctx.Flash.Error(ctx.Tr("repo.settings.external_wiki_url_error")) diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index d4fb051d8d..89a013d9af 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -134,6 +134,7 @@ type RepoSettingForm struct { EnablePrune bool // Advanced settings + EnableCode bool EnableWiki bool EnableExternalWiki bool ExternalWikiURL string diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index aa79f75617..e1f53072b8 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -249,6 +249,19 @@ {{.CsrfTokenHtml}} + {{$isCodeEnabled := .Repository.UnitEnabled $.Context $.UnitTypeCode}} +
+ + {{if .UnitTypeCode.UnitGlobalDisabled}} +
+ {{else}} +
+ {{end}} + + +
+
+ {{$isWikiEnabled := or (.Repository.UnitEnabled $.Context $.UnitTypeWiki) (.Repository.UnitEnabled $.Context $.UnitTypeExternalWiki)}}