From 8f590b0a211716bcbfc0f2278a452469f3346f55 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 4 Feb 2023 04:56:06 +0100 Subject: [PATCH] Add setting for status page URL (#23390) --- .../features/ui/components/link_footer.js | 16 +++++++++++----- app/javascript/mastodon/initial_state.js | 1 + app/models/form/admin_settings.rb | 2 ++ app/presenters/instance_presenter.rb | 4 ++++ app/serializers/initial_state_serializer.rb | 1 + app/serializers/rest/instance_serializer.rb | 1 + app/views/admin/settings/about/show.html.haml | 3 +++ config/locales/simple_form.en.yml | 2 ++ 8 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/javascript/mastodon/features/ui/components/link_footer.js b/app/javascript/mastodon/features/ui/components/link_footer.js index db5945d6ac..be21112079 100644 --- a/app/javascript/mastodon/features/ui/components/link_footer.js +++ b/app/javascript/mastodon/features/ui/components/link_footer.js @@ -3,7 +3,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { FormattedMessage, defineMessages, injectIntl } from 'react-intl'; import { Link } from 'react-router-dom'; -import { domain, version, source_url, profile_directory as profileDirectory } from 'mastodon/initial_state'; +import { domain, version, source_url, statusPageUrl, profile_directory as profileDirectory } from 'mastodon/initial_state'; import { logOut } from 'mastodon/utils/log_out'; import { openModal } from 'mastodon/actions/modal'; import { PERMISSION_INVITE_USERS } from 'mastodon/permissions'; @@ -59,21 +59,27 @@ class LinkFooter extends React.PureComponent {

{domain}: {' '} - + + {statusPageUrl && ( + <> + {DividingCircle} + + + )} {canInvite && ( <> {DividingCircle} - + )} {canProfileDirectory && ( <> {DividingCircle} - + )} {DividingCircle} - +

diff --git a/app/javascript/mastodon/initial_state.js b/app/javascript/mastodon/initial_state.js index 5bb8546eb4..d04c4a42d2 100644 --- a/app/javascript/mastodon/initial_state.js +++ b/app/javascript/mastodon/initial_state.js @@ -134,5 +134,6 @@ export const usePendingItems = getMeta('use_pending_items'); export const version = getMeta('version'); export const translationEnabled = getMeta('translation_enabled'); export const languages = initialState?.languages; +export const statusPageUrl = getMeta('status_page_url'); export default initialState; diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index 132b57b04a..001caa3765 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -32,6 +32,7 @@ class Form::AdminSettings media_cache_retention_period content_cache_retention_period backups_retention_period + status_page_url ).freeze INTEGER_KEYS = %i( @@ -68,6 +69,7 @@ class Form::AdminSettings validates :show_domain_blocks_rationale, inclusion: { in: %w(disabled users all) }, if: -> { defined?(@show_domain_blocks_rationale) } validates :media_cache_retention_period, :content_cache_retention_period, :backups_retention_period, numericality: { only_integer: true }, allow_blank: true, if: -> { defined?(@media_cache_retention_period) || defined?(@content_cache_retention_period) || defined?(@backups_retention_period) } validates :site_short_description, length: { maximum: 200 }, if: -> { defined?(@site_short_description) } + validates :status_page_url, url: true validate :validate_site_uploads KEYS.each do |key| diff --git a/app/presenters/instance_presenter.rb b/app/presenters/instance_presenter.rb index fba3cc734b..e3ba984f74 100644 --- a/app/presenters/instance_presenter.rb +++ b/app/presenters/instance_presenter.rb @@ -38,6 +38,10 @@ class InstancePresenter < ActiveModelSerializers::Model Setting.site_terms end + def status_page_url + Setting.status_page_url + end + def domain Rails.configuration.x.local_domain end diff --git a/app/serializers/initial_state_serializer.rb b/app/serializers/initial_state_serializer.rb index 1bd62c26f6..24417bca77 100644 --- a/app/serializers/initial_state_serializer.rb +++ b/app/serializers/initial_state_serializer.rb @@ -33,6 +33,7 @@ class InitialStateSerializer < ActiveModel::Serializer single_user_mode: Rails.configuration.x.single_user_mode, translation_enabled: TranslationService.configured?, trends_as_landing_page: Setting.trends_as_landing_page, + status_page_url: Setting.status_page_url, } if object.current_account diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index 5ae1099d04..fbb2fea0dc 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -45,6 +45,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer { urls: { streaming: Rails.configuration.x.streaming_api_base_url, + status: object.status_page_url, }, accounts: { diff --git a/app/views/admin/settings/about/show.html.haml b/app/views/admin/settings/about/show.html.haml index 366d213f62..2aaa64abe7 100644 --- a/app/views/admin/settings/about/show.html.haml +++ b/app/views/admin/settings/about/show.html.haml @@ -26,6 +26,9 @@ .fields-row__column.fields-row__column-6.fields-group = f.input :show_domain_blocks_rationale, wrapper: :with_label, collection: %i(disabled users all), label_method: lambda { |value| t("admin.settings.domain_blocks.#{value}") }, include_blank: false, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li' + .fields-group + = f.input :status_page_url, wrapper: :with_block_label, input_html: { placeholder: "https://status.#{Rails.configuration.x.local_domain}" } + .fields-group = f.input :site_terms, wrapper: :with_block_label, as: :text, input_html: { rows: 8 } diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index d01f0ae753..96b0131efe 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -91,6 +91,7 @@ en: site_short_description: A short description to help uniquely identify your server. Who is running it, who is it for? site_terms: Use your own privacy policy or leave blank to use the default. Can be structured with Markdown syntax. site_title: How people may refer to your server besides its domain name. + status_page_url: URL of a page where people can see the status of this server during an outage theme: Theme that logged out visitors and new users see. thumbnail: A roughly 2:1 image displayed alongside your server information. timeline_preview: Logged out visitors will be able to browse the most recent public posts available on the server. @@ -252,6 +253,7 @@ en: site_short_description: Server description site_terms: Privacy Policy site_title: Server name + status_page_url: Status page URL theme: Default theme thumbnail: Server thumbnail timeline_preview: Allow unauthenticated access to public timelines