From 8045da7944102e54bb172a5ef3c5a8088459c360 Mon Sep 17 00:00:00 2001 From: David O'Regan <doregan@gitlab.com> Date: Sun, 13 Mar 2022 22:18:42 +0000 Subject: [PATCH] Remove wiki_front_matter FF Remove the wiki_front_matter Feature flag to add the feature by default. Changelog: added --- app/models/wiki_page.rb | 3 +- .../development/wiki_front_matter.yml | 8 --- lib/gitlab/wiki_pages/front_matter_parser.rb | 18 +----- .../wiki_pages/front_matter_parser_spec.rb | 29 +--------- spec/models/wiki_page_spec.rb | 57 +------------------ 5 files changed, 8 insertions(+), 107 deletions(-) delete mode 100644 config/feature_flags/development/wiki_front_matter.yml diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index de9497a2f404b..803b9781ac40e 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -316,7 +316,6 @@ def serialize_front_matter(hash) end def update_front_matter(attrs) - return unless Gitlab::WikiPages::FrontMatterParser.enabled?(container) return unless attrs.has_key?(:front_matter) fm_yaml = serialize_front_matter(attrs[:front_matter]) @@ -327,7 +326,7 @@ def update_front_matter(attrs) def parsed_content strong_memoize(:parsed_content) do - Gitlab::WikiPages::FrontMatterParser.new(raw_content, container).parse + Gitlab::WikiPages::FrontMatterParser.new(raw_content).parse end end diff --git a/config/feature_flags/development/wiki_front_matter.yml b/config/feature_flags/development/wiki_front_matter.yml deleted file mode 100644 index 39196440d176e..0000000000000 --- a/config/feature_flags/development/wiki_front_matter.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -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 diff --git a/lib/gitlab/wiki_pages/front_matter_parser.rb b/lib/gitlab/wiki_pages/front_matter_parser.rb index 071b0dde61919..ee30fa907f4aa 100644 --- a/lib/gitlab/wiki_pages/front_matter_parser.rb +++ b/lib/gitlab/wiki_pages/front_matter_parser.rb @@ -3,8 +3,6 @@ module Gitlab module WikiPages class FrontMatterParser - FEATURE_FLAG = :wiki_front_matter - # 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: # - a title line @@ -30,18 +28,12 @@ def initialize(content:, front_matter: {}, reason: nil, error: nil) end # @param [String] wiki_content - # @param [FeatureGate] feature_gate The scope for feature availability - def initialize(wiki_content, feature_gate) + def initialize(wiki_content) @wiki_content = wiki_content - @feature_gate = feature_gate - end - - def self.enabled?(gate = nil) - Feature.enabled?(FEATURE_FLAG, gate) end 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? Result.new(front_matter: block.data, content: strip_front_matter_block) @@ -94,16 +86,12 @@ def not_mapping? private - attr_reader :wiki_content, :feature_gate + attr_reader :wiki_content def empty_result(reason = nil, error = nil) Result.new(content: wiki_content, reason: reason, error: error) end - def enabled? - self.class.enabled?(feature_gate) - end - def block @block ||= parse_front_matter_block end diff --git a/spec/lib/gitlab/wiki_pages/front_matter_parser_spec.rb b/spec/lib/gitlab/wiki_pages/front_matter_parser_spec.rb index 3152dc2ad2f41..c0629c8d795a3 100644 --- a/spec/lib/gitlab/wiki_pages/front_matter_parser_spec.rb +++ b/spec/lib/gitlab/wiki_pages/front_matter_parser_spec.rb @@ -3,11 +3,10 @@ require 'spec_helper' 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(:end_divider) { '---' } - let(:gate) { stub_feature_flag_gate('Gate') } let(:with_front_matter) do <<~MD @@ -62,32 +61,6 @@ def have_correct_front_matter it { is_expected.to have_attributes(reason: :no_match) } 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 let(:end_divider) { '...' } let(:raw_content) { with_front_matter } diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb index 699dd35196f96..0016d2f517b7d 100644 --- a/spec/models/wiki_page_spec.rb +++ b/spec/models/wiki_page_spec.rb @@ -24,14 +24,6 @@ def wiki container.wiki 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`. # # include_context 'subject is persisted page', title: 'my title' @@ -48,12 +40,6 @@ def enable_front_matter_for(thing) it { expect(wiki_page).to have_attributes(front_matter: {}, content: content) } 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 let(:content) do <<~MD @@ -68,27 +54,13 @@ def enable_front_matter_for(thing) MD 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 expect(wiki_page.content.strip).to eq('My actual content') 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 context 'the wiki page does not have front matter' do @@ -471,29 +443,6 @@ def enable_front_matter_for(thing) 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 content = 'totally new content' subject.update(content: content, front_matter: { slugs: ['x'] }) -- GitLab