Commit 6205e9d5 authored by Jarka Kadlecová's avatar Jarka Kadlecová

use relation_path instead of destroy_relation_path

parent 05eacd01
...@@ -21,9 +21,5 @@ module EpicIssues ...@@ -21,9 +21,5 @@ module EpicIssues
def reference(issue) def reference(issue)
issue.to_reference(full: true) issue.to_reference(full: true)
end end
def to_hash(issue)
super.merge(relation_path: relation_path(issue))
end
end end
end end
...@@ -26,7 +26,8 @@ module IssuableLinks ...@@ -26,7 +26,8 @@ module IssuableLinks
title: issue.title, title: issue.title,
state: issue.state, state: issue.state,
reference: reference(issue), reference: reference(issue),
path: project_issue_path(issue.project, issue.iid) path: project_issue_path(issue.project, issue.iid),
relation_path: relation_path(issue)
} }
end end
end end
......
module IssueLinks module IssueLinks
class ListService < IssuableLinks::ListService class ListService < IssuableLinks::ListService
include Gitlab::Utils::StrongMemoize
private private
def issues def issues
issuable.related_issues(current_user, preload: { project: :namespace }) issuable.related_issues(current_user, preload: { project: :namespace })
end end
def destroy_relation_path(issue) def relation_path(issue)
current_project = issuable.project
# Make sure the user can admin both the current issue AND the # Make sure the user can admin both the current issue AND the
# referenced issue projects in order to return the removal link. # referenced issue projects in order to return the removal link.
if can_destroy_issue_link_on_current_project?(current_project) && can_destroy_issue_link?(issue.project) if can_admin_issue_link_on_current_project? && can_admin_issue_link?(issue.project)
project_issue_link_path(current_project, issuable.iid, issue.issue_link_id) project_issue_link_path(current_project, issuable.iid, issue.issue_link_id)
end end
end end
def can_destroy_issue_link_on_current_project?(current_project) def can_admin_issue_link_on_current_project?
return @can_destroy_on_current_project if defined?(@can_destroy_on_current_project) strong_memoize(:can_admin_on_current_project) do
can_admin_issue_link?(current_project)
@can_destroy_on_current_project = can_destroy_issue_link?(current_project) end
end end
def can_destroy_issue_link?(project) def can_admin_issue_link?(project)
Ability.allowed?(current_user, :admin_issue_link, project) Ability.allowed?(current_user, :admin_issue_link, project)
end end
def to_hash(issue) def current_project
super.merge(destroy_relation_path: destroy_relation_path(issue)) issuable.project
end end
end end
end end
...@@ -57,21 +57,21 @@ describe IssueLinks::ListService do ...@@ -57,21 +57,21 @@ describe IssueLinks::ListService do
state: issue_b.state, state: issue_b.state,
reference: issue_b.to_reference(project), reference: issue_b.to_reference(project),
path: "/#{project.full_path}/issues/#{issue_b.iid}", path: "/#{project.full_path}/issues/#{issue_b.iid}",
destroy_relation_path: "/#{project.full_path}/issues/#{issue.iid}/links/#{issue_link_a.id}")) relation_path: "/#{project.full_path}/issues/#{issue.iid}/links/#{issue_link_a.id}"))
expect(subject).to include(include(id: issue_c.id, expect(subject).to include(include(id: issue_c.id,
title: issue_c.title, title: issue_c.title,
state: issue_c.state, state: issue_c.state,
reference: issue_c.to_reference(project), reference: issue_c.to_reference(project),
path: "/#{project.full_path}/issues/#{issue_c.iid}", path: "/#{project.full_path}/issues/#{issue_c.iid}",
destroy_relation_path: "/#{project.full_path}/issues/#{issue.iid}/links/#{issue_link_b.id}")) relation_path: "/#{project.full_path}/issues/#{issue.iid}/links/#{issue_link_b.id}"))
expect(subject).to include(include(id: issue_d.id, expect(subject).to include(include(id: issue_d.id,
title: issue_d.title, title: issue_d.title,
state: issue_d.state, state: issue_d.state,
reference: issue_d.to_reference(project), reference: issue_d.to_reference(project),
path: "/#{project.full_path}/issues/#{issue_d.iid}", path: "/#{project.full_path}/issues/#{issue_d.iid}",
destroy_relation_path: "/#{project.full_path}/issues/#{issue.iid}/links/#{issue_link_c.id}")) relation_path: "/#{project.full_path}/issues/#{issue.iid}/links/#{issue_link_c.id}"))
end end
end end
...@@ -164,7 +164,7 @@ describe IssueLinks::ListService do ...@@ -164,7 +164,7 @@ describe IssueLinks::ListService do
it 'returns no destroy relation path' do it 'returns no destroy relation path' do
target_project.add_developer(user) target_project.add_developer(user)
expect(subject.first[:destroy_relation_path]).to be_nil expect(subject.first[:relation_path]).to be_nil
end end
end end
...@@ -176,7 +176,7 @@ describe IssueLinks::ListService do ...@@ -176,7 +176,7 @@ describe IssueLinks::ListService do
it 'returns no destroy relation path' do it 'returns no destroy relation path' do
target_project.add_guest(user) target_project.add_guest(user)
expect(subject.first[:destroy_relation_path]).to be_nil expect(subject.first[:relation_path]).to be_nil
end end
end end
...@@ -184,7 +184,7 @@ describe IssueLinks::ListService do ...@@ -184,7 +184,7 @@ describe IssueLinks::ListService do
let(:referenced_issue) { create :issue, project: project } let(:referenced_issue) { create :issue, project: project }
it 'returns related issue destroy relation path' do it 'returns related issue destroy relation path' do
expect(subject.first[:destroy_relation_path]) expect(subject.first[:relation_path])
.to eq("/#{project.full_path}/issues/#{issue.iid}/links/#{issue_link.id}") .to eq("/#{project.full_path}/issues/#{issue.iid}/links/#{issue_link.id}")
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