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
def reference(issue)
issue.to_reference(full: true)
end
def to_hash(issue)
super.merge(relation_path: relation_path(issue))
end
end
end
......@@ -26,7 +26,8 @@ module IssuableLinks
title: issue.title,
state: issue.state,
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
......
module IssueLinks
class ListService < IssuableLinks::ListService
include Gitlab::Utils::StrongMemoize
private
def issues
issuable.related_issues(current_user, preload: { project: :namespace })
end
def destroy_relation_path(issue)
current_project = issuable.project
def relation_path(issue)
# Make sure the user can admin both the current issue AND the
# 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)
end
end
def can_destroy_issue_link_on_current_project?(current_project)
return @can_destroy_on_current_project if defined?(@can_destroy_on_current_project)
@can_destroy_on_current_project = can_destroy_issue_link?(current_project)
def can_admin_issue_link_on_current_project?
strong_memoize(:can_admin_on_current_project) do
can_admin_issue_link?(current_project)
end
end
def can_destroy_issue_link?(project)
def can_admin_issue_link?(project)
Ability.allowed?(current_user, :admin_issue_link, project)
end
def to_hash(issue)
super.merge(destroy_relation_path: destroy_relation_path(issue))
def current_project
issuable.project
end
end
end
......@@ -57,21 +57,21 @@ describe IssueLinks::ListService do
state: issue_b.state,
reference: issue_b.to_reference(project),
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,
title: issue_c.title,
state: issue_c.state,
reference: issue_c.to_reference(project),
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,
title: issue_d.title,
state: issue_d.state,
reference: issue_d.to_reference(project),
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
......@@ -164,7 +164,7 @@ describe IssueLinks::ListService do
it 'returns no destroy relation path' do
target_project.add_developer(user)
expect(subject.first[:destroy_relation_path]).to be_nil
expect(subject.first[:relation_path]).to be_nil
end
end
......@@ -176,7 +176,7 @@ describe IssueLinks::ListService do
it 'returns no destroy relation path' do
target_project.add_guest(user)
expect(subject.first[:destroy_relation_path]).to be_nil
expect(subject.first[:relation_path]).to be_nil
end
end
......@@ -184,7 +184,7 @@ describe IssueLinks::ListService do
let(:referenced_issue) { create :issue, project: project }
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}")
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