Remove feature flag and use consistent rendering by default (#20305)
This commit is contained in:
parent
0ddb133c49
commit
41ab84a25d
13 changed files with 8 additions and 140 deletions
|
|
@ -111,18 +111,10 @@ class ArticlesController < ApplicationController
|
|||
authorize Article
|
||||
|
||||
begin
|
||||
if FeatureFlag.enabled?(:consistent_rendering, FeatureFlag::Actor[current_user])
|
||||
renderer = ContentRenderer.new(params[:article_body], source: Article.new, user: current_user)
|
||||
result = renderer.process_article
|
||||
processed_html = result.processed_html
|
||||
front_matter = result.front_matter.to_h
|
||||
else
|
||||
fixed_body_markdown = MarkdownProcessor::Fixer::FixForPreview.call(params[:article_body])
|
||||
parsed = FrontMatterParser::Parser.new(:md).call(fixed_body_markdown)
|
||||
parsed_markdown = MarkdownProcessor::Parser.new(parsed.content, source: Article.new, user: current_user)
|
||||
processed_html = parsed_markdown.finalize
|
||||
front_matter = parsed.front_matter.to_h
|
||||
end
|
||||
renderer = ContentRenderer.new(params[:article_body], source: Article.new, user: current_user)
|
||||
result = renderer.process_article
|
||||
processed_html = result.processed_html
|
||||
front_matter = result.front_matter.to_h
|
||||
rescue StandardError => e
|
||||
@article = Article.new(body_markdown: params[:article_body])
|
||||
@article.errors.add(:base, ErrorMessages::Clean.call(e.message))
|
||||
|
|
|
|||
|
|
@ -187,14 +187,8 @@ class CommentsController < ApplicationController
|
|||
skip_authorization
|
||||
begin
|
||||
permitted_body_markdown = permitted_attributes(Comment)[:body_markdown]
|
||||
if FeatureFlag.enabled?(:consistent_rendering, FeatureFlag::Actor[current_user])
|
||||
renderer = ContentRenderer.new(permitted_body_markdown, source: self, user: current_user)
|
||||
processed_html = renderer.process.processed_html
|
||||
else
|
||||
fixed_body_markdown = MarkdownProcessor::Fixer::FixForPreview.call(permitted_body_markdown)
|
||||
parsed_markdown = MarkdownProcessor::Parser.new(fixed_body_markdown, source: Comment.new, user: current_user)
|
||||
processed_html = parsed_markdown.finalize
|
||||
end
|
||||
renderer = ContentRenderer.new(permitted_body_markdown, source: self, user: current_user)
|
||||
processed_html = renderer.process.processed_html
|
||||
rescue StandardError => e
|
||||
processed_html = I18n.t("comments_controller.markdown_html", error: e)
|
||||
end
|
||||
|
|
@ -223,7 +217,7 @@ class CommentsController < ApplicationController
|
|||
if success
|
||||
@comment&.commentable&.update_column(:any_comments_hidden, true)
|
||||
if params[:hide_children] == "1"
|
||||
@comment.descendants.includes(:user, :commentable).each do |c|
|
||||
@comment.descendants.includes(:user, :commentable).find_each do |c|
|
||||
c.update(hidden_by_commentable_user: true)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -478,22 +478,7 @@ class Article < ApplicationRecord
|
|||
end
|
||||
|
||||
def has_frontmatter?
|
||||
if FeatureFlag.enabled?(:consistent_rendering, FeatureFlag::Actor[user])
|
||||
processed_content.has_front_matter?
|
||||
else
|
||||
original_has_frontmatter?
|
||||
end
|
||||
end
|
||||
|
||||
def original_has_frontmatter?
|
||||
fixed_body_markdown = MarkdownProcessor::Fixer::FixAll.call(body_markdown)
|
||||
begin
|
||||
parsed = FrontMatterParser::Parser.new(:md).call(fixed_body_markdown)
|
||||
parsed.front_matter["title"].present?
|
||||
rescue Psych::SyntaxError, Psych::DisallowedClass
|
||||
# if frontmatter is invalid, still render editor with errors instead of 500ing
|
||||
true
|
||||
end
|
||||
processed_content.has_front_matter?
|
||||
end
|
||||
|
||||
def class_name
|
||||
|
|
@ -687,14 +672,6 @@ class Article < ApplicationRecord
|
|||
end
|
||||
|
||||
def evaluate_markdown
|
||||
if FeatureFlag.enabled?(:consistent_rendering, FeatureFlag::Actor[user])
|
||||
extracted_evaluate_markdown
|
||||
else
|
||||
original_evaluate_markdown
|
||||
end
|
||||
end
|
||||
|
||||
def extracted_evaluate_markdown
|
||||
content_renderer = processed_content
|
||||
return unless content_renderer
|
||||
|
||||
|
|
@ -716,24 +693,6 @@ class Article < ApplicationRecord
|
|||
errors.add(:base, ErrorMessages::Clean.call(e.message))
|
||||
end
|
||||
|
||||
def original_evaluate_markdown
|
||||
fixed_body_markdown = MarkdownProcessor::Fixer::FixAll.call(body_markdown || "")
|
||||
parsed = FrontMatterParser::Parser.new(:md).call(fixed_body_markdown)
|
||||
parsed_markdown = MarkdownProcessor::Parser.new(parsed.content, source: self, user: user)
|
||||
self.reading_time = parsed_markdown.calculate_reading_time
|
||||
self.processed_html = parsed_markdown.finalize
|
||||
|
||||
if parsed.front_matter.any?
|
||||
evaluate_front_matter(parsed.front_matter)
|
||||
elsif tag_list.any?
|
||||
set_tag_list(tag_list)
|
||||
end
|
||||
|
||||
self.description = processed_description if description.blank?
|
||||
rescue StandardError => e
|
||||
errors.add(:base, ErrorMessages::Clean.call(e.message))
|
||||
end
|
||||
|
||||
def set_tag_list(tags)
|
||||
self.tag_list = [] # overwrite any existing tag with those from the front matter
|
||||
tag_list.add(tags, parse: true)
|
||||
|
|
|
|||
|
|
@ -229,14 +229,6 @@ class Comment < ApplicationRecord
|
|||
end
|
||||
|
||||
def evaluate_markdown
|
||||
if FeatureFlag.enabled?(:consistent_rendering, FeatureFlag::Actor[user])
|
||||
extracted_evaluate_markdown
|
||||
else
|
||||
original_evaluate_markdown
|
||||
end
|
||||
end
|
||||
|
||||
def extracted_evaluate_markdown
|
||||
return unless user
|
||||
|
||||
renderer = ContentRenderer.new(body_markdown, source: self, user: user)
|
||||
|
|
@ -247,14 +239,6 @@ class Comment < ApplicationRecord
|
|||
errors.add(:base, ErrorMessages::Clean.call(e.message))
|
||||
end
|
||||
|
||||
def original_evaluate_markdown
|
||||
fixed_body_markdown = MarkdownProcessor::Fixer::FixForComment.call(body_markdown)
|
||||
parsed_markdown = MarkdownProcessor::Parser.new(fixed_body_markdown, source: self, user: user)
|
||||
self.processed_html = parsed_markdown.finalize(link_attributes: { rel: "nofollow" })
|
||||
wrap_timestamps_if_video_present! if commentable
|
||||
shorten_urls!
|
||||
end
|
||||
|
||||
def adjust_comment_parent_based_on_depth
|
||||
self.parent_id = parent.descendant_ids.last if parent_exists? && (parent.depth > 1 && parent.has_children?)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@ RSpec.describe Article do
|
|||
article
|
||||
end
|
||||
|
||||
before { allow(FeatureFlag).to receive(:enabled?).with(:consistent_rendering, any_args).and_return(true) }
|
||||
|
||||
let(:user) { create(:user) }
|
||||
let!(:article) { create(:article, user: user) }
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ RSpec.describe Comment do
|
|||
let(:article) { create(:article, user: user) }
|
||||
let(:comment) { create(:comment, user: user, commentable: article) }
|
||||
|
||||
before { allow(FeatureFlag).to receive(:enabled?).with(:consistent_rendering, any_args).and_return(true) }
|
||||
|
||||
include_examples "#sync_reactions_count", :article_comment
|
||||
|
||||
describe "validations" do
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ RSpec.describe "ArticlesCreate" do
|
|||
|
||||
before do
|
||||
sign_in user
|
||||
allow(FeatureFlag).to receive(:enabled?).with(:consistent_rendering, any_args).and_return(true)
|
||||
end
|
||||
|
||||
it "creates ordinary article with proper params" do
|
||||
|
|
|
|||
|
|
@ -65,8 +65,6 @@ RSpec.describe "ArticlesShow" do
|
|||
end
|
||||
|
||||
describe "GET /:username/:slug (scheduled)" do
|
||||
before { allow(FeatureFlag).to receive(:enabled?).with(:consistent_rendering, any_args).and_return(true) }
|
||||
|
||||
let(:scheduled_article) { create(:article, published: true, published_at: Date.tomorrow) }
|
||||
let(:query_params) { "?preview=#{scheduled_article.password}" }
|
||||
let(:scheduled_article_path) { scheduled_article.path + query_params }
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ RSpec.describe "ArticlesUpdate" do
|
|||
|
||||
before do
|
||||
sign_in user
|
||||
allow(FeatureFlag).to receive(:enabled?).with(:consistent_rendering, any_args).and_return(true)
|
||||
end
|
||||
|
||||
it "updates ordinary article with proper params" do
|
||||
|
|
|
|||
|
|
@ -254,7 +254,6 @@ RSpec.describe "Comments" do
|
|||
|
||||
describe "PUT /comments/:id" do
|
||||
before do
|
||||
allow(FeatureFlag).to receive(:enabled?).with(:consistent_rendering, any_args).and_return(true)
|
||||
sign_in user
|
||||
end
|
||||
|
||||
|
|
@ -293,25 +292,6 @@ RSpec.describe "Comments" do
|
|||
context "when logged-in and consistent rendering" do
|
||||
before do
|
||||
sign_in user
|
||||
allow(FeatureFlag).to receive(:enabled?).with(:consistent_rendering, any_args).and_return(true)
|
||||
post "/comments/preview",
|
||||
params: { comment: { body_markdown: "hi" } },
|
||||
headers: { HTTP_ACCEPT: "application/json" }
|
||||
end
|
||||
|
||||
it "returns 200 on good request" do
|
||||
expect(response).to have_http_status(:ok)
|
||||
end
|
||||
|
||||
it "returns json" do
|
||||
expect(response.media_type).to eq("application/json")
|
||||
end
|
||||
end
|
||||
|
||||
context "when logged-in and inconsistent rendering" do
|
||||
before do
|
||||
sign_in user
|
||||
allow(FeatureFlag).to receive(:enabled?).with(:consistent_rendering, any_args).and_return(false)
|
||||
post "/comments/preview",
|
||||
params: { comment: { body_markdown: "hi" } },
|
||||
headers: { HTTP_ACCEPT: "application/json" }
|
||||
|
|
@ -339,8 +319,6 @@ RSpec.describe "Comments" do
|
|||
}
|
||||
end
|
||||
|
||||
before { allow(FeatureFlag).to receive(:enabled?).with(:consistent_rendering, any_args).and_return(true) }
|
||||
|
||||
context "when a user is comment_suspended" do
|
||||
before do
|
||||
sign_in user
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ RSpec.describe "Editor" do
|
|||
context "when logged-in" do
|
||||
before do
|
||||
sign_in user
|
||||
allow(FeatureFlag).to receive(:enabled?).with(:consistent_rendering, any_args).and_return(false)
|
||||
end
|
||||
|
||||
it "returns json" do
|
||||
|
|
@ -81,33 +80,5 @@ RSpec.describe "Editor" do
|
|||
expect(response).to be_successful
|
||||
end
|
||||
end
|
||||
|
||||
context "when logged-in + consistent rendering" do
|
||||
before do
|
||||
sign_in user
|
||||
allow(FeatureFlag).to receive(:enabled?).with(:consistent_rendering, any_args).and_return(true)
|
||||
end
|
||||
|
||||
it "returns json" do
|
||||
post "/articles/preview", headers: headers
|
||||
expect(response.media_type).to eq("application/json")
|
||||
end
|
||||
|
||||
it "returns successfully" do
|
||||
article_body = <<~MARKDOWN
|
||||
---
|
||||
---
|
||||
|
||||
Hello
|
||||
MARKDOWN
|
||||
|
||||
post "/articles/preview",
|
||||
headers: headers,
|
||||
params: { article_body: article_body },
|
||||
as: :json
|
||||
|
||||
expect(response).to be_successful
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ RSpec.describe Articles::Creator, type: :service do
|
|||
let(:user) { create(:user) }
|
||||
|
||||
before do
|
||||
allow(FeatureFlag).to receive(:enabled?).with(:consistent_rendering, any_args).and_return(true)
|
||||
allow(SegmentedUserRefreshWorker).to receive(:perform_async)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ RSpec.describe Articles::Updater, type: :service do
|
|||
let(:draft) { create(:article, user: user, published: false, published_at: nil) }
|
||||
|
||||
before do
|
||||
allow(FeatureFlag).to receive(:enabled?).with(:consistent_rendering, any_args).and_return(true)
|
||||
allow(SegmentedUserRefreshWorker).to receive(:perform_async)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue