summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-04-21 15:20:18 +0000
committerDouwe Maan <douwe@gitlab.com>2017-04-21 15:20:18 +0000
commitd3a788da5b3871331b967e692d78a808a31f08fa (patch)
tree06937ea26e95cf3a79284b8cc7e55b14523d7904
parent38c52ab1f6fc216de6d240bffaa8c75dddcc6987 (diff)
parent67d380136c3fabd60dc86b7e6c0ce4f7c4800d36 (diff)
downloadgitlab-ce-d3a788da5b3871331b967e692d78a808a31f08fa.tar.gz
Merge branch 'sh-fix-issue-31215-2' into 'master'
Based on !10841 Fix Error 500 when referencing issue with project in pending delete Closes #31215 See merge request !10843
-rw-r--r--app/models/issue.rb2
-rw-r--r--changelogs/unreleased/sh-fix-issue-31215-2.yml4
-rw-r--r--spec/lib/banzai/redactor_spec.rb25
3 files changed, 30 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/changelogs/unreleased/sh-fix-issue-31215-2.yml b/changelogs/unreleased/sh-fix-issue-31215-2.yml
new file mode 100644
index 00000000000..eab5bb5d0ae
--- /dev/null
+++ b/changelogs/unreleased/sh-fix-issue-31215-2.yml
@@ -0,0 +1,4 @@
+---
+title: Fix error when an issue reference has a pending deleting project
+merge_request: 10843
+author:
diff --git a/spec/lib/banzai/redactor_spec.rb b/spec/lib/banzai/redactor_spec.rb
index 6d2c141e18b..e6f2963193c 100644
--- a/spec/lib/banzai/redactor_spec.rb
+++ b/spec/lib/banzai/redactor_spec.rb
@@ -42,6 +42,31 @@ describe Banzai::Redactor do
end
end
+ context 'when project is in pending delete' do
+ let!(:issue) { create(:issue, project: project) }
+ let(:redactor) { described_class.new(project, user) }
+
+ before do
+ project.update(pending_delete: true)
+ end
+
+ it 'redacts an issue attached' do
+ doc = Nokogiri::HTML.fragment("<a class='gfm' data-reference-type='issue' data-issue='#{issue.id}'>foo</a>")
+
+ redactor.redact([doc])
+
+ expect(doc.to_html).to eq('foo')
+ end
+
+ it 'redacts an external issue' do
+ doc = Nokogiri::HTML.fragment("<a class='gfm' data-reference-type='issue' data-external-issue='#{issue.id}' data-project='#{project.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>'