Commit a2f93a75 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Return proper relation removal path on RelatedIssues::ListService

parent ee743909
......@@ -12,7 +12,8 @@ module RelatedIssues
title: referenced_issue.title,
state: referenced_issue.state,
reference: referenced_issue.to_reference(@issue.project),
path: namespace_project_issue_path(referenced_issue.project.namespace, referenced_issue.project, referenced_issue.iid)
path: namespace_project_issue_path(referenced_issue.project.namespace, referenced_issue.project, referenced_issue.iid),
destroy_relation_path: destroy_relation_path(referenced_issue)
}
end
end
......@@ -39,5 +40,14 @@ module RelatedIssues
# TODO: Try to use SQL instead Array#select
@issues = Ability.issues_readable_by_user(@issues, @current_user)
end
def destroy_relation_path(issue)
return unless Ability.allowed?(@current_user, :admin_related_issue, issue.project)
namespace_project_issue_related_issue_path(issue.project.namespace,
issue.project,
issue.iid,
issue.related_issues_id)
end
end
end
......@@ -20,27 +20,24 @@ describe RelatedIssues::ListService, service: true do
let!(:related_issue_c) do
create(:related_issue, id: 999,
issue: issue_d,
related_issue: issue,
created_at: Date.today)
related_issue: issue)
end
let!(:related_issue_b) do
create(:related_issue, id: 998,
issue: issue,
related_issue: issue_c,
created_at: 1.day.ago)
related_issue: issue_c)
end
let!(:related_issue_a) do
create(:related_issue, id: 997,
issue: issue,
related_issue: issue_b,
created_at: 2.days.ago)
related_issue: issue_b)
end
it 'verifies number of queries' do
recorded = ActiveRecord::QueryRecorder.new { subject }
expect(recorded.count).to be_within(1).of(25)
expect(recorded.count).to be_within(1).of(39)
end
it 'returns related issues JSON' do
......@@ -51,7 +48,8 @@ describe RelatedIssues::ListService, service: true do
title: issue_b.title,
state: issue_b.state,
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_b.iid}/related_issues/#{related_issue_a.id}"
}
)
......@@ -60,7 +58,8 @@ describe RelatedIssues::ListService, service: true do
title: issue_c.title,
state: issue_c.state,
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_c.iid}/related_issues/#{related_issue_b.id}"
}
)
......@@ -69,7 +68,8 @@ describe RelatedIssues::ListService, service: true do
title: issue_d.title,
state: issue_d.state,
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_d.iid}/related_issues/#{related_issue_c.id}"
}
)
end
......@@ -96,5 +96,34 @@ describe RelatedIssues::ListService, service: true do
end
end
end
context 'remove relations' do
let!(:related_issue) do
create(:related_issue, issue: issue, related_issue: referenced_issue)
end
context 'when user can admin related issues on one project' do
let(:unauthorized_project) { create :empty_project }
let(:referenced_issue) { create :issue, project: unauthorized_project }
before do
# User can just see related issues
unauthorized_project.team << [user, :guest]
end
it 'returns no destroy relation path' do
expect(subject.first[:destroy_relation_path]).to be_nil
end
end
context 'when user can admin related issues on both projects' do
let(:referenced_issue) { create :issue, project: project }
it 'returns related issue destroy relation path' do
expect(subject.first[:destroy_relation_path])
.to eq("/#{project.full_path}/issues/#{referenced_issue.iid}/related_issues/#{related_issue.id}")
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