Skip to content

Commit 942d78f

Browse files
committed
Update backport
1 parent 949d3fe commit 942d78f

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

models/activities/notification.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func CreateRepoTransferNotification(doer, newOwner *user_model.User, repo *repo_
157157
}
158158
for i := range users {
159159
notify = append(notify, &Notification{
160-
UserID: users[i].ID,
160+
UserID: i,
161161
RepoID: repo.ID,
162162
Status: NotificationStatusUnread,
163163
UpdatedBy: doer.ID,

models/organization/org.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,16 +396,14 @@ func (org *Organization) GetOrgUserMaxAuthorizeLevel(uid int64) (perm.AccessMode
396396
}
397397

398398
// GetUsersWhoCanCreateOrgRepo returns users which are able to create repo in organization
399-
func GetUsersWhoCanCreateOrgRepo(ctx context.Context, orgID int64) ([]*user_model.User, error) {
400-
users := make([]*user_model.User, 0, 10)
399+
func GetUsersWhoCanCreateOrgRepo(ctx context.Context, orgID int64) (map[int64]*user_model.User, error) {
400+
// Use a map, in order to de-duplicate users.
401+
users := make(map[int64]*user_model.User)
401402
return users, db.GetEngine(ctx).
402403
Join("INNER", "`team_user`", "`team_user`.uid=`user`.id").
403404
Join("INNER", "`team`", "`team`.id=`team_user`.team_id").
404405
Where(builder.Eq{"team.can_create_org_repo": true}.Or(builder.Eq{"team.authorize": perm.AccessModeOwner})).
405-
And("team_user.org_id = ?", orgID).
406-
Asc("`user`.name").
407-
Distinct("`user`.id").
408-
Find(&users)
406+
And("team_user.org_id = ?", orgID).Find(&users)
409407
}
410408

411409
// SearchOrganizationsOptions options to filter organizations

models/organization/org_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ func TestGetUsersWhoCanCreateOrgRepo(t *testing.T) {
449449
users, err = organization.GetUsersWhoCanCreateOrgRepo(db.DefaultContext, 7)
450450
assert.NoError(t, err)
451451
assert.Len(t, users, 1)
452-
assert.EqualValues(t, 5, users[0].ID)
452+
assert.NotNil(t, users[5])
453453
}
454454

455455
func TestUser_RemoveOrgRepo(t *testing.T) {

0 commit comments

Comments
 (0)