Commit 6e152662 authored by Eugenia Grieff's avatar Eugenia Grieff

Fix #can_assign_epic? method

- Fix specs
parent 459318fe
......@@ -150,7 +150,7 @@ module EE
end
def can_assign_epic?(user)
user&.can?(:admin_epic, project.group)
project.group&.feature_available?(:epics) && user&.can?(:admin_issue, project)
end
def can_be_promoted_to_epic?(user, group = nil)
......
......@@ -48,15 +48,7 @@ module EE
def epic_param(issue)
epic_id = params.delete(:epic_id)
epic = params.delete(:epic) || find_epic(issue, epic_id)
return unless epic
unless can?(current_user, :admin_issue, issue)
raise ::Gitlab::Access::AccessDeniedError
end
epic
params.delete(:epic) || find_epic(issue, epic_id)
end
def find_epic(issue, epic_id)
......
......@@ -36,14 +36,18 @@ module EpicIssues
def linkable_issuables(issues)
@linkable_issues ||= begin
issues.select do |issue|
supports_epics?(issue) &&
can?(current_user, :admin_issue, issue) &&
issuable_group_descendants.include?(issue.project.group) &&
!previous_related_issuables.include?(issue)
linkable_issue?(issue)
end
end
end
def linkable_issue?(issue)
issue.supports_epic? &&
issue.project.group&.feature_available?(:epics) &&
issuable_group_descendants.include?(issue.project.group) &&
!previous_related_issuables.include?(issue)
end
def previous_related_issuables
@related_issues ||= issuable.issues.to_a
end
......@@ -51,9 +55,5 @@ 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
......@@ -816,15 +816,13 @@ RSpec.describe Issue do
it 'returns false' do
project.add_developer(user)
expect(subject).to be_falsey
expect(subject).to be_truthy
end
end
context 'when a user is a group member' do
it 'returns true' do
group.add_developer(user)
expect(subject).to be_truthy
context 'when a user is not a group member' do
it 'returns false' do
expect(subject).to be_falsey
end
end
end
......
......@@ -89,6 +89,10 @@ RSpec.describe EpicIssues::CreateService do
context 'when epics feature is disabled' do
subject { assign_issue([valid_reference]) }
before do
group.add_developer(user)
end
include_examples 'returns an error'
end
......@@ -156,7 +160,7 @@ RSpec.describe EpicIssues::CreateService do
# and we insert 5 issues instead of 1 which we do for control count
expect { described_class.new(epic, user, params).execute }
.not_to exceed_query_limit(control_count)
.with_threshold(29)
.with_threshold(30)
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