Skip to content
代码片段 群组 项目
提交 aac69b0b 编辑于 作者: Manoj M J's avatar Manoj M J
浏览文件

GraphQL: lists the groups to where a project can be transferred to

GraphQL: lists the groups to where a project
can be transferred to

Changelog: added
上级 dcc34a45
No related branches found
No related tags found
无相关合并请求
......@@ -35,7 +35,7 @@ def execute
attr_reader :current_user, :target_user, :params
def sort(items)
items.order(path: :asc, id: :asc) # rubocop: disable CodeReuse/ActiveRecord
items.order(Group.arel_table[:path].asc, Group.arel_table[:id].asc) # rubocop: disable CodeReuse/ActiveRecord
end
def by_search(items)
......@@ -47,6 +47,8 @@ def by_search(items)
def by_permission_scope
if permission_scope_create_projects?
target_user.manageable_groups(include_groups_with_developer_maintainer_access: true)
elsif permission_scope_transfer_projects?
target_user.manageable_groups(include_groups_with_developer_maintainer_access: false)
else
target_user.groups
end
......@@ -55,5 +57,9 @@ def by_permission_scope
def permission_scope_create_projects?
params[:permission_scope] == :create_projects
end
def permission_scope_transfer_projects?
params[:permission_scope] == :transfer_projects
end
end
end
......@@ -7,6 +7,8 @@ class GroupEnum < BaseEnum
description 'User permission on groups'
value 'CREATE_PROJECTS', value: :create_projects, description: 'Groups where the user can create projects.'
value 'TRANSFER_PROJECTS', value: :transfer_projects,
description: 'Groups where the user can transfer projects to.'
end
end
end
......@@ -19233,6 +19233,7 @@ User permission on groups.
| Value | Description |
| ----- | ----------- |
| <a id="grouppermissioncreate_projects"></a>`CREATE_PROJECTS` | Groups where the user can create projects. |
| <a id="grouppermissiontransfer_projects"></a>`TRANSFER_PROJECTS` | Groups where the user can transfer projects to. |
 
### `HealthStatus`
 
......@@ -9,6 +9,7 @@
let_it_be(:private_maintainer_group) { create(:group, :private, name: 'b private maintainer', path: 'b-private-maintainer') }
let_it_be(:public_developer_group) { create(:group, project_creation_level: nil, name: 'c public developer', path: 'c-public-developer') }
let_it_be(:public_maintainer_group) { create(:group, name: 'a public maintainer', path: 'a-public-maintainer') }
let_it_be(:public_owner_group) { create(:group, name: 'a public owner', path: 'a-public-owner') }
subject { described_class.new(current_user, target_user, arguments).execute }
......@@ -21,12 +22,14 @@
private_maintainer_group.add_maintainer(user)
public_developer_group.add_developer(user)
public_maintainer_group.add_maintainer(user)
public_owner_group.add_owner(user)
end
it 'returns all groups where the user is a direct member' do
is_expected.to match(
[
public_maintainer_group,
public_owner_group,
private_maintainer_group,
public_developer_group,
guest_group
......@@ -53,6 +56,7 @@
is_expected.to match(
[
public_maintainer_group,
public_owner_group,
private_maintainer_group,
public_developer_group
]
......@@ -73,6 +77,32 @@
end
end
context 'when permission is :transfer_projects' do
let(:arguments) { { permission_scope: :transfer_projects } }
specify do
is_expected.to match(
[
public_maintainer_group,
public_owner_group,
private_maintainer_group
]
)
end
context 'when search is provided' do
let(:arguments) { { permission_scope: :transfer_projects, search: 'owner' } }
specify do
is_expected.to match(
[
public_owner_group
]
)
end
end
end
context 'when search is provided' do
let(:arguments) { { search: 'maintainer' } }
......
......@@ -12,6 +12,7 @@
let_it_be(:private_maintainer_group) { create(:group, :private, name: 'b private maintainer', path: 'b-private-maintainer') }
let_it_be(:public_developer_group) { create(:group, project_creation_level: nil, name: 'c public developer', path: 'c-public-developer') }
let_it_be(:public_maintainer_group) { create(:group, name: 'a public maintainer', path: 'a-public-maintainer') }
let_it_be(:public_owner_group) { create(:group, name: 'a public owner', path: 'a-public-owner') }
subject(:resolved_items) { resolve_groups(args: group_arguments, current_user: current_user, obj: resolver_object) }
......@@ -24,6 +25,7 @@
private_maintainer_group.add_maintainer(user)
public_developer_group.add_developer(user)
public_maintainer_group.add_maintainer(user)
public_owner_group.add_owner(user)
end
context 'when resolver object is current user' do
......@@ -34,6 +36,7 @@
is_expected.to match(
[
public_maintainer_group,
public_owner_group,
private_maintainer_group,
public_developer_group
]
......@@ -41,10 +44,25 @@
end
end
context 'when permission is :transfer_projects' do
let(:group_arguments) { { permission_scope: :transfer_projects } }
specify do
is_expected.to match(
[
public_maintainer_group,
public_owner_group,
private_maintainer_group
]
)
end
end
specify do
is_expected.to match(
[
public_maintainer_group,
public_owner_group,
private_maintainer_group,
public_developer_group,
guest_group
......@@ -82,6 +100,7 @@
is_expected.to match(
[
public_maintainer_group,
public_owner_group,
private_maintainer_group,
public_developer_group,
guest_group
......
......@@ -8,8 +8,9 @@
let_it_be(:user) { create(:user) }
let_it_be(:guest_group) { create(:group, name: 'public guest', path: 'public-guest') }
let_it_be(:private_maintainer_group) { create(:group, :private, name: 'b private maintainer', path: 'b-private-maintainer') }
let_it_be(:public_developer_group) { create(:group, :private, project_creation_level: nil, name: 'c public developer', path: 'c-public-developer') }
let_it_be(:public_maintainer_group) { create(:group, :private, name: 'a public maintainer', path: 'a-public-maintainer') }
let_it_be(:public_developer_group) { create(:group, project_creation_level: nil, name: 'c public developer', path: 'c-public-developer') }
let_it_be(:public_maintainer_group) { create(:group, name: 'a public maintainer', path: 'a-public-maintainer') }
let_it_be(:public_owner_group) { create(:group, name: 'a public owner', path: 'a-public-owner') }
let(:group_arguments) { {} }
let(:current_user) { user }
......@@ -29,6 +30,7 @@
private_maintainer_group.add_maintainer(user)
public_developer_group.add_developer(user)
public_maintainer_group.add_maintainer(user)
public_owner_group.add_owner(user)
end
subject { graphql_data.dig('currentUser', 'groups', 'nodes') }
......@@ -52,6 +54,7 @@
is_expected.to match(
expected_group_hash(
public_maintainer_group,
public_owner_group,
private_maintainer_group,
public_developer_group,
guest_group
......@@ -66,6 +69,7 @@
is_expected.to match(
expected_group_hash(
public_maintainer_group,
public_owner_group,
private_maintainer_group,
public_developer_group
)
......@@ -86,6 +90,32 @@
end
end
context 'when permission_scope is TRANSFER_PROJECTS' do
let(:group_arguments) { { permission_scope: :TRANSFER_PROJECTS } }
specify do
is_expected.to match(
expected_group_hash(
public_maintainer_group,
public_owner_group,
private_maintainer_group
)
)
end
context 'when search is provided' do
let(:group_arguments) { { permission_scope: :TRANSFER_PROJECTS, search: 'owner' } }
specify do
is_expected.to match(
expected_group_hash(
public_owner_group
)
)
end
end
end
context 'when search is provided' do
let(:group_arguments) { { search: 'maintainer' } }
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册