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,28 +32,13 @@ 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
it 'moves and repositions issue and sets epic' 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
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
end
context 'when user cannot be assigned to issue' do
before 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,6 +23,10 @@ RSpec.describe 'Update of an existing issue' do
before do
stub_licensed_features(issuable_health_status: true)
end
context 'when user can update issue' do
before do
project.add_developer(current_user)
end
......@@ -42,7 +46,6 @@ RSpec.describe 'Update of an existing issue' do
before do
stub_licensed_features(epics: true)
group.add_developer(current_user)
end
it 'sets the epic' do
......@@ -55,17 +58,6 @@ RSpec.describe 'Update of an existing issue' do
)
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)
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) }
......@@ -143,4 +135,5 @@ RSpec.describe 'Update of an existing issue' do
end
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