diff options
author | John Olheiser <john.olheiser@gmail.com> | 2020-06-02 20:21:38 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-02 21:21:38 -0400 |
commit | a6fd2f23f7e6bdc60c092207ac43af3a9a291f8f (patch) | |
tree | e9abecb2896bcb688235d8aba3a76281cde64873 | |
parent | d0a18a12704360c06cf48b586956148a17a4505a (diff) | |
download | gitea-a6fd2f23f7e6bdc60c092207ac43af3a9a291f8f.tar.gz gitea-a6fd2f23f7e6bdc60c092207ac43af3a9a291f8f.zip |
Allow site admin to disable mirrors (#11740)
* Allow site admin to disable mirrors
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* No need to run through Safe
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Clarify only disabling NEW mirrors
Signed-off-by: jolheiser <john.olheiser@gmail.com>
* Apply suggestions from @guillep2k
Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
-rw-r--r-- | custom/conf/app.ini.sample | 2 | ||||
-rw-r--r-- | docs/content/doc/advanced/config-cheat-sheet.en-us.md | 1 | ||||
-rw-r--r-- | modules/setting/repository.go | 2 | ||||
-rw-r--r-- | options/locale/locale_en-US.ini | 1 | ||||
-rw-r--r-- | routers/api/v1/repo/migrate.go | 2 | ||||
-rw-r--r-- | routers/repo/repo.go | 3 | ||||
-rw-r--r-- | 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 4f5529edfa..35508bad3c 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 c29151f648..0ed0d92033 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 1796a8d6b5..3e63d458f8 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 57ab4966a3..f854821827 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 <span class="text blue">mirror</span> +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 fd0db7814c..aefbffa8fa 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 b0bb608d09..4ded75db6c 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 f30b59df3f..60b432beaa 100644 --- a/templates/repo/migrate.tmpl +++ b/templates/repo/migrate.tmpl @@ -81,8 +81,13 @@ <div class="inline field"> <label>{{.i18n.Tr "repo.migrate_type"}}</label> <div class="ui checkbox"> - <input id="mirror" name="mirror" type="checkbox" {{if .mirror}}checked{{end}}> - <label>{{.i18n.Tr "repo.migrate_type_helper" | Safe}}</label> + {{if .DisableMirrors}} + <input id="mirror" name="mirror" type="checkbox" readonly> + <label>{{.i18n.Tr "repo.migrate_type_helper_disabled"}}</label> + {{else}} + <input id="mirror" name="mirror" type="checkbox" {{if .mirror}}checked{{end}}> + <label>{{.i18n.Tr "repo.migrate_type_helper" | Safe}}</label> + {{end}} </div> </div> <div id="migrate_items" class="ui field"> |