Skip to content

Commit 04b04cf

Browse files
committed
Added option to disable migrations
This patch introduces DISABLE_MIGRATIONS parameter in [repository] section of app.ini (by default set to false). If set to true it blocks access to repository migration feature. This mod hides also local repo import option in user editor if local repo importing or migrations is disabled. Author-Change-Id: IB#1105130
1 parent 95ff559 commit 04b04cf

File tree

10 files changed

+38
-5
lines changed

10 files changed

+38
-5
lines changed

custom/conf/app.example.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ DEFAULT_REPO_UNITS = repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,re
6262
PREFIX_ARCHIVE_FILES = true
6363
; Disable the creation of new mirrors. Pre-existing mirrors remain valid.
6464
DISABLE_MIRRORS = false
65+
; Disable migrating feature.
66+
DISABLE_MIGRATIONS = true
6567
; The default branch name of new repositories
6668
DEFAULT_BRANCH=master
6769
; Allow adoption of unadopted repositories

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
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.
7373
- `DISABLE_MIRRORS`: **false**: Disable the creation of **new** mirrors. Pre-existing mirrors remain valid.
74+
- `DISABLE_MIGRATIONS`: **false**: Disable migrating feature.
7475
- `DEFAULT_BRANCH`: **master**: Default branch name of all repositories.
7576

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

modules/context/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ func Contexter() macaron.Handler {
343343

344344
ctx.Data["EnableSwagger"] = setting.API.EnableSwagger
345345
ctx.Data["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn
346+
ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations
346347

347348
c.Map(ctx)
348349
}

modules/cron/tasks_basic.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,7 @@ func initBasicTasks() {
115115
registerArchiveCleanup()
116116
registerSyncExternalUsers()
117117
registerDeletedBranchesCleanup()
118-
registerUpdateMigrationPosterID()
118+
if !setting.Repository.DisableMigrations {
119+
registerUpdateMigrationPosterID()
120+
}
119121
}

modules/setting/repository.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var (
4343
DefaultRepoUnits []string
4444
PrefixArchiveFiles bool
4545
DisableMirrors bool
46+
DisableMigrations bool
4647
DefaultBranch string
4748
AllowAdoptionOfUnadoptedRepositories bool
4849
AllowDeleteOfUnadoptedRepositories bool
@@ -148,6 +149,7 @@ var (
148149
DefaultRepoUnits: []string{},
149150
PrefixArchiveFiles: true,
150151
DisableMirrors: false,
152+
DisableMigrations: false,
151153
DefaultBranch: "master",
152154

153155
// Repository editor settings

routers/admin/users.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ func EditUser(ctx *context.Context) {
188188
ctx.Data["PageIsAdmin"] = true
189189
ctx.Data["PageIsAdminUsers"] = true
190190
ctx.Data["DisableRegularOrgCreation"] = setting.Admin.DisableRegularOrgCreation
191+
ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations
191192

192193
prepareUserInfo(ctx)
193194
if ctx.Written() {
@@ -202,6 +203,7 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
202203
ctx.Data["Title"] = ctx.Tr("admin.users.edit_account")
203204
ctx.Data["PageIsAdmin"] = true
204205
ctx.Data["PageIsAdminUsers"] = true
206+
ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations
205207

206208
u := prepareUserInfo(ctx)
207209
if ctx.Written() {

routers/api/v1/repo/migrate.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ func Migrate(ctx *context.APIContext, form api.MigrateRepoOptions) {
119119
return
120120
}
121121

122+
if setting.Repository.DisableMigrations {
123+
ctx.Error(http.StatusForbidden, "MigrationsGlobalDisabled", fmt.Errorf("the site administrator has disabled migrations"))
124+
return
125+
}
126+
122127
var opts = migrations.MigrateOptions{
123128
CloneAddr: remoteAddr,
124129
RepoName: form.RepoName,

routers/repo/migrate.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package repo
77

88
import (
9+
"fmt"
910
"strings"
1011

1112
"code.gitea.io/gitea/models"
@@ -25,6 +26,11 @@ const (
2526

2627
// Migrate render migration of repository page
2728
func Migrate(ctx *context.Context) {
29+
if setting.Repository.DisableMigrations {
30+
ctx.ServerError("MigratePost", fmt.Errorf("cannot migrate; migrations disabled"))
31+
return
32+
}
33+
2834
ctx.Data["Services"] = append([]structs.GitServiceType{structs.PlainGitService}, structs.SupportedFullGitService...)
2935
serviceType := ctx.QueryInt("service_type")
3036
if serviceType == 0 {
@@ -57,6 +63,11 @@ func Migrate(ctx *context.Context) {
5763
}
5864

5965
func handleMigrateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form *auth.MigrateRepoForm) {
66+
if setting.Repository.DisableMigrations {
67+
ctx.ServerError("MigrateError", fmt.Errorf("migrations disabled"))
68+
return
69+
}
70+
6071
switch {
6172
case migrations.IsRateLimitError(err):
6273
ctx.RenderWithErr(ctx.Tr("form.visit_rate_limit"), tpl, form)
@@ -104,6 +115,11 @@ func handleMigrateError(ctx *context.Context, owner *models.User, err error, nam
104115

105116
// MigratePost response for migrating from external git repository
106117
func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) {
118+
if setting.Repository.DisableMigrations {
119+
ctx.ServerError("MigratePost", fmt.Errorf("cannot migrate; migrations disabled"))
120+
return
121+
}
122+
107123
ctx.Data["Title"] = ctx.Tr("new_migrate")
108124
// Plain git should be first
109125
ctx.Data["service"] = structs.GitServiceType(form.Service)

templates/admin/user/edit.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
<input name="allow_git_hook" type="checkbox" {{if .User.CanEditGitHook}}checked{{end}} {{if DisableGitHooks}}disabled{{end}}>
9696
</div>
9797
</div>
98-
<div class="inline field">
98+
<div class="inline field" {{if or (DisableImportLocal) (.DisableMigrations)}}hidden{{end}}>
9999
<div class="ui checkbox">
100100
<label><strong>{{.i18n.Tr "admin.users.allow_import_local"}}</strong></label>
101101
<input name="allow_import_local" type="checkbox" {{if .User.CanImportLocal}}checked{{end}} {{if DisableImportLocal}}disabled{{end}}>

templates/base/head_navbar.tmpl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@
8989
<a class="item" href="{{AppSubUrl}}/repo/create">
9090
<span class="fitted">{{svg "octicon-plus"}}</span> {{.i18n.Tr "new_repo"}}
9191
</a>
92-
<a class="item" href="{{AppSubUrl}}/repo/migrate">
93-
<span class="fitted">{{svg "octicon-repo-push"}}</span> {{.i18n.Tr "new_migrate"}}
94-
</a>
92+
{{if not .DisableMigrations}}
93+
<a class="item" href="{{AppSubUrl}}/repo/migrate">
94+
<span class="fitted">{{svg "octicon-repo-push"}}</span> {{.i18n.Tr "new_migrate"}}
95+
</a>
96+
{{end}}
9597
{{if .SignedUser.CanCreateOrganization}}
9698
<a class="item" href="{{AppSubUrl}}/org/create">
9799
<span class="fitted">{{svg "octicon-organization"}}</span> {{.i18n.Tr "new_org"}}

0 commit comments

Comments
 (0)