From 340f1a68becaf7c0f67b0f3a6d101213c8ceff90 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 28 Sep 2023 10:52:37 -0400 Subject: [PATCH] Simplify instance presenter view access (#26046) --- .haml-lint_todo.yml | 5 ++--- app/controllers/about_controller.rb | 8 -------- app/controllers/auth/registrations_controller.rb | 5 ----- app/controllers/auth/sessions_controller.rb | 5 ----- app/controllers/concerns/account_controller_concern.rb | 6 ------ app/controllers/home_controller.rb | 8 -------- app/controllers/privacy_controller.rb | 8 -------- app/controllers/statuses_controller.rb | 5 ----- app/controllers/tags_controller.rb | 5 ----- app/helpers/mascot_helper.rb | 2 -- app/views/shared/_og.html.haml | 6 +++--- 11 files changed, 5 insertions(+), 58 deletions(-) diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index 886855ce0f0..64f5c0cc75d 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `haml-lint --auto-gen-config` -# on 2023-09-28 10:26:23 -0400 using Haml-Lint version 0.50.0. +# on 2023-09-28 10:42:25 -0400 using Haml-Lint version 0.50.0. # The point is for the user to remove these configuration records # one by one as the lints are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -26,14 +26,13 @@ linters: - 'app/views/admin/reports/show.html.haml' - 'app/views/disputes/strikes/show.html.haml' - # Offense count: 18 + # Offense count: 15 InstanceVariables: exclude: - 'app/views/admin/reports/_actions.html.haml' - 'app/views/auth/registrations/_status.html.haml' - 'app/views/auth/sessions/two_factor/_otp_authentication_form.html.haml' - 'app/views/relationships/_account.html.haml' - - 'app/views/shared/_og.html.haml' # Offense count: 2 IdNames: diff --git a/app/controllers/about_controller.rb b/app/controllers/about_controller.rb index c4b7e9c9d26..ffccf7a28e6 100644 --- a/app/controllers/about_controller.rb +++ b/app/controllers/about_controller.rb @@ -5,15 +5,7 @@ class AboutController < ApplicationController skip_before_action :require_functional! - before_action :set_instance_presenter - def show expires_in(15.seconds, public: true, stale_while_revalidate: 30.seconds, stale_if_error: 1.day) unless user_signed_in? end - - private - - def set_instance_presenter - @instance_presenter = InstancePresenter.new - end end diff --git a/app/controllers/auth/registrations_controller.rb b/app/controllers/auth/registrations_controller.rb index e70ae5b1b8b..b0f2a02aa33 100644 --- a/app/controllers/auth/registrations_controller.rb +++ b/app/controllers/auth/registrations_controller.rb @@ -10,7 +10,6 @@ class Auth::RegistrationsController < Devise::RegistrationsController before_action :configure_sign_up_params, only: [:create] before_action :set_sessions, only: [:edit, :update] before_action :set_strikes, only: [:edit, :update] - before_action :set_instance_presenter, only: [:new, :create, :update] before_action :set_body_classes, only: [:new, :create, :edit, :update] before_action :require_not_suspended!, only: [:update] before_action :set_cache_headers, only: [:edit, :update] @@ -107,10 +106,6 @@ class Auth::RegistrationsController < Devise::RegistrationsController private - def set_instance_presenter - @instance_presenter = InstancePresenter.new - end - def set_body_classes @body_classes = %w(edit update).include?(action_name) ? 'admin' : 'lighter' end diff --git a/app/controllers/auth/sessions_controller.rb b/app/controllers/auth/sessions_controller.rb index 06a3deee2ba..5327192b81d 100644 --- a/app/controllers/auth/sessions_controller.rb +++ b/app/controllers/auth/sessions_controller.rb @@ -11,7 +11,6 @@ class Auth::SessionsController < Devise::SessionsController include TwoFactorAuthenticationConcern - before_action :set_instance_presenter, only: [:new] before_action :set_body_classes content_security_policy only: :new do |p| @@ -99,10 +98,6 @@ class Auth::SessionsController < Devise::SessionsController private - def set_instance_presenter - @instance_presenter = InstancePresenter.new - end - def set_body_classes @body_classes = 'lighter' end diff --git a/app/controllers/concerns/account_controller_concern.rb b/app/controllers/concerns/account_controller_concern.rb index e9cff22ca8c..d63bcc85c95 100644 --- a/app/controllers/concerns/account_controller_concern.rb +++ b/app/controllers/concerns/account_controller_concern.rb @@ -9,17 +9,11 @@ module AccountControllerConcern FOLLOW_PER_PAGE = 12 included do - before_action :set_instance_presenter - after_action :set_link_headers, if: -> { request.format.nil? || request.format == :html } end private - def set_instance_presenter - @instance_presenter = InstancePresenter.new - end - def set_link_headers response.headers['Link'] = LinkHeader.new( [ diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index ee940e67075..03aa3eb52a6 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -3,15 +3,7 @@ class HomeController < ApplicationController include WebAppControllerConcern - before_action :set_instance_presenter - def index expires_in(15.seconds, public: true, stale_while_revalidate: 30.seconds, stale_if_error: 1.day) unless user_signed_in? end - - private - - def set_instance_presenter - @instance_presenter = InstancePresenter.new - end end diff --git a/app/controllers/privacy_controller.rb b/app/controllers/privacy_controller.rb index 070ee8a06a5..860e7c77a06 100644 --- a/app/controllers/privacy_controller.rb +++ b/app/controllers/privacy_controller.rb @@ -5,15 +5,7 @@ class PrivacyController < ApplicationController skip_before_action :require_functional! - before_action :set_instance_presenter - def show expires_in(15.seconds, public: true, stale_while_revalidate: 30.seconds, stale_if_error: 1.day) unless user_signed_in? end - - private - - def set_instance_presenter - @instance_presenter = InstancePresenter.new - end end diff --git a/app/controllers/statuses_controller.rb b/app/controllers/statuses_controller.rb index effaba3630f..db7eddd78b3 100644 --- a/app/controllers/statuses_controller.rb +++ b/app/controllers/statuses_controller.rb @@ -10,7 +10,6 @@ class StatusesController < ApplicationController before_action :require_account_signature!, only: [:show, :activity], if: -> { request.format == :json && authorized_fetch_mode? } before_action :set_status - before_action :set_instance_presenter before_action :redirect_to_original, only: :show before_action :set_body_classes, only: :embed @@ -67,10 +66,6 @@ class StatusesController < ApplicationController not_found end - def set_instance_presenter - @instance_presenter = InstancePresenter.new - end - def redirect_to_original redirect_to(ActivityPub::TagManager.instance.url_for(@status.reblog), allow_other_host: true) if @status.reblog? end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 2007fe8462e..b0bdbde9566 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -14,7 +14,6 @@ class TagsController < ApplicationController before_action :set_local before_action :set_tag before_action :set_statuses, if: -> { request.format == :rss } - before_action :set_instance_presenter skip_before_action :require_functional!, unless: :limited_federation_mode? @@ -49,10 +48,6 @@ class TagsController < ApplicationController @statuses = cache_collection(TagFeed.new(@tag, nil, local: @local).get(limit_param), Status) end - def set_instance_presenter - @instance_presenter = InstancePresenter.new - end - def limit_param params[:limit].present? ? [params[:limit].to_i, PAGE_SIZE_MAX].min : PAGE_SIZE end diff --git a/app/helpers/mascot_helper.rb b/app/helpers/mascot_helper.rb index 0124c74f19b..8ee04383ece 100644 --- a/app/helpers/mascot_helper.rb +++ b/app/helpers/mascot_helper.rb @@ -5,8 +5,6 @@ module MascotHelper full_asset_url(instance_presenter.mascot&.file&.url || asset_pack_path('media/images/elephant_ui_plane.svg')) end - private - def instance_presenter @instance_presenter ||= InstancePresenter.new end diff --git a/app/views/shared/_og.html.haml b/app/views/shared/_og.html.haml index a5d99ae33ac..385351ee14a 100644 --- a/app/views/shared/_og.html.haml +++ b/app/views/shared/_og.html.haml @@ -1,12 +1,12 @@ -- thumbnail = @instance_presenter.thumbnail -- description ||= @instance_presenter.description.presence || strip_tags(t('about.about_mastodon_html')) +- thumbnail = instance_presenter.thumbnail +- description ||= instance_presenter.description.presence || strip_tags(t('about.about_mastodon_html')) %meta{ name: 'description', content: description }/ = opengraph 'og:site_name', t('about.hosted_on', domain: site_hostname) = opengraph 'og:url', url_for(only_path: false) = opengraph 'og:type', 'website' -= opengraph 'og:title', @instance_presenter.title += opengraph 'og:title', instance_presenter.title = opengraph 'og:description', description = opengraph 'og:image', full_asset_url(thumbnail&.file&.url(:'@1x') || asset_pack_path('media/images/preview.png', protocol: :request)) = opengraph 'og:image:width', thumbnail ? thumbnail.meta['width'] : '1200'