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