Commit 459318fe authored by Eugenia Grieff's avatar Eugenia Grieff

Fix specs that check admin_epic permissions

- Remove extra checks for permissions
- Recue EpicAssignmentError
parent f97684de
......@@ -17,7 +17,7 @@ module EE
def resolve(**args)
super
rescue ::Gitlab::Access::AccessDeniedError
rescue ::Gitlab::Access::AccessDeniedError, ::Issues::BaseService::EpicAssignmentError
raise_resource_not_available_error!
end
end
......
......@@ -36,7 +36,7 @@ module EpicIssues
def linkable_issuables(issues)
@linkable_issues ||= begin
issues.select do |issue|
issue.supports_epic? &&
supports_epics?(issue) &&
can?(current_user, :admin_issue, issue) &&
issuable_group_descendants.include?(issue.project.group) &&
!previous_related_issuables.include?(issue)
......@@ -51,5 +51,9 @@ module EpicIssues
def issuable_group_descendants
@descendants ||= issuable.group.self_and_descendants
end
def supports_epics?(issue)
issue.supports_epic? && issue.project.group&.feature_available?(:epics)
end
end
end
......@@ -32,27 +32,12 @@ RSpec.describe Mutations::Boards::Issues::IssueMoveList do
end
describe '#resolve' do
context 'when user has access to the epic' do
before do
group.add_developer(user)
end
it 'moves and repositions issue' do
subject
expect(issue1.reload.epic).to eq(epic)
expect(issue1.relative_position).to be < existing_issue2.relative_position
expect(issue1.relative_position).to be > existing_issue1.relative_position
end
end
it 'moves and repositions issue and sets epic' do
subject
context 'when user does not have access to the epic' do
it 'does not update issue' do
subject
expect(issue1.reload.epic).to be_nil
expect(issue1.relative_position).to eq(3)
end
expect(issue1.reload.epic).to eq(epic)
expect(issue1.relative_position).to be < existing_issue2.relative_position
expect(issue1.relative_position).to be > existing_issue1.relative_position
end
context 'when user cannot be assigned to issue' do
......
......@@ -44,8 +44,6 @@ RSpec.describe Mutations::Issues::Update do
context 'when epics feature is disabled' do
it 'raises an error' do
group.add_developer(user)
expect { subject }.to raise_error(::Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
......@@ -90,6 +88,14 @@ RSpec.describe Mutations::Issues::Update do
expect(mutated_issue.epic).to be_nil
end
end
context 'the epic belongs to an external group' do
let(:epic) { create(:epic) }
it 'does not set the epic' do
expect { subject }.to raise_error(Gitlab::Graphql::Errors::ResourceNotAvailable)
end
end
end
end
end
......
......@@ -33,11 +33,11 @@ RSpec.describe 'Reposition and move issue within board lists' do
before do
stub_licensed_features(epics: true)
project.add_maintainer(user)
end
context 'when user can admin epic' do
context 'when user can admin issue' do
before do
project.add_maintainer(user)
group.add_maintainer(user)
end
......@@ -77,17 +77,6 @@ RSpec.describe 'Reposition and move issue within board lists' do
end
end
context 'when user can not admin epic' do
it 'fails with error' do
post_graphql_mutation(mutation(params), current_user: user)
mutation_response = graphql_mutation_response(:issue_move_list)
expect(mutation_response['errors']).to eq(['You are not allowed to move the issue'])
expect(mutation_response['issue']['epic']).to eq(nil)
expect(mutation_response['issue']['relativePosition']).to eq(3)
end
end
def mutation(additional_params = {})
graphql_mutation(mutation_name, issue_move_params.merge(additional_params),
<<-QL.strip_heredoc
......
......@@ -23,123 +23,116 @@ RSpec.describe 'Update of an existing issue' do
before do
stub_licensed_features(issuable_health_status: true)
project.add_developer(current_user)
end
it 'updates the issue' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(mutated_issue).to include(input)
end
context 'setting epic' do
let(:epic) { create(:epic, group: group) }
let(:input) do
{ iid: issue.iid.to_s, epic_id: global_id_of(epic) }
end
context 'when user can update issue' do
before do
stub_licensed_features(epics: true)
group.add_developer(current_user)
project.add_developer(current_user)
end
it 'sets the epic' do
it 'updates the issue' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(graphql_errors).to be_blank
expect(mutated_issue).to include(
'epic' => include('id' => global_id_of(epic))
)
expect(mutated_issue).to include(input)
end
context 'the epic is not readable to the current user' do
let(:epic) { create(:epic) }
it 'does not set the epic' do
post_graphql_mutation(mutation, current_user: current_user)
context 'setting epic' do
let(:epic) { create(:epic, group: group) }
expect(response).to have_gitlab_http_status(:success)
expect(graphql_errors).not_to be_blank
end
end
context 'the epic is not an epic' do
let(:epic) { create(:user) }
it 'does not set the epic' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(graphql_errors).not_to be_blank
let(:input) do
{ iid: issue.iid.to_s, epic_id: global_id_of(epic) }
end
end
# TODO: remove when the global-ID compatibility layer is removed,
# at which point this error becomes unreachable because the query will
# be rejected as ill-typed.
context 'the epic is not an epic, using the ID type' do
let(:mutation) do
query = <<~GQL
mutation($epic: ID!, $path: ID!, $iid: String!) {
updateIssue(input: { epicId: $epic, projectPath: $path, iid: $iid }) {
errors
}
}
GQL
::GraphqlHelpers::MutationDefinition.new(query, {
epic: global_id_of(create(:user)),
iid: issue.iid.to_s,
path: project.full_path
})
before do
stub_licensed_features(epics: true)
end
it 'does not set the epic' do
it 'sets the epic' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(graphql_errors).to contain_exactly(
a_hash_including('message' => /No object found/)
expect(graphql_errors).to be_blank
expect(mutated_issue).to include(
'epic' => include('id' => global_id_of(epic))
)
end
end
end
context 'removing epic' do
let(:epic) { create(:epic, group: group) }
let(:input) do
{ iid: issue.iid.to_s, epic_id: nil }
end
context 'the epic is not an epic' do
let(:epic) { create(:user) }
before do
stub_licensed_features(epics: true)
group.add_developer(current_user)
issue.update!(epic: epic)
end
it 'does not set the epic' do
post_graphql_mutation(mutation, current_user: current_user)
it 'removes the epic' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(graphql_errors).not_to be_blank
end
end
expect(response).to have_gitlab_http_status(:success)
expect(graphql_errors).to be_blank
expect(mutated_issue).to include('epic' => be_nil)
# TODO: remove when the global-ID compatibility layer is removed,
# at which point this error becomes unreachable because the query will
# be rejected as ill-typed.
context 'the epic is not an epic, using the ID type' do
let(:mutation) do
query = <<~GQL
mutation($epic: ID!, $path: ID!, $iid: String!) {
updateIssue(input: { epicId: $epic, projectPath: $path, iid: $iid }) {
errors
}
}
GQL
::GraphqlHelpers::MutationDefinition.new(query, {
epic: global_id_of(create(:user)),
iid: issue.iid.to_s,
path: project.full_path
})
end
it 'does not set the epic' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(graphql_errors).to contain_exactly(
a_hash_including('message' => /No object found/)
)
end
end
end
context 'the epic argument is not provided' do
context 'removing epic' do
let(:epic) { create(:epic, group: group) }
let(:input) do
{ iid: issue.iid.to_s, weight: 1 }
{ iid: issue.iid.to_s, epic_id: nil }
end
before do
stub_licensed_features(epics: true)
group.add_developer(current_user)
issue.update!(epic: epic)
end
it 'does not remove the epic' do
it 'removes the epic' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(graphql_errors).to be_blank
expect(mutated_issue).to include('epic' => be_present)
expect(mutated_issue).to include('epic' => be_nil)
end
context 'the epic argument is not provided' do
let(:input) do
{ iid: issue.iid.to_s, weight: 1 }
end
it 'does not remove the epic' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(graphql_errors).to be_blank
expect(mutated_issue).to include('epic' => be_present)
end
end
end
end
......
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