Commit 8a570944 authored by Stan Hu's avatar Stan Hu

Fix Error 500 when referencing issue with project in pending delete

Closes #31215
parent a9da3743
...@@ -199,7 +199,7 @@ class Issue < ActiveRecord::Base ...@@ -199,7 +199,7 @@ class Issue < ActiveRecord::Base
# Returns `true` if the current issue can be viewed by either a logged in User # Returns `true` if the current issue can be viewed by either a logged in User
# or an anonymous user. # or an anonymous user.
def visible_to_user?(user = nil) def visible_to_user?(user = nil)
return false unless project.feature_available?(:issues, user) return false unless project && project.feature_available?(:issues, user)
user ? readable_by?(user) : publicly_visible? user ? readable_by?(user) : publicly_visible?
end end
......
...@@ -42,6 +42,19 @@ describe Banzai::Redactor do ...@@ -42,6 +42,19 @@ describe Banzai::Redactor do
end end
end end
context 'when project is in pending delete' do
it 'redacts an issue attached' do
project.pending_delete = true
project.save
issue = create(:issue, project: project)
redactor = described_class.new(project, user)
doc = Nokogiri::HTML.fragment("<a class='gfm' data-reference-type='issue' data-project=\"#{project.id}\" data-issue=\"#{issue.id}\">foo</a>")
redactor.redact([doc])
expect(doc.to_html).to eq('foo')
end
end
context 'when reference visible to user' do context 'when reference visible to user' do
it 'does not redact an array of documents' do it 'does not redact an array of documents' do
doc1_html = '<a class="gfm" data-reference-type="issue">foo</a>' doc1_html = '<a class="gfm" data-reference-type="issue">foo</a>'
......
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