Skip to content

Commit 7cb4939

Browse files
committed
add access_model.ActionsTaskIDKey
1 parent 51cf3da commit 7cb4939

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

models/git/lfs_lock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func CheckLFSAccessForRepo(ctx context.Context, ownerID int64, repo *repo_model.
187187
return ErrLFSUnauthorizedAction{repo.ID, "undefined", mode}
188188
}
189189
if ownerID == user_model.ActionsUserID {
190-
taskId, ok := ctx.Value(user_model.ActionsUserName).(int64)
190+
taskId, ok := ctx.Value(access_model.ActionsTaskIDKey).(int64)
191191
if !ok || taskId == 0 {
192192
return ErrLFSUnauthorizedAction{repo.ID, user_model.ActionsUserName, mode}
193193
}

models/perm/access/repo_permission.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,11 @@ 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+
258263
// GetActionsUserRepoPermission returns the actions user permissions to the repository
259264
func GetActionsUserRepoPermission(ctx context.Context, repo *repo_model.Repository, actionsUser *user_model.User, taskID int64) (perm Permission, err error) {
260265
if actionsUser.ID != user_model.ActionsUserID {

services/lfs/locks.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111

1212
auth_model "code.gitea.io/gitea/models/auth"
1313
git_model "code.gitea.io/gitea/models/git"
14+
access_model "code.gitea.io/gitea/models/perm/access"
1415
repo_model "code.gitea.io/gitea/models/repo"
15-
user_model "code.gitea.io/gitea/models/user"
1616
"code.gitea.io/gitea/modules/json"
1717
lfs_module "code.gitea.io/gitea/modules/lfs"
1818
"code.gitea.io/gitea/modules/log"
@@ -179,9 +179,9 @@ func PostLockHandler(ctx *context.Context) {
179179

180180
var lockCtx go_context.Context = ctx
181181
// Pass Actions Task ID in context if creating lock using Actions Job Token
182-
if ctx.Doer != nil && ctx.Doer.ID == user_model.ActionsUserID {
182+
if ctx.Data["IsActionsToken"] == true {
183183
taskID := ctx.Data["ActionsTaskID"].(int64)
184-
lockCtx = go_context.WithValue(lockCtx, user_model.ActionsUserName, taskID)
184+
lockCtx = go_context.WithValue(lockCtx, access_model.ActionsTaskIDKey, taskID)
185185
}
186186

187187
lock, err := git_model.CreateLFSLock(lockCtx, repository, &git_model.LFSLock{
@@ -326,9 +326,9 @@ func UnLockHandler(ctx *context.Context) {
326326

327327
var lockCtx go_context.Context = ctx
328328
// Pass Actions Task ID in context if deleting lock using Actions Job Token
329-
if ctx.Doer != nil && ctx.Doer.ID == user_model.ActionsUserID {
329+
if ctx.Data["IsActionsToken"] == true {
330330
taskID := ctx.Data["ActionsTaskID"].(int64)
331-
lockCtx = go_context.WithValue(lockCtx, user_model.ActionsUserName, taskID)
331+
lockCtx = go_context.WithValue(lockCtx, access_model.ActionsTaskIDKey, taskID)
332332
}
333333

334334
lock, err := git_model.DeleteLFSLockByID(lockCtx, ctx.PathParamInt64("lid"), repository, ctx.Doer, req.Force)

0 commit comments

Comments
 (0)