Skip to content

Commit 6142f66

Browse files
committed
use CollaborativeOwnerIDs
1 parent 6b2434f commit 6142f66

File tree

20 files changed

+159
-54
lines changed

20 files changed

+159
-54
lines changed

models/repo/repo_unit.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,10 @@ func (cfg *PullRequestsConfig) GetDefaultMergeStyle() MergeStyle {
169169
}
170170

171171
type ActionsConfig struct {
172-
DisabledWorkflows []string
173-
AccessbleFromOtherRepos bool
172+
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
174176
}
175177

176178
func (cfg *ActionsConfig) EnableWorkflow(file string) {
@@ -195,6 +197,20 @@ func (cfg *ActionsConfig) DisableWorkflow(file string) {
195197
cfg.DisabledWorkflows = append(cfg.DisabledWorkflows, file)
196198
}
197199

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

models/user/search.go

Lines changed: 6 additions & 4 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
@@ -45,15 +46,16 @@ type SearchUserOptions struct {
4546

4647
func (opts *SearchUserOptions) toSearchQueryBase(ctx context.Context) *xorm.Session {
4748
var cond builder.Cond
48-
cond = builder.Eq{"type": opts.Type}
49+
cond = builder.In("type", opts.Types)
4950
if opts.IncludeReserved {
50-
if opts.Type == UserTypeIndividual {
51+
if slices.Contains(opts.Types, UserTypeIndividual) {
5152
cond = cond.Or(builder.Eq{"type": UserTypeUserReserved}).Or(
5253
builder.Eq{"type": UserTypeBot},
5354
).Or(
5455
builder.Eq{"type": UserTypeRemoteUser},
5556
)
56-
} else if opts.Type == UserTypeOrganization {
57+
}
58+
if slices.Contains(opts.Types, UserTypeOrganization) {
5759
cond = cond.Or(builder.Eq{"type": UserTypeOrganizationReserved})
5860
}
5961
}

models/user/user.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,3 +1317,15 @@ func DisabledFeaturesWithLoginType(user *User) *container.Set[string] {
13171317
}
13181318
return &setting.Admin.UserDisabledFeatures
13191319
}
1320+
1321+
// GetUserOrOrgIDByName returns the id for a user or an org by name
1322+
func GetUserOrOrgIDByName(ctx context.Context, name string) (int64, error) {
1323+
var id int64
1324+
has, err := db.GetEngine(ctx).Table("user").Where("name = ?", name).Cols("id").Get(&id)
1325+
if err != nil {
1326+
return 0, err
1327+
} else if !has {
1328+
return 0, fmt.Errorf("user or org with name %s: %w", name, util.ErrNotExist)
1329+
}
1330+
return id, nil
1331+
}

models/user/user_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestSearchUsers(t *testing.T) {
7676

7777
// test orgs
7878
testOrgSuccess := func(opts *user_model.SearchUserOptions, expectedOrgIDs []int64) {
79-
opts.Type = user_model.UserTypeOrganization
79+
opts.Types = []user_model.UserType{user_model.UserTypeOrganization}
8080
testSuccess(opts, expectedOrgIDs)
8181
}
8282

@@ -100,7 +100,7 @@ func TestSearchUsers(t *testing.T) {
100100

101101
// test users
102102
testUserSuccess := func(opts *user_model.SearchUserOptions, expectedUserIDs []int64) {
103-
opts.Type = user_model.UserTypeIndividual
103+
opts.Types = []user_model.UserType{user_model.UserTypeIndividual}
104104
testSuccess(opts, expectedUserIDs)
105105
}
106106

options/locale/locale_en-US.ini

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3755,10 +3755,11 @@ variables.update.failed = Failed to edit variable.
37553755
variables.update.success = The variable has been edited.
37563756

37573757
general = General
3758-
general.settings = Actions General Settings
3759-
general.actions_accessible_from_other_repositories = Accessible from repositories owned by '%s'
3760-
general.actions_accessible_from_other_repositories_desc = Workflows in other repositories that are owned by the user '%s' can access the actions and reusable workflows in this repository. Access is allowed only from private repositories.
3761-
general.actions_always_accessible_desc = The actions and workflows of a public repository are always accessible to other repositories.
3758+
general.collaborative_owners_management = Collaborative Owners Management
3759+
general.add_collaborative_owner = Add Collaborative Owner
3760+
general.collaborative_owner_not_exist = The collaborative owner does not exist.
3761+
general.remove_collaborative_owner = Remove Collaborative Owner
3762+
general.remove_collaborative_owner_desc = Removing a collaborative owner will prevent the repositories of the owner from accessing the actions in this repository. Continue?
37623763

37633764
[projects]
37643765
deleted.display_name = Deleted Project

routers/api/v1/admin/org.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func GetAllOrgs(ctx *context.APIContext) {
103103

104104
users, maxResults, err := user_model.SearchUsers(ctx, &user_model.SearchUserOptions{
105105
Actor: ctx.Doer,
106-
Type: user_model.UserTypeOrganization,
106+
Types: []user_model.UserType{user_model.UserTypeOrganization},
107107
OrderBy: db.SearchOrderByAlphabetically,
108108
ListOptions: listOptions,
109109
Visible: []api.VisibleType{api.VisibleTypePublic, api.VisibleTypeLimited, api.VisibleTypePrivate},

routers/api/v1/admin/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ func SearchUsers(ctx *context.APIContext) {
423423

424424
users, maxResults, err := user_model.SearchUsers(ctx, &user_model.SearchUserOptions{
425425
Actor: ctx.Doer,
426-
Type: user_model.UserTypeIndividual,
426+
Types: []user_model.UserType{user_model.UserTypeIndividual},
427427
LoginName: ctx.FormTrim("login_name"),
428428
SourceID: ctx.FormInt64("source_id"),
429429
OrderBy: db.SearchOrderByAlphabetically,

routers/api/v1/org/org.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func GetAll(ctx *context.APIContext) {
203203
publicOrgs, maxResults, err := user_model.SearchUsers(ctx, &user_model.SearchUserOptions{
204204
Actor: ctx.Doer,
205205
ListOptions: listOptions,
206-
Type: user_model.UserTypeOrganization,
206+
Types: []user_model.UserType{user_model.UserTypeOrganization},
207207
OrderBy: db.SearchOrderByAlphabetically,
208208
Visible: vMode,
209209
})

routers/api/v1/user/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func Search(ctx *context.APIContext) {
7676
Actor: ctx.Doer,
7777
Keyword: ctx.FormTrim("q"),
7878
UID: uid,
79-
Type: user_model.UserTypeIndividual,
79+
Types: []user_model.UserType{user_model.UserTypeIndividual},
8080
SearchByEmail: true,
8181
Visible: visible,
8282
ListOptions: listOptions,

routers/web/admin/orgs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func Organizations(ctx *context.Context) {
2929

3030
explore.RenderUserSearch(ctx, &user_model.SearchUserOptions{
3131
Actor: ctx.Doer,
32-
Type: user_model.UserTypeOrganization,
32+
Types: []user_model.UserType{user_model.UserTypeOrganization},
3333
IncludeReserved: true, // administrator needs to list all accounts include reserved
3434
ListOptions: db.ListOptions{
3535
PageSize: setting.UI.Admin.OrgPagingNum,

0 commit comments

Comments
 (0)