Skip to content

Commit 3d9c4a4

Browse files
committed
Change Assignee list to include any team member with WriteAccess
Fix go-gitea#18572 Signed-off-by: Andrew Thornton <art27@cantab.net>
1 parent ad14f9c commit 3d9c4a4

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

models/repo.go

+41-11
Original file line numberDiff line numberDiff line change
@@ -150,27 +150,57 @@ func getRepoAssignees(ctx context.Context, repo *repo_model.Repository) (_ []*us
150150
}
151151

152152
e := db.GetEngine(ctx)
153-
accesses := make([]*Access, 0, 10)
154-
if err = e.
153+
userIDs := make([]int64, 0, 10)
154+
if err = e.Table("access").
155155
Where("repo_id = ? AND mode >= ?", repo.ID, perm.AccessModeWrite).
156-
Find(&accesses); err != nil {
156+
Distinct("id").
157+
Select("id").
158+
Find(&userIDs); err != nil {
157159
return nil, err
158160
}
159161

160-
// Leave a seat for owner itself to append later, but if owner is an organization
161-
// and just waste 1 unit is cheaper than re-allocate memory once.
162-
users := make([]*user_model.User, 0, len(accesses)+1)
163-
if len(accesses) > 0 {
164-
userIDs := make([]int64, len(accesses))
165-
for i := 0; i < len(accesses); i++ {
166-
userIDs[i] = accesses[i].UserID
162+
additionalUserIDs := make([]int64, 0, 10)
163+
if err = e.Table("team_user").
164+
Join("INNER", "team_repo", "`team_repo`.team_id = `team_user`.team_id").
165+
Join("INNER", "team_unit", "`team_unit`.team_id = `team_user`.team_id").
166+
Where("`team_repo`.repo_id = ? AND `team_unit`.access_mode >= ?", repo.ID, perm.AccessModeWrite).
167+
Distinct("`team_user`.uid").
168+
Select("`team_user`.uid").
169+
Find(&additionalUserIDs); err != nil {
170+
return nil, err
171+
}
172+
173+
uidMap := map[int64]bool{}
174+
i := 0
175+
for _, uid := range userIDs {
176+
if uidMap[uid] {
177+
continue
178+
}
179+
uidMap[uid] = true
180+
userIDs[i] = uid
181+
i++
182+
}
183+
userIDs = userIDs[:i]
184+
userIDs = append(userIDs, additionalUserIDs...)
185+
186+
for _, uid := range additionalUserIDs {
187+
if uidMap[uid] {
188+
continue
167189
}
190+
userIDs[i] = uid
191+
i++
192+
}
193+
userIDs = userIDs[:i]
168194

195+
// Leave a seat for owner itself to append later, but if owner is an organization
196+
// and just waste 1 unit is cheaper than re-allocate memory once.
197+
users := make([]*user_model.User, 0, len(userIDs)+1)
198+
if len(userIDs) > 0 {
169199
if err = e.In("id", userIDs).Find(&users); err != nil {
170200
return nil, err
171201
}
172202
}
173-
if !repo.Owner.IsOrganization() {
203+
if !repo.Owner.IsOrganization() && !uidMap[repo.OwnerID] {
174204
users = append(users, repo.Owner)
175205
}
176206

0 commit comments

Comments
 (0)