}
// GetUsersWhoCanCreateOrgRepo returns users which are able to create repo in organization
-func GetUsersWhoCanCreateOrgRepo(ctx context.Context, orgID int64) ([]*user_model.User, error) {
- users := make([]*user_model.User, 0, 10)
+func GetUsersWhoCanCreateOrgRepo(ctx context.Context, orgID int64) (map[int64]*user_model.User, error) {
+ // Use a map, in order to de-duplicate users.
+ users := make(map[int64]*user_model.User)
return users, db.GetEngine(ctx).
Join("INNER", "`team_user`", "`team_user`.uid=`user`.id").
Join("INNER", "`team`", "`team`.id=`team_user`.team_id").
Where(builder.Eq{"team.can_create_org_repo": true}.Or(builder.Eq{"team.authorize": perm.AccessModeOwner})).
- And("team_user.org_id = ?", orgID).Asc("`user`.name").Find(&users)
+ And("team_user.org_id = ?", orgID).Find(&users)
}
// SearchOrganizationsOptions options to filter organizations
org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3})
teams, err := org.LoadTeams()
assert.NoError(t, err)
- if assert.Len(t, teams, 4) {
+ if assert.Len(t, teams, 5) {
assert.Equal(t, int64(1), teams[0].ID)
assert.Equal(t, int64(2), teams[1].ID)
assert.Equal(t, int64(12), teams[2].ID)
- assert.Equal(t, int64(7), teams[3].ID)
+ assert.Equal(t, int64(14), teams[3].ID)
+ assert.Equal(t, int64(7), teams[4].ID)
}
}
assert.NoError(t, err)
assert.Equal(t, expected, teamIDs)
}
- testSuccess(2, []int64{1, 2})
+ testSuccess(2, []int64{1, 2, 14})
testSuccess(4, []int64{2})
testSuccess(unittest.NonexistentID, []int64{})
}
users, err = organization.GetUsersWhoCanCreateOrgRepo(db.DefaultContext, 7)
assert.NoError(t, err)
assert.Len(t, users, 1)
- assert.EqualValues(t, 5, users[0].ID)
+ assert.NotNil(t, users[5])
}
func TestUser_RemoveOrgRepo(t *testing.T) {