From e17faedffba569a5925b1da35214c1f56806f6b2 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 14 Dec 2023 09:04:55 -0500 Subject: [PATCH] Move default `meta` options from `InitialStateSerializer` to private method (AbcSize reduction) (#28355) --- .rubocop_todo.yml | 2 +- app/serializers/initial_state_serializer.rb | 50 +++++++++++---------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 03543c8e0d2..03cc2e75d35 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -26,7 +26,7 @@ Lint/NonLocalExitFromIterator: # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: - Max: 125 + Max: 100 # Configuration parameters: CountBlocks, Max. Metrics/BlockNesting: diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb index f606836ba4f..9f7921461d7 100644 --- a/app/serializers/initial_state_serializer.rb +++ b/app/serializers/initial_state_serializer.rb @@ -13,29 +13,7 @@ class InitialStateSerializer < ActiveModel::Serializer has_one :role, serializer: REST::RoleSerializer def meta - store = { - streaming_api_base_url: Rails.configuration.x.streaming_api_base_url, - access_token: object.token, - locale: I18n.locale, - domain: Addressable::IDNA.to_unicode(instance_presenter.domain), - title: instance_presenter.title, - admin: object.admin&.id&.to_s, - search_enabled: Chewy.enabled?, - repository: Mastodon::Version.repository, - source_url: instance_presenter.source_url, - version: instance_presenter.version, - limited_federation_mode: Rails.configuration.x.limited_federation_mode, - mascot: instance_presenter.mascot&.file&.url, - profile_directory: Setting.profile_directory, - trends_enabled: Setting.trends, - registrations_open: Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode, - timeline_preview: Setting.timeline_preview, - activity_api_enabled: Setting.activity_api_enabled, - single_user_mode: Rails.configuration.x.single_user_mode, - trends_as_landing_page: Setting.trends_as_landing_page, - status_page_url: Setting.status_page_url, - sso_redirect: sso_redirect, - } + store = default_meta_store if object.current_account store[:me] = object.current_account.id.to_s @@ -108,6 +86,32 @@ class InitialStateSerializer < ActiveModel::Serializer private + def default_meta_store + { + access_token: object.token, + activity_api_enabled: Setting.activity_api_enabled, + admin: object.admin&.id&.to_s, + domain: Addressable::IDNA.to_unicode(instance_presenter.domain), + limited_federation_mode: Rails.configuration.x.limited_federation_mode, + locale: I18n.locale, + mascot: instance_presenter.mascot&.file&.url, + profile_directory: Setting.profile_directory, + registrations_open: Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode, + repository: Mastodon::Version.repository, + search_enabled: Chewy.enabled?, + single_user_mode: Rails.configuration.x.single_user_mode, + source_url: instance_presenter.source_url, + sso_redirect: sso_redirect, + status_page_url: Setting.status_page_url, + streaming_api_base_url: Rails.configuration.x.streaming_api_base_url, + timeline_preview: Setting.timeline_preview, + title: instance_presenter.title, + trends_as_landing_page: Setting.trends_as_landing_page, + trends_enabled: Setting.trends, + version: instance_presenter.version, + } + end + def object_account_user object.current_account.user end