Skip to content

Commit a6fd2f2

Browse files
jolheiserguillep2k
andauthored
Allow site admin to disable mirrors (#11740)
* Allow site admin to disable mirrors Signed-off-by: jolheiser <[email protected]> * No need to run through Safe Signed-off-by: jolheiser <[email protected]> * Clarify only disabling NEW mirrors Signed-off-by: jolheiser <[email protected]> * Apply suggestions from @guillep2k Co-authored-by: guillep2k <[email protected]> Co-authored-by: guillep2k <[email protected]>
1 parent d0a18a1 commit a6fd2f2

File tree

7 files changed

+16
-4
lines changed

7 files changed

+16
-4
lines changed

custom/conf/app.ini.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ DISABLED_REPO_UNITS =
5555
DEFAULT_REPO_UNITS = repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki
5656
; Prefix archive files by placing them in a directory named after the repository
5757
PREFIX_ARCHIVE_FILES = true
58+
; Disable the creation of new mirrors. Pre-existing mirrors remain valid.
59+
DISABLE_MIRRORS = false
5860

5961
[repository.editor]
6062
; List of file extensions for which lines should be wrapped in the Monaco editor

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
7070
- `ENABLE_PUSH_CREATE_USER`: **false**: Allow users to push local repositories to Gitea and have them automatically created for a user.
7171
- `ENABLE_PUSH_CREATE_ORG`: **false**: Allow users to push local repositories to Gitea and have them automatically created for an org.
7272
- `PREFIX_ARCHIVE_FILES`: **true**: Prefix archive files by placing them in a directory named after the repository.
73+
- `DISABLE_MIRRORS`: **false**: Disable the creation of **new** mirrors. Pre-existing mirrors remain valid.
7374

7475
### Repository - Pull Request (`repository.pull-request`)
7576

modules/setting/repository.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var (
4242
DisabledRepoUnits []string
4343
DefaultRepoUnits []string
4444
PrefixArchiveFiles bool
45+
DisableMirrors bool
4546

4647
// Repository editor settings
4748
Editor struct {
@@ -142,6 +143,7 @@ var (
142143
DisabledRepoUnits: []string{},
143144
DefaultRepoUnits: []string{},
144145
PrefixArchiveFiles: true,
146+
DisableMirrors: false,
145147

146148
// Repository editor settings
147149
Editor: struct {

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@ form.name_pattern_not_allowed = The pattern '%s' is not allowed in a repository
689689
need_auth = Clone Authorization
690690
migrate_type = Migration Type
691691
migrate_type_helper = This repository will be a <span class="text blue">mirror</span>
692+
migrate_type_helper_disabled = Your site administrator has disabled new mirrors.
692693
migrate_items = Migration Items
693694
migrate_items_wiki = Wiki
694695
migrate_items_milestones = Milestones

routers/api/v1/repo/migrate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
118118
RepoName: form.RepoName,
119119
Description: form.Description,
120120
Private: form.Private || setting.Repository.ForcePrivate,
121-
Mirror: form.Mirror,
121+
Mirror: form.Mirror && !setting.Repository.DisableMirrors,
122122
AuthUsername: form.AuthUsername,
123123
AuthPassword: form.AuthPassword,
124124
Wiki: form.Wiki,

routers/repo/repo.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ func Migrate(ctx *context.Context) {
259259
ctx.Data["Title"] = ctx.Tr("new_migrate")
260260
ctx.Data["private"] = getRepoPrivate(ctx)
261261
ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate
262+
ctx.Data["DisableMirrors"] = setting.Repository.DisableMirrors
262263
ctx.Data["mirror"] = ctx.Query("mirror") == "1"
263264
ctx.Data["wiki"] = ctx.Query("wiki") == "1"
264265
ctx.Data["milestones"] = ctx.Query("milestones") == "1"
@@ -360,7 +361,7 @@ func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) {
360361
RepoName: form.RepoName,
361362
Description: form.Description,
362363
Private: form.Private || setting.Repository.ForcePrivate,
363-
Mirror: form.Mirror,
364+
Mirror: form.Mirror && !setting.Repository.DisableMirrors,
364365
AuthUsername: form.AuthUsername,
365366
AuthPassword: form.AuthPassword,
366367
Wiki: form.Wiki,

templates/repo/migrate.tmpl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,13 @@
8181
<div class="inline field">
8282
<label>{{.i18n.Tr "repo.migrate_type"}}</label>
8383
<div class="ui checkbox">
84-
<input id="mirror" name="mirror" type="checkbox" {{if .mirror}}checked{{end}}>
85-
<label>{{.i18n.Tr "repo.migrate_type_helper" | Safe}}</label>
84+
{{if .DisableMirrors}}
85+
<input id="mirror" name="mirror" type="checkbox" readonly>
86+
<label>{{.i18n.Tr "repo.migrate_type_helper_disabled"}}</label>
87+
{{else}}
88+
<input id="mirror" name="mirror" type="checkbox" {{if .mirror}}checked{{end}}>
89+
<label>{{.i18n.Tr "repo.migrate_type_helper" | Safe}}</label>
90+
{{end}}
8691
</div>
8792
</div>
8893
<div id="migrate_items" class="ui field">

0 commit comments

Comments
 (0)