Skip to content
Snippets Groups Projects
Commit f414a6b2 authored by Eugenia Grieff's avatar Eugenia Grieff :two:
Browse files

Remove hierarchy validation for promote_to quick action

This validation is already present at the service level where errors
are returned correctly for work items quick actions

Changelog: fixed
parent ea3e084c
No related branches found
No related tags found
1 merge request!128393Remove hierarchy validation for promote_to quick action
......@@ -54,18 +54,9 @@ def validate_type(type)
def validate_promote_to(type)
return error_msg(:not_found, action: 'promote') unless type && supports_promote_to?(type.name)
return if current_user.can?(:"create_#{type.base_type}", quick_action_target)
unless current_user.can?(:"create_#{type.base_type}", quick_action_target)
return error_msg(:forbidden, action: 'promote')
end
validate_hierarchy
end
def validate_hierarchy
return unless current_type.task? && quick_action_target.parent_link
error_msg(:hierarchy, action: 'promote')
error_msg(:forbidden, action: 'promote')
end
def current_type
......@@ -88,8 +79,7 @@ def error_msg(reason, action: 'convert')
message = {
not_found: 'Provided type is not supported',
same_type: 'Types are the same',
forbidden: 'You have insufficient permissions',
hierarchy: 'A task cannot be promoted when a parent issue is present'
forbidden: 'You have insufficient permissions'
}.freeze
format(_("Failed to %{action} this work item: %{reason}."), { action: action, reason: message[reason] })
......
......@@ -163,63 +163,77 @@
noteable.update!(work_item_type: task_type)
end
it 'updates type' do
expect do
post_graphql_mutation(mutation, current_user: current_user)
noteable.reload
end.to change { noteable.work_item_type.base_type }.from('task').to('issue')
expect(response).to have_gitlab_http_status(:success)
end
context 'when update service returns errors' do
let_it_be(:issue) { create(:work_item, :issue, project: project) }
before do
create(:parent_link, work_item: noteable, work_item_parent: issue)
end
it 'mutation response include the errors' do
shared_examples 'a quick command that changes type' do
it 'updates type' do
expect do
post_graphql_mutation(mutation, current_user: current_user)
noteable.reload
end.not_to change { noteable.work_item_type.base_type }
end.to change { noteable.work_item_type.base_type }.from('task').to('issue')
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['errors'])
.to include('Validation Work item type cannot be changed to issue when linked to a parent issue.')
end
end
context 'when quick command for unsupported widget is present' do
let(:body) { "\n/type Issue\n/assign @#{assignee.username}" }
context 'when update service returns errors' do
let_it_be(:issue) { create(:work_item, :issue, project: project) }
before do
WorkItems::Type.default_by_type(:issue).widget_definitions
.find_by_widget_type(:assignees).update!(disabled: true)
before do
create(:parent_link, work_item: noteable, work_item_parent: issue)
end
it 'mutation response include the errors' do
expect do
post_graphql_mutation(mutation, current_user: current_user)
noteable.reload
end.not_to change { noteable.work_item_type.base_type }
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['errors'])
.to include('Validation Work item type cannot be changed to issue when linked to a parent issue.')
end
end
it 'updates only type' do
expect do
post_graphql_mutation(mutation, current_user: current_user)
noteable.reload
end.to change { noteable.work_item_type.base_type }.from('task').to('issue')
.and change { noteable.assignees }.to([])
context 'when quick command for unsupported widget is present' do
let(:body) { "\n/type Issue\n/assign @#{assignee.username}" }
before do
WorkItems::Type.default_by_type(:issue).widget_definitions
.find_by_widget_type(:assignees).update!(disabled: true)
end
it 'updates only type' do
expect do
post_graphql_mutation(mutation, current_user: current_user)
noteable.reload
end.to change { noteable.work_item_type.base_type }.from('task').to('issue')
.and change { noteable.assignees }.to([])
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['errors'])
.to include("Commands only Type changed successfully. Assigned @#{assignee.username}.")
end
end
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['errors'])
.to include("Commands only Type changed successfully. Assigned @#{assignee.username}.")
context 'when the type name is upper case' do
let(:body) { "Updating type.\n/type Issue" }
it 'changes type to issue' do
expect do
post_graphql_mutation(mutation, current_user: current_user)
noteable.reload
end.to change { noteable.work_item_type.base_type }.from('task').to('issue')
end
end
end
context 'when the type name is upper case' do
let(:body) { "Updating type.\n/type Issue" }
context 'with /type quick command' do
let(:body) { "Updating type.\n/type issue" }
it 'changes type to issue' do
expect do
post_graphql_mutation(mutation, current_user: current_user)
noteable.reload
end.to change { noteable.work_item_type.base_type }.from('task').to('issue')
end
it_behaves_like 'a quick command that changes type'
end
context 'with /promote_to quick command' do
let(:body) { "Updating type.\n/promote_to issue" }
it_behaves_like 'a quick command that changes type'
end
end
......@@ -78,16 +78,6 @@
end
it_behaves_like 'action with validation errors'
context 'when task has a parent' do
let_it_be(:parent) { create(:work_item, :issue, project: project) }
before do
create(:parent_link, work_item: task, work_item_parent: parent)
end
it_behaves_like 'quick command error', 'A task cannot be promoted when a parent issue is present', 'promote'
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment