@@ -8,13 +8,15 @@ import (
88 "strconv"
99
1010 admin_model "code.gitea.io/gitea/models/admin"
11+ access_model "code.gitea.io/gitea/models/perm/access"
12+ "code.gitea.io/gitea/models/unit"
1113 "code.gitea.io/gitea/modules/json"
1214 "code.gitea.io/gitea/services/context"
1315)
1416
1517// TaskStatus returns task's status
1618func TaskStatus (ctx * context.Context ) {
17- task , opts , err := admin_model .GetMigratingTaskByID (ctx , ctx .PathParamInt64 ("task" ), ctx . Doer . ID )
19+ task , _ , err := admin_model .GetMigratingTaskByID (ctx , ctx .PathParamInt64 ("task" ), 0 )
1820 if err != nil {
1921 if admin_model .IsErrTaskDoesNotExist (err ) {
2022 ctx .JSON (http .StatusNotFound , map [string ]any {
@@ -28,6 +30,27 @@ func TaskStatus(ctx *context.Context) {
2830 return
2931 }
3032
33+ if err := task .LoadRepo (ctx ); err != nil {
34+ ctx .JSON (http .StatusInternalServerError , map [string ]any {
35+ "err" : err ,
36+ })
37+ return
38+ }
39+
40+ perm , err := access_model .GetUserRepoPermission (ctx , task .Repo , ctx .Doer )
41+ if err != nil {
42+ ctx .JSON (http .StatusInternalServerError , map [string ]any {
43+ "err" : err ,
44+ })
45+ return
46+ }
47+ if ! perm .CanRead (unit .TypeCode ) {
48+ ctx .JSON (http .StatusForbidden , map [string ]any {
49+ "error" : "you do not have access to this task" ,
50+ })
51+ return
52+ }
53+
3154 message := task .Message
3255
3356 if task .Message != "" && task .Message [0 ] == '{' {
@@ -43,11 +66,7 @@ func TaskStatus(ctx *context.Context) {
4366 }
4467
4568 ctx .JSON (http .StatusOK , map [string ]any {
46- "status" : task .Status ,
47- "message" : message ,
48- "repo-id" : task .RepoID ,
49- "repo-name" : opts .RepoName ,
50- "start" : task .StartTime ,
51- "end" : task .EndTime ,
69+ "status" : task .Status ,
70+ "message" : message ,
5271 })
5372}
0 commit comments