summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2017-04-20 23:45:09 -0700
committerStan Hu <stanhu@gmail.com>2017-04-20 23:48:20 -0700
commit8a570944a9d0f0e4cd607e5d2dfe2eac4bd83f47 (patch)
treea50ac76dd0140d4072e3b04062998f4e928dad2a
parenta9da37434af6d44c5f851affd4bd69b370760e8e (diff)
downloadgitlab-ce-8a570944a9d0f0e4cd607e5d2dfe2eac4bd83f47.tar.gz
Fix Error 500 when referencing issue with project in pending deletesh-fix-issue-31215
Closes #31215
-rw-r--r--app/models/issue.rb2
-rw-r--r--spec/lib/banzai/redactor_spec.rb13
2 files changed, 14 insertions, 1 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb
index d39ae3a6c92..305fc01f041 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -199,7 +199,7 @@ class Issue < ActiveRecord::Base
# Returns `true` if the current issue can be viewed by either a logged in User
# or an anonymous user.
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?
end
diff --git a/spec/lib/banzai/redactor_spec.rb b/spec/lib/banzai/redactor_spec.rb
index 6d2c141e18b..334b74fab3c 100644
--- a/spec/lib/banzai/redactor_spec.rb
+++ b/spec/lib/banzai/redactor_spec.rb
@@ -42,6 +42,19 @@ describe Banzai::Redactor do
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
it 'does not redact an array of documents' do
doc1_html = '<a class="gfm" data-reference-type="issue">foo</a>'