Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions routers/web/user/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,51 @@ package user

import (
"net/http"
"strconv"

admin_model "code.gitea.io/gitea/models/admin"
access_model "code.gitea.io/gitea/models/perm/access"
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/services/context"
)

// TaskStatus returns task's status
func TaskStatus(ctx *context.Context) {
task, opts, err := admin_model.GetMigratingTaskByID(ctx, ctx.PathParamInt64("task"), ctx.Doer.ID)
task, _, err := admin_model.GetMigratingTaskByID(ctx, ctx.PathParamInt64("task"), 0)
if err != nil {
if admin_model.IsErrTaskDoesNotExist(err) {
ctx.JSON(http.StatusNotFound, map[string]any{
"error": "task `" + strconv.FormatInt(ctx.PathParamInt64("task"), 10) + "` does not exist",
"err": "task does not exist or you do not have access to this task",
})
return
}
log.Error("GetMigratingTaskByID: %v", err)
ctx.JSON(http.StatusInternalServerError, map[string]any{
"err": err,
"err": http.StatusText(http.StatusInternalServerError),
})
return
}

if err := task.LoadRepo(ctx); err != nil {
log.Error("LoadRepo: %v", err)
ctx.JSON(http.StatusInternalServerError, map[string]any{
"err": http.StatusText(http.StatusInternalServerError),
})
return
}

perm, err := access_model.GetUserRepoPermission(ctx, task.Repo, ctx.Doer)
if err != nil {
log.Error("LoadRepo: %v", err)
ctx.JSON(http.StatusInternalServerError, map[string]any{
"err": http.StatusText(http.StatusInternalServerError),
})
return
}
if !perm.CanRead(unit.TypeCode) {
ctx.JSON(http.StatusNotFound, map[string]any{
"err": "task does not exist or you do not have access to this task",
})
return
}
Expand All @@ -43,11 +69,7 @@ func TaskStatus(ctx *context.Context) {
}

ctx.JSON(http.StatusOK, map[string]any{
"status": task.Status,
"message": message,
"repo-id": task.RepoID,
"repo-name": opts.RepoName,
"start": task.StartTime,
"end": task.EndTime,
"status": task.Status,
"message": message,
})
}
2 changes: 1 addition & 1 deletion routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ func registerRoutes(m *web.Router) {
m.Get("/forgot_password", auth.ForgotPasswd)
m.Post("/forgot_password", auth.ForgotPasswdPost)
m.Post("/logout", auth.SignOut)
m.Get("/task/{task}", reqSignIn, user.TaskStatus)
m.Get("/task/{task}", user.TaskStatus)
m.Get("/stopwatches", reqSignIn, user.GetStopwatches)
m.Get("/search", ignExploreSignIn, user.Search)
m.Group("/oauth2", func() {
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/features/repo-migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function initRepoMigrationStatusChecker() {
const repoMigrating = document.querySelector('#repo_migrating');
if (!repoMigrating) return;

document.querySelector('#repo_migrating_retry').addEventListener('click', doMigrationRetry);
document.querySelector('#repo_migrating_retry')?.addEventListener('click', doMigrationRetry);

const task = repoMigrating.getAttribute('data-migrating-task-id');

Expand Down
Loading