aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-02-24 01:22:46 +0000
committerGitHub <noreply@github.com>2022-02-24 09:22:46 +0800
commit81b29d6263aff460e8321464a8e473efac7a103d (patch)
tree8d9e879caa83499f0370db36c3c7d389786292c7 /models
parent6591f87b28edbdf25ac16985f6aa1a190f7ba2e8 (diff)
downloadgitea-81b29d6263aff460e8321464a8e473efac7a103d.tar.gz
gitea-81b29d6263aff460e8321464a8e473efac7a103d.zip
Update assignees check to include any writing team and change org sidebar (#18680) (#18873)
Backport #18680 Following the merging of #17811 teams can now have differing write and readonly permissions, however the assignee list will not include teams which have mixed perms. Further the org sidebar is no longer helpful as it can't describe these mixed permissions situations. Fix #18572 Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'models')
-rw-r--r--models/repo.go51
1 files changed, 40 insertions, 11 deletions
diff --git a/models/repo.go b/models/repo.go
index 83031c508c..933bb6c2a7 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -150,27 +150,56 @@ func getRepoAssignees(ctx context.Context, repo *repo_model.Repository) (_ []*us
}
e := db.GetEngine(ctx)
- accesses := make([]*Access, 0, 10)
- if err = e.
+ userIDs := make([]int64, 0, 10)
+ if err = e.Table("access").
Where("repo_id = ? AND mode >= ?", repo.ID, perm.AccessModeWrite).
- Find(&accesses); err != nil {
+ Select("id").
+ Find(&userIDs); err != nil {
return nil, err
}
- // Leave a seat for owner itself to append later, but if owner is an organization
- // and just waste 1 unit is cheaper than re-allocate memory once.
- users := make([]*user_model.User, 0, len(accesses)+1)
- if len(accesses) > 0 {
- userIDs := make([]int64, len(accesses))
- for i := 0; i < len(accesses); i++ {
- userIDs[i] = accesses[i].UserID
+ additionalUserIDs := make([]int64, 0, 10)
+ if err = e.Table("team_user").
+ Join("INNER", "team_repo", "`team_repo`.team_id = `team_user`.team_id").
+ Join("INNER", "team_unit", "`team_unit`.team_id = `team_user`.team_id").
+ Where("`team_repo`.repo_id = ? AND `team_unit`.access_mode >= ?", repo.ID, perm.AccessModeWrite).
+ Distinct("`team_user`.uid").
+ Select("`team_user`.uid").
+ Find(&additionalUserIDs); err != nil {
+ return nil, err
+ }
+
+ uidMap := map[int64]bool{}
+ i := 0
+ for _, uid := range userIDs {
+ if uidMap[uid] {
+ continue
+ }
+ uidMap[uid] = true
+ userIDs[i] = uid
+ i++
+ }
+ userIDs = userIDs[:i]
+ userIDs = append(userIDs, additionalUserIDs...)
+
+ for _, uid := range additionalUserIDs {
+ if uidMap[uid] {
+ continue
}
+ userIDs[i] = uid
+ i++
+ }
+ userIDs = userIDs[:i]
+ // Leave a seat for owner itself to append later, but if owner is an organization
+ // and just waste 1 unit is cheaper than re-allocate memory once.
+ users := make([]*user_model.User, 0, len(userIDs)+1)
+ if len(userIDs) > 0 {
if err = e.In("id", userIDs).Find(&users); err != nil {
return nil, err
}
}
- if !repo.Owner.IsOrganization() {
+ if !repo.Owner.IsOrganization() && !uidMap[repo.OwnerID] {
users = append(users, repo.Owner)
}