mirror of
https://github.com/go-gitea/gitea
synced 2025-12-07 13:28:25 +00: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:
@@ -188,6 +188,7 @@ func EditUser(ctx *context.Context) {
|
||||
ctx.Data["PageIsAdmin"] = true
|
||||
ctx.Data["PageIsAdminUsers"] = true
|
||||
ctx.Data["DisableRegularOrgCreation"] = setting.Admin.DisableRegularOrgCreation
|
||||
ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations
|
||||
|
||||
prepareUserInfo(ctx)
|
||||
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["PageIsAdmin"] = true
|
||||
ctx.Data["PageIsAdminUsers"] = true
|
||||
ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations
|
||||
|
||||
u := prepareUserInfo(ctx)
|
||||
if ctx.Written() {
|
||||
|
||||
@@ -119,6 +119,11 @@ func Migrate(ctx *context.APIContext, form api.MigrateRepoOptions) {
|
||||
return
|
||||
}
|
||||
|
||||
if setting.Repository.DisableMigrations {
|
||||
ctx.Error(http.StatusForbidden, "MigrationsGlobalDisabled", fmt.Errorf("the site administrator has disabled migrations"))
|
||||
return
|
||||
}
|
||||
|
||||
var opts = migrations.MigrateOptions{
|
||||
CloneAddr: remoteAddr,
|
||||
RepoName: form.RepoName,
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package repo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
@@ -25,6 +26,11 @@ const (
|
||||
|
||||
// Migrate render migration of repository page
|
||||
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...)
|
||||
serviceType := ctx.QueryInt("service_type")
|
||||
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) {
|
||||
if setting.Repository.DisableMigrations {
|
||||
ctx.ServerError("MigrateError", fmt.Errorf("migrations disabled"))
|
||||
return
|
||||
}
|
||||
|
||||
switch {
|
||||
case migrations.IsRateLimitError(err):
|
||||
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
|
||||
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")
|
||||
// Plain git should be first
|
||||
ctx.Data["service"] = structs.GitServiceType(form.Service)
|
||||
|
||||
Reference in New Issue
Block a user