diff --git a/app/controllers/settings/preferences/posting_defaults_controller.rb b/app/controllers/settings/preferences/posting_defaults_controller.rb new file mode 100644 index 00000000000..53fee0e5ca3 --- /dev/null +++ b/app/controllers/settings/preferences/posting_defaults_controller.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class Settings::Preferences::PostingDefaultsController < Settings::Preferences::BaseController + private + + def after_update_redirect_path + settings_preferences_posting_defaults_path + end +end diff --git a/app/views/settings/preferences/other/show.html.haml b/app/views/settings/preferences/other/show.html.haml index e39f43f7d49..5008a0bbb7e 100644 --- a/app/views/settings/preferences/other/show.html.haml +++ b/app/views/settings/preferences/other/show.html.haml @@ -15,45 +15,6 @@ recommended: true, wrapper: :with_label - %h4= t 'preferences.posting_defaults' - - .fields-group - = ff.input :default_privacy, - collection: Status.selectable_visibilities, - selected: current_user.setting_default_privacy, - hint: false, - include_blank: false, - label_method: ->(visibility) { safe_join([I18n.t("statuses.visibilities.#{visibility}"), I18n.t("statuses.visibilities.#{visibility}_long")], ' - ') }, - label: I18n.t('simple_form.labels.defaults.setting_default_privacy'), - required: false, - wrapper: :with_label - - .fields-group - = ff.input :default_quote_policy, - collection: %w(public followers nobody), - include_blank: false, - label_method: ->(policy) { I18n.t("statuses.quote_policies.#{policy}") }, - label: I18n.t('simple_form.labels.defaults.setting_default_quote_policy'), - hint: I18n.t('simple_form.hints.defaults.setting_default_quote_policy'), - required: false, - wrapper: :with_label - - .fields-group - = ff.input :default_language, - collection: [nil] + filterable_languages, - hint: false, - include_blank: false, - label_method: ->(locale) { locale.nil? ? I18n.t('statuses.default_language') : native_locale_name(locale) }, - label: I18n.t('simple_form.labels.defaults.setting_default_language'), - required: false, - wrapper: :with_label - - .fields-group - = ff.input :default_sensitive, - hint: I18n.t('simple_form.hints.defaults.setting_default_sensitive'), - label: I18n.t('simple_form.labels.defaults.setting_default_sensitive'), - wrapper: :with_label - %h4= t 'preferences.public_timelines' .fields-group diff --git a/app/views/settings/preferences/posting_defaults/show.html.haml b/app/views/settings/preferences/posting_defaults/show.html.haml new file mode 100644 index 00000000000..4d5905208a7 --- /dev/null +++ b/app/views/settings/preferences/posting_defaults/show.html.haml @@ -0,0 +1,48 @@ +- content_for :page_title do + = t('preferences.posting_defaults') + +- content_for :heading_actions do + = button_tag t('generic.save_changes'), class: 'button', form: 'edit_preferences' + += simple_form_for current_user, url: settings_preferences_posting_defaults_path, html: { id: :edit_preferences } do |f| + = render 'shared/error_messages', object: current_user + + = f.simple_fields_for :settings, current_user.settings do |ff| + .flash-message= t('posting_defaults.explanation') + + .fields-group + = ff.input :default_privacy, + collection: Status.selectable_visibilities, + selected: current_user.setting_default_privacy, + hint: false, + include_blank: false, + label_method: ->(visibility) { safe_join([I18n.t("statuses.visibilities.#{visibility}"), I18n.t("statuses.visibilities.#{visibility}_long")], ' - ') }, + label: I18n.t('simple_form.labels.defaults.setting_default_privacy'), + required: false, + wrapper: :with_label + + .fields-group + = ff.input :default_quote_policy, + collection: %w(public followers nobody), + include_blank: false, + label_method: ->(policy) { I18n.t("statuses.quote_policies.#{policy}") }, + label: I18n.t('simple_form.labels.defaults.setting_default_quote_policy'), + hint: I18n.t('simple_form.hints.defaults.setting_default_quote_policy'), + required: false, + wrapper: :with_label + + .fields-group + = ff.input :default_language, + collection: [nil] + filterable_languages, + hint: false, + include_blank: false, + label_method: ->(locale) { locale.nil? ? I18n.t('statuses.default_language') : native_locale_name(locale) }, + label: I18n.t('simple_form.labels.defaults.setting_default_language'), + required: false, + wrapper: :with_label + + .fields-group + = ff.input :default_sensitive, + hint: I18n.t('simple_form.hints.defaults.setting_default_sensitive'), + label: I18n.t('simple_form.labels.defaults.setting_default_sensitive'), + wrapper: :with_label diff --git a/config/locales/en.yml b/config/locales/en.yml index 014ec44863b..b657932d802 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1740,6 +1740,8 @@ en: self_vote: You cannot vote in your own polls too_few_options: must have more than one item too_many_options: can't contain more than %{max} items + posting_defaults: + explanation: These settings will be used as defaults when you create new posts, but you can edit them per post within the composer. preferences: other: Other posting_defaults: Posting defaults diff --git a/config/navigation.rb b/config/navigation.rb index a8f686fd8b1..4829f9efd2d 100644 --- a/config/navigation.rb +++ b/config/navigation.rb @@ -16,6 +16,7 @@ SimpleNavigation::Configuration.run do |navigation| n.item :preferences, safe_join([material_symbol('settings'), t('settings.preferences')]), settings_preferences_path, if: -> { current_user.functional? && !self_destruct } do |s| s.item :appearance, safe_join([material_symbol('computer'), t('settings.appearance')]), settings_preferences_appearance_path + s.item :posting_defaults, safe_join([material_symbol('edit_square'), t('preferences.posting_defaults')]), settings_preferences_posting_defaults_path s.item :notifications, safe_join([material_symbol('mail'), t('settings.notifications')]), settings_preferences_notifications_path s.item :other, safe_join([material_symbol('tune'), t('preferences.other')]), settings_preferences_other_path end diff --git a/config/routes/settings.rb b/config/routes/settings.rb index cefa24316db..f5869a767c2 100644 --- a/config/routes/settings.rb +++ b/config/routes/settings.rb @@ -9,6 +9,7 @@ namespace :settings do namespace :preferences do resource :appearance, only: [:show, :update], controller: :appearance + resource :posting_defaults, only: [:show, :update], controller: :posting_defaults resource :notifications, only: [:show, :update] resource :other, only: [:show, :update], controller: :other end diff --git a/spec/system/settings/preferences/other_spec.rb b/spec/system/settings/preferences/other_spec.rb index d741ec1ad2d..762233b9e5a 100644 --- a/spec/system/settings/preferences/other_spec.rb +++ b/spec/system/settings/preferences/other_spec.rb @@ -15,11 +15,9 @@ RSpec.describe 'Settings preferences other page' do check language_field(:es) check language_field(:fr) - check mark_sensitive_field expect { save_changes } .to change { user.reload.chosen_languages }.to(%w(es fr)) - .and(change { user.reload.settings.default_sensitive }.to(true)) expect(page) .to have_title(I18n.t('settings.preferences')) end @@ -28,10 +26,6 @@ RSpec.describe 'Settings preferences other page' do within('form') { click_on submit_button } end - def mark_sensitive_field - form_label('defaults.setting_default_sensitive') - end - def language_field(key) LanguagesHelper::SUPPORTED_LOCALES[key].last end diff --git a/spec/system/settings/preferences/posting_defaults_spec.rb b/spec/system/settings/preferences/posting_defaults_spec.rb new file mode 100644 index 00000000000..583958f96b3 --- /dev/null +++ b/spec/system/settings/preferences/posting_defaults_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Settings preferences posting defaults page' do + let(:user) { Fabricate :user } + + before { sign_in user } + + it 'Views and updates user prefs' do + visit settings_preferences_posting_defaults_path + + expect(page) + .to have_private_cache_control + + check mark_sensitive_field + + expect { save_changes } + .to change { user.reload.settings.default_sensitive }.to(true) + expect(page) + .to have_title(I18n.t('preferences.posting_defaults')) + end + + def save_changes + click_on submit_button + end + + def mark_sensitive_field + form_label('defaults.setting_default_sensitive') + end +end