Skip to content

Commit cf6c1c5

Browse files
authored
Merge branch 'main' into lunny/catfile_batch_refactor
2 parents e2f4663 + bc50431 commit cf6c1c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+439
-48
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ require (
109109
github.com/ulikunitz/xz v0.5.15
110110
github.com/urfave/cli-docs/v3 v3.0.0-alpha6
111111
github.com/urfave/cli/v3 v3.4.1
112-
github.com/wneessen/go-mail v0.7.1
112+
github.com/wneessen/go-mail v0.7.2
113113
github.com/xeipuuv/gojsonschema v1.2.0
114114
github.com/yohcop/openid-go v1.0.1
115115
github.com/yuin/goldmark v1.7.13

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,8 @@ github.com/urfave/cli/v3 v3.4.1/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZ
768768
github.com/valyala/fastjson v1.6.4 h1:uAUNq9Z6ymTgGhcm0UynUAB6tlbakBrz6CQFax3BXVQ=
769769
github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
770770
github.com/willf/bitset v1.1.10/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
771-
github.com/wneessen/go-mail v0.7.1 h1:rvy63sp14N06/kdGqCYwW8Na5gDCXjTQM1E7So4PuKk=
772-
github.com/wneessen/go-mail v0.7.1/go.mod h1:+TkW6QP3EVkgTEqHtVmnAE/1MRhmzb8Y9/W3pweuS+k=
771+
github.com/wneessen/go-mail v0.7.2 h1:xxPnhZ6IZLSgxShebmZ6DPKh1b6OJcoHfzy7UjOkzS8=
772+
github.com/wneessen/go-mail v0.7.2/go.mod h1:+TkW6QP3EVkgTEqHtVmnAE/1MRhmzb8Y9/W3pweuS+k=
773773
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
774774
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
775775
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=

models/fixtures/action_run.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,23 @@
139139
updated: 1683636626
140140
need_approval: 0
141141
approved_by: 0
142+
-
143+
id: 804
144+
title: "use a private action"
145+
repo_id: 60
146+
owner_id: 40
147+
workflow_id: "run.yaml"
148+
index: 189
149+
trigger_user_id: 40
150+
ref: "refs/heads/master"
151+
commit_sha: "6e64b26de7ba966d01d90ecfaf5c7f14ef203e86"
152+
event: "push"
153+
trigger_event: "push"
154+
is_fork_pull_request: 0
155+
status: 1
156+
started: 1683636528
157+
stopped: 1683636626
158+
created: 1683636108
159+
updated: 1683636626
160+
need_approval: 0
161+
approved_by: 0

models/fixtures/action_run_job.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,17 @@
129129
status: 5
130130
started: 1683636528
131131
stopped: 1683636626
132+
-
133+
id: 205
134+
run_id: 804
135+
repo_id: 6
136+
owner_id: 10
137+
commit_sha: 6e64b26de7ba966d01d90ecfaf5c7f14ef203e86
138+
is_fork_pull_request: 0
139+
name: job_2
140+
attempt: 1
141+
job_id: job_2
142+
task_id: 48
143+
status: 1
144+
started: 1683636528
145+
stopped: 1683636626

models/fixtures/action_task.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,23 @@
177177
log_length: 0
178178
log_size: 0
179179
log_expired: 0
180+
-
181+
id: 55
182+
job_id: 205
183+
attempt: 1
184+
runner_id: 1
185+
status: 6 # 6 is the status code for "running"
186+
started: 1683636528
187+
stopped: 1683636626
188+
repo_id: 6
189+
owner_id: 10
190+
commit_sha: 6e64b26de7ba966d01d90ecfaf5c7f14ef203e86
191+
is_fork_pull_request: 0
192+
token_hash: b8d3962425466b6709b9ac51446f93260c54afe8e7b6d3686e34f991fb8a8953822b0deed86fe41a103f34bc48dbc478422b
193+
token_salt: ERxJGHvg3I
194+
token_last_eight: 182199eb
195+
log_filename: collaborative-owner-test/1a/49.log
196+
log_in_storage: 1
197+
log_length: 707
198+
log_size: 90179
199+
log_expired: 0

models/fixtures/repo_unit.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,3 +733,10 @@
733733
type: 3
734734
config: "{\"IgnoreWhitespaceConflicts\":false,\"AllowMerge\":true,\"AllowRebase\":true,\"AllowRebaseMerge\":true,\"AllowSquash\":true}"
735735
created_unix: 946684810
736+
737+
-
738+
id: 111
739+
repo_id: 3
740+
type: 10
741+
config: "{}"
742+
created_unix: 946684810

models/perm/access/repo_permission.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,22 @@ func GetActionsUserRepoPermission(ctx context.Context, repo *repo_model.Reposito
264264
if err != nil {
265265
return perm, err
266266
}
267-
if task.RepoID != repo.ID {
268-
// FIXME allow public repo read access if tokenless pull is enabled
269-
return perm, nil
270-
}
271267

272268
var accessMode perm_model.AccessMode
273-
if task.IsForkPullRequest {
269+
if task.RepoID != repo.ID {
270+
taskRepo, exist, err := db.GetByID[repo_model.Repository](ctx, task.RepoID)
271+
if err != nil || !exist {
272+
return perm, err
273+
}
274+
actionsCfg := repo.MustGetUnit(ctx, unit.TypeActions).ActionsConfig()
275+
if !actionsCfg.IsCollaborativeOwner(taskRepo.OwnerID) || !taskRepo.IsPrivate {
276+
// The task repo can access the current repo only if the task repo is private and
277+
// the owner of the task repo is a collaborative owner of the current repo.
278+
// FIXME allow public repo read access if tokenless pull is enabled
279+
return perm, nil
280+
}
281+
accessMode = perm_model.AccessModeRead
282+
} else if task.IsForkPullRequest {
274283
accessMode = perm_model.AccessModeRead
275284
} else {
276285
accessMode = perm_model.AccessModeWrite

models/repo/repo_unit.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ func (cfg *PullRequestsConfig) GetDefaultMergeStyle() MergeStyle {
170170

171171
type ActionsConfig struct {
172172
DisabledWorkflows []string
173+
// CollaborativeOwnerIDs is a list of owner IDs used to share actions from private repos.
174+
// Only workflows from the private repos whose owners are in CollaborativeOwnerIDs can access the current repo's actions.
175+
CollaborativeOwnerIDs []int64
173176
}
174177

175178
func (cfg *ActionsConfig) EnableWorkflow(file string) {
@@ -192,6 +195,20 @@ func (cfg *ActionsConfig) DisableWorkflow(file string) {
192195
cfg.DisabledWorkflows = append(cfg.DisabledWorkflows, file)
193196
}
194197

198+
func (cfg *ActionsConfig) AddCollaborativeOwner(ownerID int64) {
199+
if !slices.Contains(cfg.CollaborativeOwnerIDs, ownerID) {
200+
cfg.CollaborativeOwnerIDs = append(cfg.CollaborativeOwnerIDs, ownerID)
201+
}
202+
}
203+
204+
func (cfg *ActionsConfig) RemoveCollaborativeOwner(ownerID int64) {
205+
cfg.CollaborativeOwnerIDs = util.SliceRemoveAll(cfg.CollaborativeOwnerIDs, ownerID)
206+
}
207+
208+
func (cfg *ActionsConfig) IsCollaborativeOwner(ownerID int64) bool {
209+
return slices.Contains(cfg.CollaborativeOwnerIDs, ownerID)
210+
}
211+
195212
// FromDB fills up a ActionsConfig from serialized format.
196213
func (cfg *ActionsConfig) FromDB(bs []byte) error {
197214
return json.UnmarshalHandleDoubleEncode(bs, &cfg)

models/user/search.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package user
66
import (
77
"context"
88
"fmt"
9+
"slices"
910
"strings"
1011

1112
"code.gitea.io/gitea/models/db"
@@ -22,7 +23,7 @@ type SearchUserOptions struct {
2223
db.ListOptions
2324

2425
Keyword string
25-
Type UserType
26+
Types []UserType
2627
UID int64
2728
LoginName string // this option should be used only for admin user
2829
SourceID int64 // this option should be used only for admin user
@@ -43,16 +44,16 @@ type SearchUserOptions struct {
4344

4445
func (opts *SearchUserOptions) toSearchQueryBase(ctx context.Context) *xorm.Session {
4546
var cond builder.Cond
46-
cond = builder.Eq{"type": opts.Type}
47+
cond = builder.In("type", opts.Types)
4748
if opts.IncludeReserved {
48-
switch opts.Type {
49-
case UserTypeIndividual:
49+
switch {
50+
case slices.Contains(opts.Types, UserTypeIndividual):
5051
cond = cond.Or(builder.Eq{"type": UserTypeUserReserved}).Or(
5152
builder.Eq{"type": UserTypeBot},
5253
).Or(
5354
builder.Eq{"type": UserTypeRemoteUser},
5455
)
55-
case UserTypeOrganization:
56+
case slices.Contains(opts.Types, UserTypeOrganization):
5657
cond = cond.Or(builder.Eq{"type": UserTypeOrganizationReserved})
5758
}
5859
}

models/user/user.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,3 +1449,15 @@ func DisabledFeaturesWithLoginType(user *User) *container.Set[string] {
14491449
}
14501450
return &setting.Admin.UserDisabledFeatures
14511451
}
1452+
1453+
// GetUserOrOrgIDByName returns the id for a user or an org by name
1454+
func GetUserOrOrgIDByName(ctx context.Context, name string) (int64, error) {
1455+
var id int64
1456+
has, err := db.GetEngine(ctx).Table("user").Where("name = ?", name).Cols("id").Get(&id)
1457+
if err != nil {
1458+
return 0, err
1459+
} else if !has {
1460+
return 0, fmt.Errorf("user or org with name %s: %w", name, util.ErrNotExist)
1461+
}
1462+
return id, nil
1463+
}

0 commit comments

Comments
 (0)