1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-21 12:44:49 -05:00

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
This commit is contained in:
Pawel Boguslawski 2020-10-12 13:15:36 +02:00
parent 95ff55991e
commit 04b04cf854
10 changed files with 38 additions and 5 deletions

View file

@ -62,6 +62,8 @@ DEFAULT_REPO_UNITS = repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,re
PREFIX_ARCHIVE_FILES = true PREFIX_ARCHIVE_FILES = true
; Disable the creation of new mirrors. Pre-existing mirrors remain valid. ; Disable the creation of new mirrors. Pre-existing mirrors remain valid.
DISABLE_MIRRORS = false DISABLE_MIRRORS = false
; Disable migrating feature.
DISABLE_MIGRATIONS = true
; The default branch name of new repositories ; The default branch name of new repositories
DEFAULT_BRANCH=master DEFAULT_BRANCH=master
; Allow adoption of unadopted repositories ; Allow adoption of unadopted repositories

View file

@ -71,6 +71,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
- `ENABLE_PUSH_CREATE_ORG`: **false**: Allow users to push local repositories to Gitea and have them automatically created for an org. - `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. - `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. - `DISABLE_MIRRORS`: **false**: Disable the creation of **new** mirrors. Pre-existing mirrors remain valid.
- `DISABLE_MIGRATIONS`: **false**: Disable migrating feature.
- `DEFAULT_BRANCH`: **master**: Default branch name of all repositories. - `DEFAULT_BRANCH`: **master**: Default branch name of all repositories.
### Repository - Pull Request (`repository.pull-request`) ### Repository - Pull Request (`repository.pull-request`)

View file

@ -343,6 +343,7 @@ func Contexter() macaron.Handler {
ctx.Data["EnableSwagger"] = setting.API.EnableSwagger ctx.Data["EnableSwagger"] = setting.API.EnableSwagger
ctx.Data["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn ctx.Data["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn
ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations
c.Map(ctx) c.Map(ctx)
} }

View file

@ -115,5 +115,7 @@ func initBasicTasks() {
registerArchiveCleanup() registerArchiveCleanup()
registerSyncExternalUsers() registerSyncExternalUsers()
registerDeletedBranchesCleanup() registerDeletedBranchesCleanup()
registerUpdateMigrationPosterID() if !setting.Repository.DisableMigrations {
registerUpdateMigrationPosterID()
}
} }

View file

@ -43,6 +43,7 @@ var (
DefaultRepoUnits []string DefaultRepoUnits []string
PrefixArchiveFiles bool PrefixArchiveFiles bool
DisableMirrors bool DisableMirrors bool
DisableMigrations bool
DefaultBranch string DefaultBranch string
AllowAdoptionOfUnadoptedRepositories bool AllowAdoptionOfUnadoptedRepositories bool
AllowDeleteOfUnadoptedRepositories bool AllowDeleteOfUnadoptedRepositories bool
@ -148,6 +149,7 @@ var (
DefaultRepoUnits: []string{}, DefaultRepoUnits: []string{},
PrefixArchiveFiles: true, PrefixArchiveFiles: true,
DisableMirrors: false, DisableMirrors: false,
DisableMigrations: false,
DefaultBranch: "master", DefaultBranch: "master",
// Repository editor settings // Repository editor settings

View file

@ -188,6 +188,7 @@ func EditUser(ctx *context.Context) {
ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminUsers"] = true ctx.Data["PageIsAdminUsers"] = true
ctx.Data["DisableRegularOrgCreation"] = setting.Admin.DisableRegularOrgCreation ctx.Data["DisableRegularOrgCreation"] = setting.Admin.DisableRegularOrgCreation
ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations
prepareUserInfo(ctx) prepareUserInfo(ctx)
if ctx.Written() { if ctx.Written() {
@ -202,6 +203,7 @@ func EditUserPost(ctx *context.Context, form auth.AdminEditUserForm) {
ctx.Data["Title"] = ctx.Tr("admin.users.edit_account") ctx.Data["Title"] = ctx.Tr("admin.users.edit_account")
ctx.Data["PageIsAdmin"] = true ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminUsers"] = true ctx.Data["PageIsAdminUsers"] = true
ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations
u := prepareUserInfo(ctx) u := prepareUserInfo(ctx)
if ctx.Written() { if ctx.Written() {

View file

@ -119,6 +119,11 @@ func Migrate(ctx *context.APIContext, form api.MigrateRepoOptions) {
return return
} }
if setting.Repository.DisableMigrations {
ctx.Error(http.StatusForbidden, "MigrationsGlobalDisabled", fmt.Errorf("the site administrator has disabled migrations"))
return
}
var opts = migrations.MigrateOptions{ var opts = migrations.MigrateOptions{
CloneAddr: remoteAddr, CloneAddr: remoteAddr,
RepoName: form.RepoName, RepoName: form.RepoName,

View file

@ -6,6 +6,7 @@
package repo package repo
import ( import (
"fmt"
"strings" "strings"
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
@ -25,6 +26,11 @@ const (
// Migrate render migration of repository page // Migrate render migration of repository page
func Migrate(ctx *context.Context) { func Migrate(ctx *context.Context) {
if setting.Repository.DisableMigrations {
ctx.ServerError("MigratePost", fmt.Errorf("cannot migrate; migrations disabled"))
return
}
ctx.Data["Services"] = append([]structs.GitServiceType{structs.PlainGitService}, structs.SupportedFullGitService...) ctx.Data["Services"] = append([]structs.GitServiceType{structs.PlainGitService}, structs.SupportedFullGitService...)
serviceType := ctx.QueryInt("service_type") serviceType := ctx.QueryInt("service_type")
if serviceType == 0 { if serviceType == 0 {
@ -57,6 +63,11 @@ func Migrate(ctx *context.Context) {
} }
func handleMigrateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form *auth.MigrateRepoForm) { func handleMigrateError(ctx *context.Context, owner *models.User, err error, name string, tpl base.TplName, form *auth.MigrateRepoForm) {
if setting.Repository.DisableMigrations {
ctx.ServerError("MigrateError", fmt.Errorf("migrations disabled"))
return
}
switch { switch {
case migrations.IsRateLimitError(err): case migrations.IsRateLimitError(err):
ctx.RenderWithErr(ctx.Tr("form.visit_rate_limit"), tpl, form) 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
// MigratePost response for migrating from external git repository // MigratePost response for migrating from external git repository
func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) { func MigratePost(ctx *context.Context, form auth.MigrateRepoForm) {
if setting.Repository.DisableMigrations {
ctx.ServerError("MigratePost", fmt.Errorf("cannot migrate; migrations disabled"))
return
}
ctx.Data["Title"] = ctx.Tr("new_migrate") ctx.Data["Title"] = ctx.Tr("new_migrate")
// Plain git should be first // Plain git should be first
ctx.Data["service"] = structs.GitServiceType(form.Service) ctx.Data["service"] = structs.GitServiceType(form.Service)

View file

@ -95,7 +95,7 @@
<input name="allow_git_hook" type="checkbox" {{if .User.CanEditGitHook}}checked{{end}} {{if DisableGitHooks}}disabled{{end}}> <input name="allow_git_hook" type="checkbox" {{if .User.CanEditGitHook}}checked{{end}} {{if DisableGitHooks}}disabled{{end}}>
</div> </div>
</div> </div>
<div class="inline field"> <div class="inline field" {{if or (DisableImportLocal) (.DisableMigrations)}}hidden{{end}}>
<div class="ui checkbox"> <div class="ui checkbox">
<label><strong>{{.i18n.Tr "admin.users.allow_import_local"}}</strong></label> <label><strong>{{.i18n.Tr "admin.users.allow_import_local"}}</strong></label>
<input name="allow_import_local" type="checkbox" {{if .User.CanImportLocal}}checked{{end}} {{if DisableImportLocal}}disabled{{end}}> <input name="allow_import_local" type="checkbox" {{if .User.CanImportLocal}}checked{{end}} {{if DisableImportLocal}}disabled{{end}}>

View file

@ -89,9 +89,11 @@
<a class="item" href="{{AppSubUrl}}/repo/create"> <a class="item" href="{{AppSubUrl}}/repo/create">
<span class="fitted">{{svg "octicon-plus"}}</span> {{.i18n.Tr "new_repo"}} <span class="fitted">{{svg "octicon-plus"}}</span> {{.i18n.Tr "new_repo"}}
</a> </a>
<a class="item" href="{{AppSubUrl}}/repo/migrate"> {{if not .DisableMigrations}}
<span class="fitted">{{svg "octicon-repo-push"}}</span> {{.i18n.Tr "new_migrate"}} <a class="item" href="{{AppSubUrl}}/repo/migrate">
</a> <span class="fitted">{{svg "octicon-repo-push"}}</span> {{.i18n.Tr "new_migrate"}}
</a>
{{end}}
{{if .SignedUser.CanCreateOrganization}} {{if .SignedUser.CanCreateOrganization}}
<a class="item" href="{{AppSubUrl}}/org/create"> <a class="item" href="{{AppSubUrl}}/org/create">
<span class="fitted">{{svg "octicon-organization"}}</span> {{.i18n.Tr "new_org"}} <span class="fitted">{{svg "octicon-organization"}}</span> {{.i18n.Tr "new_org"}}