~cytrogen/masto-fe

340f1a68becaf7c0f67b0f3a6d101213c8ceff90 — Matt Jankowski 2 years ago 2016c5d
Simplify instance presenter view access (#26046)

M .haml-lint_todo.yml => .haml-lint_todo.yml +2 -3
@@ 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:

M app/controllers/about_controller.rb => app/controllers/about_controller.rb +0 -8
@@ 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

M app/controllers/auth/registrations_controller.rb => app/controllers/auth/registrations_controller.rb +0 -5
@@ 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

M app/controllers/auth/sessions_controller.rb => app/controllers/auth/sessions_controller.rb +0 -5
@@ 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

M app/controllers/concerns/account_controller_concern.rb => app/controllers/concerns/account_controller_concern.rb +0 -6
@@ 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(
      [

M app/controllers/home_controller.rb => app/controllers/home_controller.rb +0 -8
@@ 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

M app/controllers/privacy_controller.rb => app/controllers/privacy_controller.rb +0 -8
@@ 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

M app/controllers/statuses_controller.rb => app/controllers/statuses_controller.rb +0 -5
@@ 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

M app/controllers/tags_controller.rb => app/controllers/tags_controller.rb +0 -5
@@ 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

M app/helpers/mascot_helper.rb => app/helpers/mascot_helper.rb +0 -2
@@ 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

M app/views/shared/_og.html.haml => app/views/shared/_og.html.haml +3 -3
@@ 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'