Commit 8045da79 authored by David O'Regan's avatar David O'Regan Committed by Luke Duncalfe

Remove wiki_front_matter FF

Remove the wiki_front_matter
Feature flag to add
the feature by default.

Changelog: added
parent be262eb5
...@@ -316,7 +316,6 @@ class WikiPage ...@@ -316,7 +316,6 @@ class WikiPage
end end
def update_front_matter(attrs) def update_front_matter(attrs)
return unless Gitlab::WikiPages::FrontMatterParser.enabled?(container)
return unless attrs.has_key?(:front_matter) return unless attrs.has_key?(:front_matter)
fm_yaml = serialize_front_matter(attrs[:front_matter]) fm_yaml = serialize_front_matter(attrs[:front_matter])
...@@ -327,7 +326,7 @@ class WikiPage ...@@ -327,7 +326,7 @@ class WikiPage
def parsed_content def parsed_content
strong_memoize(:parsed_content) do strong_memoize(:parsed_content) do
Gitlab::WikiPages::FrontMatterParser.new(raw_content, container).parse Gitlab::WikiPages::FrontMatterParser.new(raw_content).parse
end end
end end
......
---
name: wiki_front_matter
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27706
rollout_issue_url:
milestone: '12.10'
type: development
group: group::editor
default_enabled: false
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
module Gitlab module Gitlab
module WikiPages module WikiPages
class FrontMatterParser class FrontMatterParser
FEATURE_FLAG = :wiki_front_matter
# We limit the maximum length of text we are prepared to parse as YAML, to # We limit the maximum length of text we are prepared to parse as YAML, to
# avoid exploitations and attempts to consume memory and CPU. We allow for: # avoid exploitations and attempts to consume memory and CPU. We allow for:
# - a title line # - a title line
...@@ -30,18 +28,12 @@ module Gitlab ...@@ -30,18 +28,12 @@ module Gitlab
end end
# @param [String] wiki_content # @param [String] wiki_content
# @param [FeatureGate] feature_gate The scope for feature availability def initialize(wiki_content)
def initialize(wiki_content, feature_gate)
@wiki_content = wiki_content @wiki_content = wiki_content
@feature_gate = feature_gate
end
def self.enabled?(gate = nil)
Feature.enabled?(FEATURE_FLAG, gate)
end end
def parse def parse
return empty_result unless enabled? && wiki_content.present? return empty_result unless wiki_content.present?
return empty_result(block.error) unless block.valid? return empty_result(block.error) unless block.valid?
Result.new(front_matter: block.data, content: strip_front_matter_block) Result.new(front_matter: block.data, content: strip_front_matter_block)
...@@ -94,16 +86,12 @@ module Gitlab ...@@ -94,16 +86,12 @@ module Gitlab
private private
attr_reader :wiki_content, :feature_gate attr_reader :wiki_content
def empty_result(reason = nil, error = nil) def empty_result(reason = nil, error = nil)
Result.new(content: wiki_content, reason: reason, error: error) Result.new(content: wiki_content, reason: reason, error: error)
end end
def enabled?
self.class.enabled?(feature_gate)
end
def block def block
@block ||= parse_front_matter_block @block ||= parse_front_matter_block
end end
......
...@@ -3,11 +3,10 @@ ...@@ -3,11 +3,10 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Gitlab::WikiPages::FrontMatterParser do RSpec.describe Gitlab::WikiPages::FrontMatterParser do
subject(:parser) { described_class.new(raw_content, gate) } subject(:parser) { described_class.new(raw_content) }
let(:content) { 'This is the content' } let(:content) { 'This is the content' }
let(:end_divider) { '---' } let(:end_divider) { '---' }
let(:gate) { stub_feature_flag_gate('Gate') }
let(:with_front_matter) do let(:with_front_matter) do
<<~MD <<~MD
...@@ -62,32 +61,6 @@ RSpec.describe Gitlab::WikiPages::FrontMatterParser do ...@@ -62,32 +61,6 @@ RSpec.describe Gitlab::WikiPages::FrontMatterParser do
it { is_expected.to have_attributes(reason: :no_match) } it { is_expected.to have_attributes(reason: :no_match) }
end end
context 'the feature flag is disabled' do
let(:raw_content) { with_front_matter }
before do
stub_feature_flags(Gitlab::WikiPages::FrontMatterParser::FEATURE_FLAG => false)
end
it { is_expected.to have_attributes(front_matter: be_empty, content: raw_content) }
end
context 'the feature flag is enabled for the gated object' do
let(:raw_content) { with_front_matter }
before do
stub_feature_flags(Gitlab::WikiPages::FrontMatterParser::FEATURE_FLAG => gate)
end
it do
is_expected.to have_attributes(
front_matter: have_correct_front_matter,
content: content + "\n",
reason: be_nil
)
end
end
context 'the end divider is ...' do context 'the end divider is ...' do
let(:end_divider) { '...' } let(:end_divider) { '...' }
let(:raw_content) { with_front_matter } let(:raw_content) { with_front_matter }
......
...@@ -24,14 +24,6 @@ RSpec.describe WikiPage do ...@@ -24,14 +24,6 @@ RSpec.describe WikiPage do
container.wiki container.wiki
end end
def disable_front_matter
stub_feature_flags(Gitlab::WikiPages::FrontMatterParser::FEATURE_FLAG => false)
end
def enable_front_matter_for(thing)
stub_feature_flags(Gitlab::WikiPages::FrontMatterParser::FEATURE_FLAG => thing)
end
# Use for groups of tests that do not modify their `subject`. # Use for groups of tests that do not modify their `subject`.
# #
# include_context 'subject is persisted page', title: 'my title' # include_context 'subject is persisted page', title: 'my title'
...@@ -48,12 +40,6 @@ RSpec.describe WikiPage do ...@@ -48,12 +40,6 @@ RSpec.describe WikiPage do
it { expect(wiki_page).to have_attributes(front_matter: {}, content: content) } it { expect(wiki_page).to have_attributes(front_matter: {}, content: content) }
end end
shared_examples 'a page with front-matter' do
let(:front_matter) { { title: 'Foo', slugs: %w[slug_a slug_b] } }
it { expect(wiki_page.front_matter).to eq(front_matter) }
end
context 'the wiki page has front matter' do context 'the wiki page has front matter' do
let(:content) do let(:content) do
<<~MD <<~MD
...@@ -68,27 +54,13 @@ RSpec.describe WikiPage do ...@@ -68,27 +54,13 @@ RSpec.describe WikiPage do
MD MD
end end
it_behaves_like 'a page with front-matter' it 'has front-matter' do
expect(wiki_page.front_matter).to eq({ title: 'Foo', slugs: %w[slug_a slug_b] })
end
it 'strips the front matter from the content' do it 'strips the front matter from the content' do
expect(wiki_page.content.strip).to eq('My actual content') expect(wiki_page.content.strip).to eq('My actual content')
end end
context 'the feature flag is off' do
before do
disable_front_matter
end
it_behaves_like 'a page without front-matter'
context 'but enabled for the container' do
before do
enable_front_matter_for(container)
end
it_behaves_like 'a page with front-matter'
end
end
end end
context 'the wiki page does not have front matter' do context 'the wiki page does not have front matter' do
...@@ -471,29 +443,6 @@ RSpec.describe WikiPage do ...@@ -471,29 +443,6 @@ RSpec.describe WikiPage do
end end
end end
context 'the front-matter feature flag is not enabled' do
before do
disable_front_matter
end
it 'does not update the front-matter' do
content = subject.content
subject.update(front_matter: { slugs: ['x'] })
page = wiki.find_page(subject.title)
expect([subject, page]).to all(have_attributes(front_matter: be_empty, content: content))
end
context 'but it is enabled for the container' do
before do
enable_front_matter_for(container)
end
it_behaves_like 'able to update front-matter'
end
end
it 'updates the wiki-page front-matter and content together' do it 'updates the wiki-page front-matter and content together' do
content = 'totally new content' content = 'totally new content'
subject.update(content: content, front_matter: { slugs: ['x'] }) subject.update(content: content, front_matter: { slugs: ['x'] })
......
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