From c099797700c5f84b83cf3096c1b58ef2adadb7d7 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 12 Nov 2024 03:28:31 -0500 Subject: [PATCH] Use `mastodon` config namespace to load software update default value via `config_for` (#30534) --- app/models/software_update.rb | 2 +- app/services/software_update_check_service.rb | 2 +- config/application.rb | 1 + config/mastodon.yml | 3 +++ config/navigation.rb | 6 +++++- .../system_check/software_version_check_spec.rb | 7 ++++--- .../services/software_update_check_service_spec.rb | 14 ++++++++------ 7 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 config/mastodon.yml diff --git a/app/models/software_update.rb b/app/models/software_update.rb index 51a73c2731..2cb935130a 100644 --- a/app/models/software_update.rb +++ b/app/models/software_update.rb @@ -24,7 +24,7 @@ class SoftwareUpdate < ApplicationRecord class << self def check_enabled? - ENV['UPDATE_CHECK_URL'] != '' + Rails.configuration.x.mastodon.software_update_url.present? end def pending_to_a diff --git a/app/services/software_update_check_service.rb b/app/services/software_update_check_service.rb index 24a6955b88..148f269289 100644 --- a/app/services/software_update_check_service.rb +++ b/app/services/software_update_check_service.rb @@ -27,7 +27,7 @@ class SoftwareUpdateCheckService < BaseService end def api_url - ENV.fetch('UPDATE_CHECK_URL', 'https://api.joinmastodon.org/update-check') + Rails.configuration.x.mastodon.software_update_url end def version diff --git a/config/application.rb b/config/application.rb index 18a1b1a0fd..cfeed02e98 100644 --- a/config/application.rb +++ b/config/application.rb @@ -105,6 +105,7 @@ module Mastodon end config.x.captcha = config_for(:captcha) + config.x.mastodon = config_for(:mastodon) config.x.translation = config_for(:translation) config.to_prepare do diff --git a/config/mastodon.yml b/config/mastodon.yml new file mode 100644 index 0000000000..255213b4b7 --- /dev/null +++ b/config/mastodon.yml @@ -0,0 +1,3 @@ +--- +shared: + software_update_url: <%= ENV.fetch('UPDATE_CHECK_URL', 'https://api.joinmastodon.org/update-check') %> diff --git a/config/navigation.rb b/config/navigation.rb index 7ec7ecb7e7..bdda569092 100644 --- a/config/navigation.rb +++ b/config/navigation.rb @@ -6,7 +6,11 @@ SimpleNavigation::Configuration.run do |navigation| navigation.items do |n| n.item :web, safe_join([material_symbol('chevron_left'), t('settings.back')]), root_path - n.item :software_updates, safe_join([material_symbol('report'), t('admin.critical_update_pending')]), admin_software_updates_path, if: -> { ENV['UPDATE_CHECK_URL'] != '' && current_user.can?(:view_devops) && SoftwareUpdate.urgent_pending? }, html: { class: 'warning' } + n.item :software_updates, + safe_join([material_symbol('report'), t('admin.critical_update_pending')]), + admin_software_updates_path, + if: -> { Rails.configuration.x.mastodon.software_update_url.present? && current_user.can?(:view_devops) && SoftwareUpdate.urgent_pending? }, + html: { class: 'warning' } n.item :profile, safe_join([material_symbol('person'), t('settings.profile')]), settings_profile_path, if: -> { current_user.functional? && !self_destruct }, highlights_on: %r{/settings/profile|/settings/featured_tags|/settings/verification|/settings/privacy} diff --git a/spec/lib/admin/system_check/software_version_check_spec.rb b/spec/lib/admin/system_check/software_version_check_spec.rb index 8460d90668..75dc1a4732 100644 --- a/spec/lib/admin/system_check/software_version_check_spec.rb +++ b/spec/lib/admin/system_check/software_version_check_spec.rb @@ -27,9 +27,10 @@ RSpec.describe Admin::SystemCheck::SoftwareVersionCheck do context 'when checks are disabled' do around do |example| - ClimateControl.modify UPDATE_CHECK_URL: '' do - example.run - end + original = Rails.configuration.x.mastodon.software_update_url + Rails.configuration.x.mastodon.software_update_url = '' + example.run + Rails.configuration.x.mastodon.software_update_url = original end it 'returns true' do diff --git a/spec/services/software_update_check_service_spec.rb b/spec/services/software_update_check_service_spec.rb index a1eb9d86e9..4098bd470a 100644 --- a/spec/services/software_update_check_service_spec.rb +++ b/spec/services/software_update_check_service_spec.rb @@ -124,9 +124,10 @@ RSpec.describe SoftwareUpdateCheckService do context 'when update checking is disabled' do around do |example| - ClimateControl.modify UPDATE_CHECK_URL: '' do - example.run - end + original = Rails.configuration.x.mastodon.software_update_url + Rails.configuration.x.mastodon.software_update_url = '' + example.run + Rails.configuration.x.mastodon.software_update_url = original end before do @@ -148,9 +149,10 @@ RSpec.describe SoftwareUpdateCheckService do let(:update_check_url) { 'https://api.example.com/update_check' } around do |example| - ClimateControl.modify UPDATE_CHECK_URL: 'https://api.example.com/update_check' do - example.run - end + original = Rails.configuration.x.mastodon.software_update_url + Rails.configuration.x.mastodon.software_update_url = 'https://api.example.com/update_check' + example.run + Rails.configuration.x.mastodon.software_update_url = original end it_behaves_like 'when the feature is enabled'