aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/repo/migrate.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-10-02 12:37:16 +0800
committerGitHub <noreply@github.com>2024-10-02 04:37:16 +0000
commita989404e23f736e7ce1c71e7105506e3bc6cdd76 (patch)
tree10e3c797b382de65fde50a076a61f020d4fb5389 /routers/web/repo/migrate.go
parent3a4a1bffbebd8a6f024a7fc4849cebbd7f0274d4 (diff)
downloadgitea-a989404e23f736e7ce1c71e7105506e3bc6cdd76.tar.gz
gitea-a989404e23f736e7ce1c71e7105506e3bc6cdd76.zip
Fix javascript error when an anonymous user visiting migration page (#32144)
This PR fixes javascript errors when an anonymous user visits the migration page. It also makes task view checking more restrictive. The router moved from `/user/task/{id}/status` to `/username/reponame/-/migrate/status` because it's a migrate status. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'routers/web/repo/migrate.go')
-rw-r--r--routers/web/repo/migrate.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/routers/web/repo/migrate.go b/routers/web/repo/migrate.go
index 31a65c65ea..3eaf05f383 100644
--- a/routers/web/repo/migrate.go
+++ b/routers/web/repo/migrate.go
@@ -15,6 +15,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
+ "code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -288,3 +289,40 @@ func MigrateCancelPost(ctx *context.Context) {
}
ctx.Redirect(ctx.Repo.Repository.Link())
}
+
+// MigrateStatus returns migrate task's status
+func MigrateStatus(ctx *context.Context) {
+ task, err := admin_model.GetMigratingTask(ctx, ctx.Repo.Repository.ID)
+ if err != nil {
+ if admin_model.IsErrTaskDoesNotExist(err) {
+ ctx.JSON(http.StatusNotFound, map[string]any{
+ "err": "task does not exist or you do not have access to this task",
+ })
+ return
+ }
+ log.Error("GetMigratingTask: %v", err)
+ ctx.JSON(http.StatusInternalServerError, map[string]any{
+ "err": http.StatusText(http.StatusInternalServerError),
+ })
+ return
+ }
+
+ message := task.Message
+
+ if task.Message != "" && task.Message[0] == '{' {
+ // assume message is actually a translatable string
+ var translatableMessage admin_model.TranslatableMessage
+ if err := json.Unmarshal([]byte(message), &translatableMessage); err != nil {
+ translatableMessage = admin_model.TranslatableMessage{
+ Format: "migrate.migrating_failed.error",
+ Args: []any{task.Message},
+ }
+ }
+ message = ctx.Locale.TrString(translatableMessage.Format, translatableMessage.Args...)
+ }
+
+ ctx.JSON(http.StatusOK, map[string]any{
+ "status": task.Status,
+ "message": message,
+ })
+}