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 ...@@ -12,7 +12,8 @@ module RelatedIssues
title: referenced_issue.title, title: referenced_issue.title,
state: referenced_issue.state, state: referenced_issue.state,
reference: referenced_issue.to_reference(@issue.project), 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
end end
...@@ -39,5 +40,14 @@ module RelatedIssues ...@@ -39,5 +40,14 @@ module RelatedIssues
# TODO: Try to use SQL instead Array#select # TODO: Try to use SQL instead Array#select
@issues = Ability.issues_readable_by_user(@issues, @current_user) @issues = Ability.issues_readable_by_user(@issues, @current_user)
end 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
end end
...@@ -20,27 +20,24 @@ describe RelatedIssues::ListService, service: true do ...@@ -20,27 +20,24 @@ describe RelatedIssues::ListService, service: true do
let!(:related_issue_c) do let!(:related_issue_c) do
create(:related_issue, id: 999, create(:related_issue, id: 999,
issue: issue_d, issue: issue_d,
related_issue: issue, related_issue: issue)
created_at: Date.today)
end end
let!(:related_issue_b) do let!(:related_issue_b) do
create(:related_issue, id: 998, create(:related_issue, id: 998,
issue: issue, issue: issue,
related_issue: issue_c, related_issue: issue_c)
created_at: 1.day.ago)
end end
let!(:related_issue_a) do let!(:related_issue_a) do
create(:related_issue, id: 997, create(:related_issue, id: 997,
issue: issue, issue: issue,
related_issue: issue_b, related_issue: issue_b)
created_at: 2.days.ago)
end end
it 'verifies number of queries' do it 'verifies number of queries' do
recorded = ActiveRecord::QueryRecorder.new { subject } recorded = ActiveRecord::QueryRecorder.new { subject }
expect(recorded.count).to be_within(1).of(25) expect(recorded.count).to be_within(1).of(39)
end end
it 'returns related issues JSON' do it 'returns related issues JSON' do
...@@ -51,7 +48,8 @@ describe RelatedIssues::ListService, service: true do ...@@ -51,7 +48,8 @@ describe RelatedIssues::ListService, service: true do
title: issue_b.title, title: issue_b.title,
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_b.iid}/related_issues/#{related_issue_a.id}"
} }
) )
...@@ -60,7 +58,8 @@ describe RelatedIssues::ListService, service: true do ...@@ -60,7 +58,8 @@ describe RelatedIssues::ListService, service: true do
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_c.iid}/related_issues/#{related_issue_b.id}"
} }
) )
...@@ -69,7 +68,8 @@ describe RelatedIssues::ListService, service: true do ...@@ -69,7 +68,8 @@ describe RelatedIssues::ListService, service: true do
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_d.iid}/related_issues/#{related_issue_c.id}"
} }
) )
end end
...@@ -96,5 +96,34 @@ describe RelatedIssues::ListService, service: true do ...@@ -96,5 +96,34 @@ describe RelatedIssues::ListService, service: true do
end end
end 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
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