diff --git a/routers/repo/setting.go b/routers/repo/setting.go index d2c20fb03a6bf..b55df22bff016 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -9,6 +9,7 @@ import ( "errors" "fmt" "io/ioutil" + "net/http" "net/url" "regexp" "strings" @@ -59,6 +60,28 @@ func Settings(ctx *context.Context) { ctx.HTML(200, tplSettingsOptions) } +// CancelMigration cancel a running migration +func CancelMigration(ctx *context.Context) { + if !ctx.Repo.IsOwner() { + ctx.Error(http.StatusNotFound) + return + } + + if ctx.Repo.Repository.Status != models.RepositoryBeingMigrated { + ctx.Error(http.StatusConflict, "repo already migrated") + return + } + + if err := repo_service.DeleteRepository(ctx.User, ctx.Repo.Repository); err != nil { + ctx.ServerError("DeleteRepository", err) + return + } + log.Trace("Repository deleted: %s/%s", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) + + ctx.Flash.Success(ctx.Tr("repo.settings.deletion_success")) + ctx.Redirect(ctx.Repo.Owner.DashboardLink()) +} + // SettingsPost response for changes of a repository func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { ctx.Data["Title"] = ctx.Tr("repo.settings") diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 5345a1017198e..64c3382a1646e 100644 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -629,6 +629,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/:username/:reponame/releases/download/:vTag/:fileName", ignSignIn, context.RepoAssignment(), repo.MustBeNotEmpty, repo.RedirectDownload) m.Group("/:username/:reponame", func() { + m.Post("/migrate_cancel", repo.CancelMigration) m.Group("/settings", func() { m.Combo("").Get(repo.Settings). Post(bindIgnErr(auth.RepoSettingForm{}), repo.SettingsPost) diff --git a/templates/repo/migrate/migrating.tmpl b/templates/repo/migrate/migrating.tmpl index 0057325e914da..57b32ea2e4d84 100644 --- a/templates/repo/migrate/migrating.tmpl +++ b/templates/repo/migrate/migrating.tmpl @@ -9,7 +9,7 @@
- +
@@ -23,6 +23,19 @@ + + {{if .Permission.IsAdmin}} +
+
+
+ {{.CsrfTokenHtml}} + +
+
+ {{end}} +