Commit 9c50fa7c authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Create Group#users_with_descendants method

parent 3d5a4ce5
...@@ -266,6 +266,12 @@ class Group < Namespace ...@@ -266,6 +266,12 @@ class Group < Namespace
User.where(id: members_with_parents.select(:user_id)) User.where(id: members_with_parents.select(:user_id))
end end
def users_with_descendants
members_with_descendants = GroupMember.non_request.where(source_id: descendants.pluck(:id).push(id))
User.where(id: members_with_descendants.select(:user_id))
end
def max_member_access_for_user(user) def max_member_access_for_user(user)
return GroupMember::OWNER if user.admin? return GroupMember::OWNER if user.admin?
......
...@@ -385,6 +385,25 @@ describe Group, models: true do ...@@ -385,6 +385,25 @@ describe Group, models: true do
end end
end end
describe '#users_with_descendants', :nested_groups do
let(:user_a) { create(:user) }
let(:user_b) { create(:user) }
let(:group) { create(:group) }
let(:nested_group) { create(:group, parent: group) }
let(:deep_nested_group) { create(:group, parent: nested_group) }
it 'returns member users on every nest level without duplication' do
group.add_developer(user_a)
nested_group.add_developer(user_b)
deep_nested_group.add_developer(user_a)
expect(group.users_with_descendants).to contain_exactly(user_a, user_b)
expect(nested_group.users_with_descendants).to contain_exactly(user_a, user_b)
expect(deep_nested_group.users_with_descendants).to contain_exactly(user_a)
end
end
describe '#user_ids_for_project_authorizations' do describe '#user_ids_for_project_authorizations' do
it 'returns the user IDs for which to refresh authorizations' do it 'returns the user IDs for which to refresh authorizations' do
master = create(:user) master = create(:user)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment