From 07983e38be832a168e8e40e82acefa94dcfcdab0 Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Thu, 7 Apr 2022 09:11:37 -0400 Subject: [PATCH] Adjusting conditional create post rendering (#17132) * Revert "conditionally render create post button for admins #16490 (#16606)" This reverts commit 1cb45995cb5e9580cc30efcb6ebdc8667cbd6a59. * Adding conditional create post rendering This pull request does two things: - Reverts the forem/forem#16606 - Replaces the conditional rendering with the approach from forem/forem#17076 What to consider: - How does this impact Cumulative Layout Shift (CLS). Prior to this commit, we didn't "flicker" the "Create Post" button into view if the site didn't have the conditional. - In reverting forem/forem#16606 we remove a dependency on Turbo. - We reduce one network call, relying instead on the async_info to carry the visible/hidden logic. If the "flicker" is a problem we could add a conditional in the page for if the site has enabled that feature. However, that's a place holder as we're looking at possible other reasons for allowing/disabling the create a post. This is a non-blocking PR, as in we can merge or not merge this and proceed with what we have. Instead the main goal is to "unify" our approach. * Update cypress/integration/seededFlows/policyFlows/limitPostCreationToAdmins.spec.js Co-authored-by: Suzanne Aitchison * Leveraging change from forem/forem#17143 Co-authored-by: Suzanne Aitchison --- app/assets/javascripts/base.js.erb | 2 - .../authorization/articles_controller.rb | 16 ------- .../articles/create_post_button.html.erb | 3 -- app/views/layouts/_top_bar.html.erb | 7 +-- config/routes.rb | 6 --- .../limitPostCreationToAdmins.spec.js | 9 ++-- package.json | 1 - spec/requests/authorization/articles_spec.rb | 47 ------------------- spec/requests/root_page_spec.rb | 31 ------------ yarn.lock | 5 -- 10 files changed, 5 insertions(+), 122 deletions(-) delete mode 100644 app/controllers/authorization/articles_controller.rb delete mode 100644 app/views/authorization/articles/create_post_button.html.erb delete mode 100644 spec/requests/authorization/articles_spec.rb delete mode 100644 spec/requests/root_page_spec.rb diff --git a/app/assets/javascripts/base.js.erb b/app/assets/javascripts/base.js.erb index 88c9eaf37..4c6fd0c24 100644 --- a/app/assets/javascripts/base.js.erb +++ b/app/assets/javascripts/base.js.erb @@ -4,11 +4,9 @@ //= require initializePage //= require utilities/getImageForLink //= require @honeybadger-io/js/dist/browser/honeybadger.js -//= require @hotwired/turbo //= require i18n //= require ahoy.js/dist/ahoy.js -Turbo.session.drive = false I18n.defaultLocale = 'en'; I18n.locale = document.body.dataset.locale; I18n.translations = JSON.parse(document.getElementById('i18n-translations').dataset.translations); diff --git a/app/controllers/authorization/articles_controller.rb b/app/controllers/authorization/articles_controller.rb deleted file mode 100644 index 6a4f6ab47..000000000 --- a/app/controllers/authorization/articles_controller.rb +++ /dev/null @@ -1,16 +0,0 @@ -module Authorization - class ArticlesController < ApplicationController - include ApplicationHelper - layout false - - before_action :authenticate_user! - after_action :verify_authorized - - def create_post_button - authorize Article, :create? - unless FeatureFlag.enabled?(:limit_post_creation_to_admins) - render file: "public/404.html", status: :not_found - end - end - end -end diff --git a/app/views/authorization/articles/create_post_button.html.erb b/app/views/authorization/articles/create_post_button.html.erb deleted file mode 100644 index 1092a72d3..000000000 --- a/app/views/authorization/articles/create_post_button.html.erb +++ /dev/null @@ -1,3 +0,0 @@ - - <%= t("views.main.create_post") %> - diff --git a/app/views/layouts/_top_bar.html.erb b/app/views/layouts/_top_bar.html.erb index a5b5a48b2..b0bd64019 100644 --- a/app/views/layouts/_top_bar.html.erb +++ b/app/views/layouts/_top_bar.html.erb @@ -29,11 +29,8 @@ <% if user_signed_in? %>