summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-04-19 15:51:55 +0000
committerSean McGivern <sean@mcgivern.me.uk>2017-04-19 15:51:55 +0000
commitd8ac7575b9990bc5c0a857e6742936f2f3bee877 (patch)
treef10aaed503c9be9207ca558f9f3d69288937a3e0
parent046c0e1e35d546463dcd9512d08fd692fc134afb (diff)
parentde71a4659482aeb38da5e883eeff12b24056871a (diff)
downloadgitlab-ce-d8ac7575b9990bc5c0a857e6742936f2f3bee877.tar.gz
Merge branch 'issuable-state-only-notes-and-description' into 'master'
Display issuable state only in notes and issuable description Closes #30964 See merge request !10789
-rw-r--r--app/models/concerns/issuable.rb2
-rw-r--r--app/models/note.rb2
-rw-r--r--lib/banzai/filter/issuable_state_filter.rb2
-rw-r--r--spec/lib/banzai/filter/issuable_state_filter_spec.rb32
4 files changed, 25 insertions, 13 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb
index 3d2258d5e3e..26dbf4d9570 100644
--- a/app/models/concerns/issuable.rb
+++ b/app/models/concerns/issuable.rb
@@ -23,7 +23,7 @@ module Issuable
included do
cache_markdown_field :title, pipeline: :single_line
- cache_markdown_field :description
+ cache_markdown_field :description, issuable_state_filter_enabled: true
belongs_to :author, class_name: "User"
belongs_to :assignee, class_name: "User"
diff --git a/app/models/note.rb b/app/models/note.rb
index 630d0adbece..e720bfba030 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -16,7 +16,7 @@ class Note < ActiveRecord::Base
ignore_column :original_discussion_id
- cache_markdown_field :note, pipeline: :note
+ cache_markdown_field :note, pipeline: :note, issuable_state_filter_enabled: true
# Attribute containing rendered and redacted Markdown as generated by
# Banzai::ObjectRenderer.
diff --git a/lib/banzai/filter/issuable_state_filter.rb b/lib/banzai/filter/issuable_state_filter.rb
index 0b2b8bd7f4d..1a9d03beb51 100644
--- a/lib/banzai/filter/issuable_state_filter.rb
+++ b/lib/banzai/filter/issuable_state_filter.rb
@@ -9,6 +9,8 @@ module Banzai
VISIBLE_STATES = %w(closed merged).freeze
def call
+ return doc unless context[:issuable_state_filter_enabled]
+
extractor = Banzai::IssuableExtractor.new(project, current_user)
issuables = extractor.extract([doc])
diff --git a/spec/lib/banzai/filter/issuable_state_filter_spec.rb b/spec/lib/banzai/filter/issuable_state_filter_spec.rb
index 5cb98163746..0df259333e4 100644
--- a/spec/lib/banzai/filter/issuable_state_filter_spec.rb
+++ b/spec/lib/banzai/filter/issuable_state_filter_spec.rb
@@ -5,6 +5,7 @@ describe Banzai::Filter::IssuableStateFilter, lib: true do
include FilterSpecHelper
let(:user) { create(:user) }
+ let(:context) { { current_user: user, issuable_state_filter_enabled: true } }
def create_link(text, data)
link_to(text, '', class: 'gfm has-tooltip', data: data)
@@ -20,7 +21,7 @@ describe Banzai::Filter::IssuableStateFilter, lib: true do
it 'ignores non-issuable links' do
project = create(:empty_project, :public)
link = create_link('text', project: project, reference_type: 'issue')
- doc = filter(link, current_user: user)
+ doc = filter(link, context)
expect(doc.css('a').last.text).to eq('text')
end
@@ -28,7 +29,7 @@ describe Banzai::Filter::IssuableStateFilter, lib: true do
it 'ignores issuable links with empty content' do
issue = create(:issue, :closed)
link = create_link('', issue: issue.id, reference_type: 'issue')
- doc = filter(link, current_user: user)
+ doc = filter(link, context)
expect(doc.css('a').last.text).to eq('')
end
@@ -40,17 +41,26 @@ describe Banzai::Filter::IssuableStateFilter, lib: true do
issue: issue.id,
reference_type: 'issue'
)
- doc = filter(link, current_user: user)
+ doc = filter(link, context)
expect(doc.css('a').last.inner_html).
to eq('something <strong>else</strong> [closed]')
end
+ it 'does not append state when filter is not enabled' do
+ issue = create(:issue, :closed)
+ link = create_link('text', issue: issue.id, reference_type: 'issue')
+ context = { current_user: user }
+ doc = filter(link, context)
+
+ expect(doc.css('a').last.text).to eq('text')
+ end
+
context 'for issue references' do
it 'ignores open issue references' do
issue = create(:issue)
link = create_link('text', issue: issue.id, reference_type: 'issue')
- doc = filter(link, current_user: user)
+ doc = filter(link, context)
expect(doc.css('a').last.text).to eq('text')
end
@@ -58,7 +68,7 @@ describe Banzai::Filter::IssuableStateFilter, lib: true do
it 'ignores reopened issue references' do
reopened_issue = create(:issue, :reopened)
link = create_link('text', issue: reopened_issue.id, reference_type: 'issue')
- doc = filter(link, current_user: user)
+ doc = filter(link, context)
expect(doc.css('a').last.text).to eq('text')
end
@@ -66,7 +76,7 @@ describe Banzai::Filter::IssuableStateFilter, lib: true do
it 'appends [closed] to closed issue references' do
closed_issue = create(:issue, :closed)
link = create_link('text', issue: closed_issue.id, reference_type: 'issue')
- doc = filter(link, current_user: user)
+ doc = filter(link, context)
expect(doc.css('a').last.text).to eq('text [closed]')
end
@@ -76,7 +86,7 @@ describe Banzai::Filter::IssuableStateFilter, lib: true do
it 'ignores open merge request references' do
mr = create(:merge_request)
link = create_link('text', merge_request: mr.id, reference_type: 'merge_request')
- doc = filter(link, current_user: user)
+ doc = filter(link, context)
expect(doc.css('a').last.text).to eq('text')
end
@@ -84,7 +94,7 @@ describe Banzai::Filter::IssuableStateFilter, lib: true do
it 'ignores reopened merge request references' do
mr = create(:merge_request, :reopened)
link = create_link('text', merge_request: mr.id, reference_type: 'merge_request')
- doc = filter(link, current_user: user)
+ doc = filter(link, context)
expect(doc.css('a').last.text).to eq('text')
end
@@ -92,7 +102,7 @@ describe Banzai::Filter::IssuableStateFilter, lib: true do
it 'ignores locked merge request references' do
mr = create(:merge_request, :locked)
link = create_link('text', merge_request: mr.id, reference_type: 'merge_request')
- doc = filter(link, current_user: user)
+ doc = filter(link, context)
expect(doc.css('a').last.text).to eq('text')
end
@@ -100,7 +110,7 @@ describe Banzai::Filter::IssuableStateFilter, lib: true do
it 'appends [closed] to closed merge request references' do
mr = create(:merge_request, :closed)
link = create_link('text', merge_request: mr.id, reference_type: 'merge_request')
- doc = filter(link, current_user: user)
+ doc = filter(link, context)
expect(doc.css('a').last.text).to eq('text [closed]')
end
@@ -108,7 +118,7 @@ describe Banzai::Filter::IssuableStateFilter, lib: true do
it 'appends [merged] to merged merge request references' do
mr = create(:merge_request, :merged)
link = create_link('text', merge_request: mr.id, reference_type: 'merge_request')
- doc = filter(link, current_user: user)
+ doc = filter(link, context)
expect(doc.css('a').last.text).to eq('text [merged]')
end