Commit 26dd0d4d authored by Lucas Zampieri's avatar Lucas Zampieri

Allow new relation to be used on GraphQL API, specs

Added new relation to RELATIONS in GroupMemberFinder, making it availble
throuth the the graphql api;
Added Grapqhl Specs;
Added new relation to graphql Docs;
Signed-off-by: default avatarLucas Zampieri <lzampier@redhat.com>
parent 9a5cdf27
# frozen_string_literal: true # frozen_string_literal: true
class GroupMembersFinder < UnionFinder class GroupMembersFinder < UnionFinder
RELATIONS = %i(direct inherited descendants).freeze RELATIONS = %i(direct inherited descendants shared_with_groups).freeze
DEFAULT_RELATIONS = %i(direct inherited).freeze DEFAULT_RELATIONS = %i(direct inherited).freeze
INVALID_RELATION_TYPE_ERROR_MSG = "is not a valid relation type. Valid relation types are #{RELATIONS.join(', ')}." INVALID_RELATION_TYPE_ERROR_MSG = "is not a valid relation type. Valid relation types are #{RELATIONS.join(', ')}."
RELATIONS_DESCRIPTIONS = { RELATIONS_DESCRIPTIONS = {
direct: 'Members in the group itself', direct: 'Members in the group itself',
inherited: "Members in the group's ancestor groups", inherited: "Members in the group's ancestor groups",
descendants: "Members in the group's subgroups" descendants: "Members in the group's subgroups",
shared_with_groups: "Invited Groups members"
}.freeze }.freeze
include CreatedAtFilter include CreatedAtFilter
......
...@@ -16418,6 +16418,7 @@ Group member relation. ...@@ -16418,6 +16418,7 @@ Group member relation.
| <a id="groupmemberrelationdescendants"></a>`DESCENDANTS` | Members in the group's subgroups. | | <a id="groupmemberrelationdescendants"></a>`DESCENDANTS` | Members in the group's subgroups. |
| <a id="groupmemberrelationdirect"></a>`DIRECT` | Members in the group itself. | | <a id="groupmemberrelationdirect"></a>`DIRECT` | Members in the group itself. |
| <a id="groupmemberrelationinherited"></a>`INHERITED` | Members in the group's ancestor groups. | | <a id="groupmemberrelationinherited"></a>`INHERITED` | Members in the group's ancestor groups. |
| <a id="groupmemberrelationshared_with_groups"></a>`SHARED_WITH_GROUPS` | Invited Groups members. |
### `GroupPermission` ### `GroupPermission`
...@@ -192,13 +192,16 @@ RSpec.describe GroupMembersFinder, '#execute' do ...@@ -192,13 +192,16 @@ RSpec.describe GroupMembersFinder, '#execute' do
end end
context 'when :shared_with_groups is passed' do context 'when :shared_with_groups is passed' do
let(:member1) { group.add_owner(user1) }
let(:member2) { shared_group.add_maintainer(user5) }
subject { described_class.new(group, user1).execute(include_relations: [:direct, :inherited, :shared_with_groups]) } subject { described_class.new(group, user1).execute(include_relations: [:direct, :inherited, :shared_with_groups]) }
it 'includes all the shared_with_groups members' do before do
member1 = group.add_owner(user1)
member2 = shared_group.add_maintainer(user5)
create(:group_group_link, shared_group: group, shared_with_group: shared_group) create(:group_group_link, shared_group: group, shared_with_group: shared_group)
end
it 'includes all the shared_with_groups members' do
expect(subject).to match_array([member1, member2]) expect(subject).to match_array([member1, member2])
end end
end end
......
...@@ -6,6 +6,6 @@ RSpec.describe Types::GroupMemberRelationEnum do ...@@ -6,6 +6,6 @@ RSpec.describe Types::GroupMemberRelationEnum do
specify { expect(described_class.graphql_name).to eq('GroupMemberRelation') } specify { expect(described_class.graphql_name).to eq('GroupMemberRelation') }
it 'exposes all the existing group member relation type values' do it 'exposes all the existing group member relation type values' do
expect(described_class.values.keys).to contain_exactly('DIRECT', 'INHERITED', 'DESCENDANTS') expect(described_class.values.keys).to contain_exactly('DIRECT', 'INHERITED', 'DESCENDANTS', 'SHARED_WITH_GROUPS')
end end
end end
...@@ -56,12 +56,16 @@ RSpec.describe 'getting group members information' do ...@@ -56,12 +56,16 @@ RSpec.describe 'getting group members information' do
context 'member relations' do context 'member relations' do
let_it_be(:child_group) { create(:group, :public, parent: parent_group) } let_it_be(:child_group) { create(:group, :public, parent: parent_group) }
let_it_be(:grandchild_group) { create(:group, :public, parent: child_group) } let_it_be(:grandchild_group) { create(:group, :public, parent: child_group) }
let_it_be(:invited_group) { create(:group, :public) }
let_it_be(:child_user) { create(:user) } let_it_be(:child_user) { create(:user) }
let_it_be(:grandchild_user) { create(:user) } let_it_be(:grandchild_user) { create(:user) }
let_it_be(:invited_user) { create(:user) }
let_it_be(:group_link) { create(:group_group_link, shared_group: child_group, shared_with_group: invited_group) }
before_all do before_all do
child_group.add_guest(child_user) child_group.add_guest(child_user)
grandchild_group.add_guest(grandchild_user) grandchild_group.add_guest(grandchild_user)
invited_group.add_guest(invited_user)
end end
it 'returns direct members' do it 'returns direct members' do
...@@ -71,6 +75,13 @@ RSpec.describe 'getting group members information' do ...@@ -71,6 +75,13 @@ RSpec.describe 'getting group members information' do
expect_array_response(child_user) expect_array_response(child_user)
end end
it 'returns invited members plus inherited members' do
fetch_members(group: child_group, args: { relations: [:DIRECT, :INHERITED, :SHARED_WITH_GROUPS] })
expect(graphql_errors).to be_nil
expect_array_response(invited_user, user_1, user_2, child_user)
end
it 'returns direct and inherited members' do it 'returns direct and inherited members' do
fetch_members(group: child_group, args: { relations: [:DIRECT, :INHERITED] }) fetch_members(group: child_group, args: { relations: [:DIRECT, :INHERITED] })
......
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