Skip to content

Commit 05af60b

Browse files
author
zsbahtiar
committed
refactor: change to GetRunsByIDsAndTriggerUserID
1 parent 5dd6245 commit 05af60b

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

models/actions/run.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,11 @@ func DeleteRunByIDs(ctx context.Context, runIDs, jobIDs []int64) error {
480480
return committer.Commit()
481481
}
482482

483-
func GetRunsByIDs(ctx context.Context, ids []int64) ([]*ActionRun, error) {
483+
// GetRunsByIDsAndTriggerUserID -- get all action run by trigger user with selected ids
484+
func GetRunsByIDsAndTriggerUserID(ctx context.Context, ids []int64, triggerUserID int64) ([]*ActionRun, error) {
484485
var runs []*ActionRun
485-
err := db.GetEngine(ctx).In("id", ids).Find(&runs)
486+
err := db.GetEngine(ctx).Where("trigger_user_id=?", triggerUserID).
487+
In("id", ids).Find(&runs)
486488
if err != nil {
487489
return nil, err
488490
}

models/actions/run_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package actions
2+
3+
import (
4+
db_model "code.gitea.io/gitea/models/db"
5+
"testing"
6+
)
7+
8+
func TestDeleteRunByIDs(t *testing.T) {
9+
tests := []struct{
10+
name string
11+
mock func(m *db_model.Engine)
12+
13+
}
14+
}

routers/web/repo/actions/actions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ func DeleteRuns(ctx *context.Context) {
441441
return
442442
}
443443

444-
actionRun, err := actions_model.GetRunsByIDs(ctx, req.ActionIDs)
444+
actionRun, err := actions_model.GetRunsByIDsAndTriggerUserID(ctx, req.ActionIDs, ctx.Doer.ID)
445445
if err != nil {
446446
ctx.ServerError("failed to get action_run", err)
447447
return

0 commit comments

Comments
 (0)