From ff177b0c093e5b7f783c1e1d1e1f753f116d69db Mon Sep 17 00:00:00 2001 From: Jacob Herrington Date: Fri, 23 Oct 2020 09:00:59 -0500 Subject: [PATCH] [deploy] Only show user count for large userbases (#11021) This is a request from one of our early adopter Forems. We should only render the user count that appears on most of our sign up CTAs when a Forem has a large userbase (initially, I'm setting that to 1000 users). The change also removes a lot of duplicated markup by using some partials to render the copy in the various auth CTAs. Hopefully, this is written in such a way that changing opening up more fine-grained control of these partials is trivial. --- app/controllers/registrations_controller.rb | 2 -- app/helpers/application_helper.rb | 10 ++++++++++ app/views/articles/_sidebar_additional.html.erb | 15 +++------------ .../registrations/_registration_form.html.erb | 4 +--- app/views/layouts/_nav_menu.html.erb | 15 +++------------ .../shared/_authentication_actions.html.erb | 6 ++++++ .../shared/_authentication_description.html.erb | 5 +++++ app/views/shared/_authentication_title.html.erb | 1 + app/views/stories/_sign_in_invitation.html.erb | 16 +++------------- 9 files changed, 32 insertions(+), 42 deletions(-) create mode 100644 app/views/shared/_authentication_actions.html.erb create mode 100644 app/views/shared/_authentication_description.html.erb create mode 100644 app/views/shared/_authentication_title.html.erb diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 5d53d8fd8..9bc368aac 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -2,8 +2,6 @@ class RegistrationsController < Devise::RegistrationsController prepend_before_action :require_no_authentication, only: [] def new - @registered_users_count = User.registered.estimated_count - if user_signed_in? redirect_to root_path(signin: "true") else diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0087e9826..068c1227d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -11,6 +11,8 @@ module ApplicationHelper ) # rubocop:enable Performance/OpenStruct + LARGE_USERBASE_THRESHOLD = 1000 + def user_logged_in_status user_signed_in? ? "logged-in" : "logged-out" end @@ -281,6 +283,14 @@ module ApplicationHelper HTMLEntities.new.decode(sanitize(str).to_str) end + def estimated_user_count + User.registered.estimated_count + end + + def display_estimated_user_count? + estimated_user_count > LARGE_USERBASE_THRESHOLD + end + # rubocop:disable Rails/OutputSafety def admin_config_label(method, content = nil) content ||= raw("#{method.to_s.humanize}") diff --git a/app/views/articles/_sidebar_additional.html.erb b/app/views/articles/_sidebar_additional.html.erb index d4ccf60b6..2dcc6ac8d 100644 --- a/app/views/articles/_sidebar_additional.html.erb +++ b/app/views/articles/_sidebar_additional.html.erb @@ -10,22 +10,13 @@

- <%= community_name %> is a community of <%= number_with_delimiter User.registered.estimated_count %> amazing <%= community_members_label %> + <%= render "shared/authentication_title" %>

- <% if SiteConfig.tagline.present? %> - <%= SiteConfig.tagline %> - <% else %> - Log in to customize your experience and get involved. - <% end %> + <%= render "shared/authentication_description" %>

diff --git a/app/views/devise/registrations/_registration_form.html.erb b/app/views/devise/registrations/_registration_form.html.erb index c8a33799a..67cc9f4e1 100644 --- a/app/views/devise/registrations/_registration_form.html.erb +++ b/app/views/devise/registrations/_registration_form.html.erb @@ -9,9 +9,7 @@ <% end %>

- <%= community_name %> is a community of - <%= number_with_delimiter(@registered_users_count) %> - amazing <%= community_members_label %>. + <%= render "shared/authentication_title" %>

diff --git a/app/views/layouts/_nav_menu.html.erb b/app/views/layouts/_nav_menu.html.erb index 31ef21f13..72eca8110 100644 --- a/app/views/layouts/_nav_menu.html.erb +++ b/app/views/layouts/_nav_menu.html.erb @@ -29,22 +29,13 @@

- <%= community_name %> is a community of <%= number_with_delimiter User.registered.estimated_count %> amazing <%= community_members_label %> + <%= render "shared/authentication_title" %>

- <% if SiteConfig.tagline.present? %> - <%= SiteConfig.tagline %> - <% else %> - Log in to customize your experience and get involved. - <% end %> + <%= render "shared/authentication_description" %>

diff --git a/app/views/shared/_authentication_actions.html.erb b/app/views/shared/_authentication_actions.html.erb new file mode 100644 index 000000000..b8105df1c --- /dev/null +++ b/app/views/shared/_authentication_actions.html.erb @@ -0,0 +1,6 @@ +" class="crayons-btn" aria-label="Create new account"> + Create new account + + + Log in + diff --git a/app/views/shared/_authentication_description.html.erb b/app/views/shared/_authentication_description.html.erb new file mode 100644 index 000000000..38a70f45e --- /dev/null +++ b/app/views/shared/_authentication_description.html.erb @@ -0,0 +1,5 @@ +<% if SiteConfig.tagline.present? %> + <%= SiteConfig.tagline %> +<% else %> + Log in to customize your experience and get involved. +<% end %> diff --git a/app/views/shared/_authentication_title.html.erb b/app/views/shared/_authentication_title.html.erb new file mode 100644 index 000000000..83aa53ef4 --- /dev/null +++ b/app/views/shared/_authentication_title.html.erb @@ -0,0 +1 @@ +<%= community_name %> is a community of <%= display_estimated_user_count? ? number_with_delimiter(estimated_user_count) : "" %> amazing <%= community_members_label %> diff --git a/app/views/stories/_sign_in_invitation.html.erb b/app/views/stories/_sign_in_invitation.html.erb index f19f265d0..87279d0d2 100644 --- a/app/views/stories/_sign_in_invitation.html.erb +++ b/app/views/stories/_sign_in_invitation.html.erb @@ -6,25 +6,15 @@

-<%= community_name %> is a community of
- <%= number_with_delimiter User.registered.estimated_count %> amazing <%= community_members_label %> + <%= render "shared/authentication_title" %>

- <% if SiteConfig.tagline.present? %> - <%= SiteConfig.tagline %> - <% else %> - Log in to customize your experience and get involved. - <% end %> + <%= render "shared/authentication_description" %>

- - Create new account - - - Log in - + <%= render "shared/authentication_actions" %>