Commit b684a009 authored by Lucas Zampieri's avatar Lucas Zampieri

Simplified Specs for new relations fetch

Added tests for shared groups;
Simplified tests to check individual relations.
Signed-off-by: default avatarLucas Zampieri <lzampier@redhat.com>
parent d29c665b
# frozen_string_literal: true
class GroupMembersFinder < UnionFinder
RELATIONS = %i(direct inherited descendants shared_with_groups).freeze
RELATIONS = %i(direct inherited descendants shared_from_groups).freeze
DEFAULT_RELATIONS = %i(direct inherited).freeze
INVALID_RELATION_TYPE_ERROR_MSG = "is not a valid relation type. Valid relation types are #{RELATIONS.join(', ')}."
......@@ -30,8 +30,6 @@ class GroupMembersFinder < UnionFinder
def execute(include_relations: DEFAULT_RELATIONS)
groups = groups_by_relations(include_relations)
return GroupMember.none unless groups
members = all_group_members(groups).distinct_on_user_with_max_access_level
filter_members(members)
......@@ -44,14 +42,14 @@ class GroupMembersFinder < UnionFinder
def groups_by_relations(include_relations)
check_relation_arguments!(include_relations)
members = []
related_groups = []
members << Group.where(id: group.id) if include_relations.include?(:direct)
members << group.ancestors if include_relations.include?(:inherited)
members << group.descendants if include_relations.include?(:descendants)
members << group.shared_with_groups.public_or_visible_to_user(user) if include_relations.include?(:shared_from_groups)
related_groups << Group.by_id(group.id) if include_relations&.include?(:direct)
related_groups << group.ancestors if include_relations&.include?(:inherited)
related_groups << group.descendants if include_relations&.include?(:descendants)
related_groups << group.shared_with_groups.public_or_visible_to_user(user) if include_relations&.include?(:shared_from_groups)
find_union(members, Group)
find_union(related_groups, Group)
end
def filter_members(members)
......
......@@ -18,7 +18,7 @@ class GroupMember < Member
default_scope { where(source_type: SOURCE_TYPE) } # rubocop:disable Cop/DefaultScope
scope :of_groups, ->(groups) { where(source_id: groups.select(:id)) }
scope :of_groups, ->(groups) { where(source_id: groups&.select(:id)) }
scope :of_ldap_type, -> { where(ldap: true) }
scope :count_users_by_group_id, -> { group(:source_id).count }
scope :with_user, -> (user) { where(user: user) }
......
......@@ -16418,7 +16418,7 @@ Group member relation.
| <a id="groupmemberrelationdescendants"></a>`DESCENDANTS` | Members in the group's subgroups. |
| <a id="groupmemberrelationdirect"></a>`DIRECT` | Members in the group itself. |
| <a id="groupmemberrelationinherited"></a>`INHERITED` | Members in the group's ancestor groups. |
| <a id="groupmemberrelationshared_with_groups"></a>`SHARED_WITH_GROUPS` | Invited group's members. |
| <a id="groupmemberrelationshared_from_groups"></a>`SHARED_FROM_GROUPS` | Invited group's members. |
### `GroupPermission`
This diff is collapsed.
......@@ -6,6 +6,6 @@ RSpec.describe Types::GroupMemberRelationEnum do
specify { expect(described_class.graphql_name).to eq('GroupMemberRelation') }
it 'exposes all the existing group member relation type values' do
expect(described_class.values.keys).to contain_exactly('DIRECT', 'INHERITED', 'DESCENDANTS', 'SHARED_WITH_GROUPS')
expect(described_class.values.keys).to contain_exactly('DIRECT', 'INHERITED', 'DESCENDANTS', 'SHARED_FROM_GROUPS')
end
end
......@@ -76,7 +76,7 @@ RSpec.describe 'getting group members information' do
end
it 'returns invited members plus inherited members' do
fetch_members(group: child_group, args: { relations: [:DIRECT, :INHERITED, :SHARED_WITH_GROUPS] })
fetch_members(group: child_group, args: { relations: [:DIRECT, :INHERITED, :SHARED_FROM_GROUPS] })
expect(graphql_errors).to be_nil
expect_array_response(invited_user, user_1, user_2, child_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