From ad1a989b157db98759ba5d6d2ab204234a51e09b Mon Sep 17 00:00:00 2001 From: jolheiser Date: Tue, 2 Jun 2020 12:39:28 -0500 Subject: [PATCH 1/4] Allow site admin to disable mirrors Signed-off-by: jolheiser --- 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 5e150172d5bf1..04dbbfb36ac1e 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -50,6 +50,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 mirror migrations +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 f0908c22a34f3..1721deb2d53f8 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -69,6 +69,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 mirror migrations ### Repository - Pull Request (`repository.pull-request`) diff --git a/modules/setting/repository.go b/modules/setting/repository.go index 8af3eaaf46933..806c56f269aee 100644 --- a/modules/setting/repository.go +++ b/modules/setting/repository.go @@ -40,6 +40,7 @@ var ( DisabledRepoUnits []string DefaultRepoUnits []string PrefixArchiveFiles bool + DisableMirrors bool // Repository editor settings Editor struct { @@ -104,6 +105,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 57ab4966a31e1..f854821827916 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 fd0db7814c799..aefbffa8fa894 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 b0bb608d09b12..4ded75db6c37a 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 f30b59df3f726..58971159facb4 100644 --- a/templates/repo/migrate.tmpl +++ b/templates/repo/migrate.tmpl @@ -81,8 +81,13 @@
- - + {{if .DisableMirrors}} + + + {{else}} + + + {{end}}
From f56efc416949192e37c4c63502938d7cdcfc054d Mon Sep 17 00:00:00 2001 From: jolheiser Date: Tue, 2 Jun 2020 12:43:39 -0500 Subject: [PATCH 2/4] No need to run through Safe Signed-off-by: jolheiser --- templates/repo/migrate.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/migrate.tmpl b/templates/repo/migrate.tmpl index 58971159facb4..60b432beaa268 100644 --- a/templates/repo/migrate.tmpl +++ b/templates/repo/migrate.tmpl @@ -83,7 +83,7 @@
{{if .DisableMirrors}} - + {{else}} From 8fd97ef3a7a4b37f7d1e009a10e7ae4144327c25 Mon Sep 17 00:00:00 2001 From: jolheiser Date: Tue, 2 Jun 2020 12:47:30 -0500 Subject: [PATCH 3/4] Clarify only disabling NEW mirrors Signed-off-by: jolheiser --- custom/conf/app.ini.sample | 2 +- docs/content/doc/advanced/config-cheat-sheet.en-us.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 04dbbfb36ac1e..8a183f6fc2a78 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -50,7 +50,7 @@ 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 mirror migrations +; Disable new mirror migrations DISABLE_MIRRORS = false [repository.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 1721deb2d53f8..e44673c3634cd 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -69,7 +69,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 mirror migrations +- `DISABLE_MIRRORS`: **false**: Disable *new* mirror migrations ### Repository - Pull Request (`repository.pull-request`) From 7b4505decb707730adadfde28a1b0f0b377b9f1e Mon Sep 17 00:00:00 2001 From: John Olheiser Date: Tue, 2 Jun 2020 17:17:53 -0500 Subject: [PATCH 4/4] Apply suggestions from @guillep2k 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 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 8a183f6fc2a78..32f81b508c41f 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -50,7 +50,7 @@ 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 new mirror migrations +; Disable the creation of new mirrors. Pre-existing mirrors remain valid. DISABLE_MIRRORS = false [repository.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 e44673c3634cd..7a1ea048212d2 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -69,7 +69,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 *new* mirror migrations +- `DISABLE_MIRRORS`: **false**: Disable the creation of **new** mirrors. Pre-existing mirrors remain valid. ### Repository - Pull Request (`repository.pull-request`)