Skip to content

Commit

Permalink
Fix more bugs when view migrating repository
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Sep 27, 2024
1 parent f351b21 commit e0a9e25
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
33 changes: 26 additions & 7 deletions routers/web/user/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import (
"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/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{
Expand All @@ -28,6 +30,27 @@ func TaskStatus(ctx *context.Context) {
return
}

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

perm, err := access_model.GetUserRepoPermission(ctx, task.Repo, ctx.Doer)
if err != nil {
ctx.JSON(http.StatusInternalServerError, map[string]any{
"err": err,
})
return
}
if !perm.CanRead(unit.TypeCode) {
ctx.JSON(http.StatusForbidden, map[string]any{
"error": "you do not have access to this task",
})
return
}

message := task.Message

if task.Message != "" && task.Message[0] == '{' {
Expand All @@ -43,11 +66,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
5 changes: 1 addition & 4 deletions web_src/js/features/repo-migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ export function initRepoMigrationStatusChecker() {
const repoMigrating = document.querySelector('#repo_migrating');
if (!repoMigrating) return;

const retryBtn = document.querySelector('#repo_migrating_retry');
if (retryBtn) {
retryBtn.addEventListener('click', doMigrationRetry);
}
document.querySelector('#repo_migrating_retry')?.addEventListener('click', doMigrationRetry);

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

Expand Down

0 comments on commit e0a9e25

Please sign in to comment.