From a6fd2f23f7e6bdc60c092207ac43af3a9a291f8f Mon Sep 17 00:00:00 2001 From: John Olheiser Date: Tue, 2 Jun 2020 20:21:38 -0500 Subject: [PATCH] Allow site admin to disable mirrors (#11740) * Allow site admin to disable mirrors Signed-off-by: jolheiser * No need to run through Safe Signed-off-by: jolheiser * Clarify only disabling NEW mirrors Signed-off-by: jolheiser * Apply suggestions from @guillep2k Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> --- custom/conf/app.ini.sample | 2 ++ docs/content/doc/advanced/config-cheat-sheet.en-us.md | 1 + modules/setting/repository.go | 2 ++ options/locale/locale_en-US.ini | 1 + routers/api/v1/repo/migrate.go | 2 +- routers/repo/repo.go | 3 ++- templates/repo/migrate.tmpl | 9 +++++++-- 7 files changed, 16 insertions(+), 4 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 4f5529edf..35508bad3 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -55,6 +55,8 @@ DISABLED_REPO_UNITS = DEFAULT_REPO_UNITS = repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki ; Prefix archive files by placing them in a directory named after the repository PREFIX_ARCHIVE_FILES = true +; Disable the creation of new mirrors. Pre-existing mirrors remain valid. +DISABLE_MIRRORS = false [repository.editor] ; List of file extensions for which lines should be wrapped in the Monaco editor diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index c29151f64..0ed0d9203 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -70,6 +70,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`. - `ENABLE_PUSH_CREATE_USER`: **false**: Allow users to push local repositories to Gitea and have them automatically created for a user. - `ENABLE_PUSH_CREATE_ORG`: **false**: Allow users to push local repositories to Gitea and have them automatically created for an org. - `PREFIX_ARCHIVE_FILES`: **true**: Prefix archive files by placing them in a directory named after the repository. +- `DISABLE_MIRRORS`: **false**: Disable the creation of **new** mirrors. Pre-existing mirrors remain valid. ### Repository - Pull Request (`repository.pull-request`) diff --git a/modules/setting/repository.go b/modules/setting/repository.go index 1796a8d6b..3e63d458f 100644 --- a/modules/setting/repository.go +++ b/modules/setting/repository.go @@ -42,6 +42,7 @@ var ( DisabledRepoUnits []string DefaultRepoUnits []string PrefixArchiveFiles bool + DisableMirrors bool // Repository editor settings Editor struct { @@ -142,6 +143,7 @@ var ( DisabledRepoUnits: []string{}, DefaultRepoUnits: []string{}, PrefixArchiveFiles: true, + DisableMirrors: false, // Repository editor settings Editor: struct { diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 57ab4966a..f85482182 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -689,6 +689,7 @@ form.name_pattern_not_allowed = The pattern '%s' is not allowed in a repository need_auth = Clone Authorization migrate_type = Migration Type migrate_type_helper = This repository will be a mirror +migrate_type_helper_disabled = Your site administrator has disabled new mirrors. migrate_items = Migration Items migrate_items_wiki = Wiki migrate_items_milestones = Milestones diff --git a/routers/api/v1/repo/migrate.go b/routers/api/v1/repo/migrate.go index fd0db7814..aefbffa8f 100644 --- a/routers/api/v1/repo/migrate.go +++ b/routers/api/v1/repo/migrate.go @@ -118,7 +118,7 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) { RepoName: form.RepoName, Description: form.Description, Private: form.Private || setting.Repository.ForcePrivate, - Mirror: form.Mirror, + Mirror: form.Mirror && !setting.Repository.DisableMirrors, AuthUsername: form.AuthUsername, AuthPassword: form.AuthPassword, Wiki: form.Wiki, diff --git a/routers/repo/repo.go b/routers/repo/repo.go index b0bb608d0..4ded75db6 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -259,6 +259,7 @@ func Migrate(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("new_migrate") ctx.Data["private"] = getRepoPrivate(ctx) ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate + ctx.Data["DisableMirrors"] = setting.Repository.DisableMirrors ctx.Data["mirror"] = ctx.Query("mirror") == "1" ctx.Data["wiki"] = ctx.Query("wiki") == "1" ctx.Data["milestones"] = ctx.Query("milestones") == "1" @@ -360,7 +361,7 @@ func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) { RepoName: form.RepoName, Description: form.Description, Private: form.Private || setting.Repository.ForcePrivate, - Mirror: form.Mirror, + Mirror: form.Mirror && !setting.Repository.DisableMirrors, AuthUsername: form.AuthUsername, AuthPassword: form.AuthPassword, Wiki: form.Wiki, diff --git a/templates/repo/migrate.tmpl b/templates/repo/migrate.tmpl index f30b59df3..60b432bea 100644 --- a/templates/repo/migrate.tmpl +++ b/templates/repo/migrate.tmpl @@ -81,8 +81,13 @@
- - + {{if .DisableMirrors}} + + + {{else}} + + + {{end}}