Skip to content

Commit 0c13471

Browse files
committed
pass taskID as parameter
1 parent 04b2c09 commit 0c13471

File tree

4 files changed

+15
-25
lines changed

4 files changed

+15
-25
lines changed

models/git/lfs_lock.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ func (l *LFSLock) LoadOwner(ctx context.Context) error {
6969
}
7070

7171
// CreateLFSLock creates a new lock.
72-
func CreateLFSLock(ctx context.Context, repo *repo_model.Repository, lock *LFSLock) (*LFSLock, error) {
72+
func CreateLFSLock(ctx context.Context, repo *repo_model.Repository, lock *LFSLock, taskID int64) (*LFSLock, error) {
7373
return db.WithTx2(ctx, func(ctx context.Context) (*LFSLock, error) {
74-
if err := CheckLFSAccessForRepo(ctx, lock.OwnerID, repo, perm.AccessModeWrite); err != nil {
74+
if err := CheckLFSAccessForRepo(ctx, lock.OwnerID, repo, perm.AccessModeWrite, taskID); err != nil {
7575
return nil, err
7676
}
7777

@@ -158,14 +158,14 @@ func CountLFSLockByRepoID(ctx context.Context, repoID int64) (int64, error) {
158158
}
159159

160160
// DeleteLFSLockByID deletes a lock by given ID.
161-
func DeleteLFSLockByID(ctx context.Context, id int64, repo *repo_model.Repository, u *user_model.User, force bool) (*LFSLock, error) {
161+
func DeleteLFSLockByID(ctx context.Context, id int64, repo *repo_model.Repository, u *user_model.User, force bool, taskID int64) (*LFSLock, error) {
162162
return db.WithTx2(ctx, func(ctx context.Context) (*LFSLock, error) {
163163
lock, err := GetLFSLockByID(ctx, id)
164164
if err != nil {
165165
return nil, err
166166
}
167167

168-
if err := CheckLFSAccessForRepo(ctx, u.ID, repo, perm.AccessModeWrite); err != nil {
168+
if err := CheckLFSAccessForRepo(ctx, u.ID, repo, perm.AccessModeWrite, taskID); err != nil {
169169
return nil, err
170170
}
171171

@@ -182,13 +182,12 @@ func DeleteLFSLockByID(ctx context.Context, id int64, repo *repo_model.Repositor
182182
}
183183

184184
// CheckLFSAccessForRepo check needed access mode base on action
185-
func CheckLFSAccessForRepo(ctx context.Context, ownerID int64, repo *repo_model.Repository, mode perm.AccessMode) error {
185+
func CheckLFSAccessForRepo(ctx context.Context, ownerID int64, repo *repo_model.Repository, mode perm.AccessMode, taskID int64) error {
186186
if ownerID == 0 {
187187
return ErrLFSUnauthorizedAction{repo.ID, "undefined", mode}
188188
}
189189
if ownerID == user_model.ActionsUserID {
190-
taskID, ok := ctx.Value(access_model.ActionsTaskIDKey).(int64)
191-
if !ok || taskID == 0 {
190+
if taskID == 0 {
192191
return ErrLFSUnauthorizedAction{repo.ID, user_model.ActionsUserName, mode}
193192
}
194193
perm, err := access_model.GetActionsUserRepoPermission(ctx, repo, user_model.NewActionsUser(), taskID)

models/perm/access/repo_permission.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,6 @@ func finalProcessRepoUnitPermission(user *user_model.User, perm *Permission) {
255255
}
256256
}
257257

258-
type ActionsTaskIDKeyType struct{}
259-
260-
// ActionsTaskIDKey is the context key for actions task ID in modules without context service like lfs locks
261-
var ActionsTaskIDKey ActionsTaskIDKeyType
262-
263258
// GetActionsUserRepoPermission returns the actions user permissions to the repository
264259
func GetActionsUserRepoPermission(ctx context.Context, repo *repo_model.Repository, actionsUser *user_model.User, taskID int64) (perm Permission, err error) {
265260
if actionsUser.ID != user_model.ActionsUserID {

routers/web/repo/setting/lfs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func LFSLockFile(ctx *context.Context) {
198198
_, err := git_model.CreateLFSLock(ctx, ctx.Repo.Repository, &git_model.LFSLock{
199199
Path: lockPath,
200200
OwnerID: ctx.Doer.ID,
201-
})
201+
}, 0)
202202
if err != nil {
203203
if git_model.IsErrLFSLockAlreadyExist(err) {
204204
ctx.Flash.Error(ctx.Tr("repo.settings.lfs_lock_already_exists", originalPath))
@@ -217,7 +217,7 @@ func LFSUnlock(ctx *context.Context) {
217217
ctx.NotFound(nil)
218218
return
219219
}
220-
_, err := git_model.DeleteLFSLockByID(ctx, ctx.PathParamInt64("lid"), ctx.Repo.Repository, ctx.Doer, true)
220+
_, err := git_model.DeleteLFSLockByID(ctx, ctx.PathParamInt64("lid"), ctx.Repo.Repository, ctx.Doer, true, 0)
221221
if err != nil {
222222
ctx.ServerError("LFSUnlock", err)
223223
return

services/lfs/locks.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
package lfs
55

66
import (
7-
go_context "context"
87
"net/http"
98
"strconv"
109
"strings"
1110

1211
auth_model "code.gitea.io/gitea/models/auth"
1312
git_model "code.gitea.io/gitea/models/git"
14-
access_model "code.gitea.io/gitea/models/perm/access"
1513
repo_model "code.gitea.io/gitea/models/repo"
1614
"code.gitea.io/gitea/modules/json"
1715
lfs_module "code.gitea.io/gitea/modules/lfs"
@@ -177,17 +175,16 @@ func PostLockHandler(ctx *context.Context) {
177175
return
178176
}
179177

180-
var lockCtx go_context.Context = ctx
178+
var taskID int64
181179
// Pass Actions Task ID in context if creating lock using Actions Job Token
182180
if ctx.Data["IsActionsToken"] == true {
183-
taskID := ctx.Data["ActionsTaskID"].(int64)
184-
lockCtx = go_context.WithValue(lockCtx, access_model.ActionsTaskIDKey, taskID)
181+
taskID = ctx.Data["ActionsTaskID"].(int64)
185182
}
186183

187-
lock, err := git_model.CreateLFSLock(lockCtx, repository, &git_model.LFSLock{
184+
lock, err := git_model.CreateLFSLock(ctx, repository, &git_model.LFSLock{
188185
Path: req.Path,
189186
OwnerID: ctx.Doer.ID,
190-
})
187+
}, taskID)
191188
if err != nil {
192189
if git_model.IsErrLFSLockAlreadyExist(err) {
193190
ctx.JSON(http.StatusConflict, api.LFSLockError{
@@ -324,14 +321,13 @@ func UnLockHandler(ctx *context.Context) {
324321
return
325322
}
326323

327-
var lockCtx go_context.Context = ctx
324+
var taskID int64
328325
// Pass Actions Task ID in context if deleting lock using Actions Job Token
329326
if ctx.Data["IsActionsToken"] == true {
330-
taskID := ctx.Data["ActionsTaskID"].(int64)
331-
lockCtx = go_context.WithValue(lockCtx, access_model.ActionsTaskIDKey, taskID)
327+
taskID = ctx.Data["ActionsTaskID"].(int64)
332328
}
333329

334-
lock, err := git_model.DeleteLFSLockByID(lockCtx, ctx.PathParamInt64("lid"), repository, ctx.Doer, req.Force)
330+
lock, err := git_model.DeleteLFSLockByID(ctx, ctx.PathParamInt64("lid"), repository, ctx.Doer, req.Force, taskID)
335331
if err != nil {
336332
if git_model.IsErrLFSUnauthorizedAction(err) {
337333
ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="gitea-lfs"`)

0 commit comments

Comments
 (0)