From 1db4117030ac69b1083ddfe7390dedb02cede421 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 7 Jun 2019 03:39:24 +0200 Subject: Change preferences page into appearance, notifications, and other (#10977) --- .../settings/notifications_controller.rb | 32 ---------------------- .../settings/preferences/appearance_controller.rb | 9 ++++++ .../preferences/notifications_controller.rb | 9 ++++++ app/controllers/settings/preferences_controller.rb | 8 ++++-- 4 files changed, 24 insertions(+), 34 deletions(-) delete mode 100644 app/controllers/settings/notifications_controller.rb create mode 100644 app/controllers/settings/preferences/appearance_controller.rb create mode 100644 app/controllers/settings/preferences/notifications_controller.rb (limited to 'app/controllers/settings') diff --git a/app/controllers/settings/notifications_controller.rb b/app/controllers/settings/notifications_controller.rb deleted file mode 100644 index b2ce83e42..000000000 --- a/app/controllers/settings/notifications_controller.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -class Settings::NotificationsController < Settings::BaseController - layout 'admin' - - before_action :authenticate_user! - - def show; end - - def update - user_settings.update(user_settings_params.to_h) - - if current_user.save - redirect_to settings_notifications_path, notice: I18n.t('generic.changes_saved_msg') - else - render :show - end - end - - private - - def user_settings - UserSettingsDecorator.new(current_user) - end - - def user_settings_params - params.require(:user).permit( - notification_emails: %i(follow follow_request reblog favourite mention digest report pending_account), - interactions: %i(must_be_follower must_be_following must_be_following_dm) - ) - end -end diff --git a/app/controllers/settings/preferences/appearance_controller.rb b/app/controllers/settings/preferences/appearance_controller.rb new file mode 100644 index 000000000..80ea57bd2 --- /dev/null +++ b/app/controllers/settings/preferences/appearance_controller.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class Settings::Preferences::AppearanceController < Settings::PreferencesController + private + + def after_update_redirect_path + settings_preferences_appearance_path + end +end diff --git a/app/controllers/settings/preferences/notifications_controller.rb b/app/controllers/settings/preferences/notifications_controller.rb new file mode 100644 index 000000000..a16ae6a67 --- /dev/null +++ b/app/controllers/settings/preferences/notifications_controller.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class Settings::Preferences::NotificationsController < Settings::PreferencesController + private + + def after_update_redirect_path + settings_preferences_notifications_path + end +end diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb index 930ff70e7..110debd6e 100644 --- a/app/controllers/settings/preferences_controller.rb +++ b/app/controllers/settings/preferences_controller.rb @@ -12,7 +12,7 @@ class Settings::PreferencesController < Settings::BaseController if current_user.update(user_params) I18n.locale = current_user.locale - redirect_to settings_preferences_path, notice: I18n.t('generic.changes_saved_msg') + redirect_to after_update_redirect_path, notice: I18n.t('generic.changes_saved_msg') else render :show end @@ -20,6 +20,10 @@ class Settings::PreferencesController < Settings::BaseController private + def after_update_redirect_path + settings_preferences_path + end + def user_settings UserSettingsDecorator.new(current_user) end @@ -51,7 +55,7 @@ class Settings::PreferencesController < Settings::BaseController :setting_show_application, :setting_advanced_layout, notification_emails: %i(follow follow_request reblog favourite mention digest report pending_account), - interactions: %i(must_be_follower must_be_following) + interactions: %i(must_be_follower must_be_following must_be_following_dm) ) end end -- cgit From 560ec24e585face30ee99d5bba39a02948fd118f Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 7 Jun 2019 16:51:08 +0200 Subject: Change /settings/preferences to redirect to appearance, add /settings/preferences/other (#10988) --- .../settings/preferences/other_controller.rb | 9 +++++ .../settings/preferences/other/show.html.haml | 37 +++++++++++++++++ app/views/settings/preferences/show.html.haml | 37 ----------------- config/navigation.rb | 4 +- config/routes.rb | 6 ++- .../settings/preferences/other_controller_spec.rb | 46 ++++++++++++++++++++++ .../settings/preferences_controller_spec.rb | 46 ---------------------- 7 files changed, 98 insertions(+), 87 deletions(-) create mode 100644 app/controllers/settings/preferences/other_controller.rb create mode 100644 app/views/settings/preferences/other/show.html.haml delete mode 100644 app/views/settings/preferences/show.html.haml create mode 100644 spec/controllers/settings/preferences/other_controller_spec.rb delete mode 100644 spec/controllers/settings/preferences_controller_spec.rb (limited to 'app/controllers/settings') diff --git a/app/controllers/settings/preferences/other_controller.rb b/app/controllers/settings/preferences/other_controller.rb new file mode 100644 index 000000000..07eb89a76 --- /dev/null +++ b/app/controllers/settings/preferences/other_controller.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class Settings::Preferences::OtherController < Settings::PreferencesController + private + + def after_update_redirect_path + settings_preferences_other_path + end +end diff --git a/app/views/settings/preferences/other/show.html.haml b/app/views/settings/preferences/other/show.html.haml new file mode 100644 index 000000000..c966a16bc --- /dev/null +++ b/app/views/settings/preferences/other/show.html.haml @@ -0,0 +1,37 @@ +- content_for :page_title do + = t('settings.preferences') + += simple_form_for current_user, url: settings_preferences_path, html: { method: :put } do |f| + = render 'shared/error_messages', object: current_user + + .fields-group + = f.input :setting_noindex, as: :boolean, wrapper: :with_label + + .fields-group + = f.input :setting_hide_network, as: :boolean, wrapper: :with_label + + .fields-group + = f.input :setting_aggregate_reblogs, as: :boolean, wrapper: :with_label, recommended: true + + %h4= t 'preferences.posting_defaults' + + .fields-row + .fields-group.fields-row__column.fields-row__column-6 + = f.input :setting_default_privacy, collection: Status.selectable_visibilities, wrapper: :with_label, include_blank: false, label_method: lambda { |visibility| safe_join([I18n.t("statuses.visibilities.#{visibility}"), I18n.t("statuses.visibilities.#{visibility}_long")], ' - ') }, required: false, hint: false + + .fields-group.fields-row__column.fields-row__column-6 + = f.input :setting_default_language, collection: [nil] + filterable_languages.sort, wrapper: :with_label, label_method: lambda { |locale| locale.nil? ? I18n.t('statuses.language_detection') : human_locale(locale) }, required: false, include_blank: false, hint: false + + .fields-group + = f.input :setting_default_sensitive, as: :boolean, wrapper: :with_label + + .fields-group + = f.input :setting_show_application, as: :boolean, wrapper: :with_label, recommended: true + + %h4= t 'preferences.public_timelines' + + .fields-group + = f.input :chosen_languages, collection: filterable_languages.sort, wrapper: :with_block_label, include_blank: false, label_method: lambda { |locale| human_locale(locale) }, required: false, as: :check_boxes, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li' + + .actions + = f.button :button, t('generic.save_changes'), type: :submit diff --git a/app/views/settings/preferences/show.html.haml b/app/views/settings/preferences/show.html.haml deleted file mode 100644 index c966a16bc..000000000 --- a/app/views/settings/preferences/show.html.haml +++ /dev/null @@ -1,37 +0,0 @@ -- content_for :page_title do - = t('settings.preferences') - -= simple_form_for current_user, url: settings_preferences_path, html: { method: :put } do |f| - = render 'shared/error_messages', object: current_user - - .fields-group - = f.input :setting_noindex, as: :boolean, wrapper: :with_label - - .fields-group - = f.input :setting_hide_network, as: :boolean, wrapper: :with_label - - .fields-group - = f.input :setting_aggregate_reblogs, as: :boolean, wrapper: :with_label, recommended: true - - %h4= t 'preferences.posting_defaults' - - .fields-row - .fields-group.fields-row__column.fields-row__column-6 - = f.input :setting_default_privacy, collection: Status.selectable_visibilities, wrapper: :with_label, include_blank: false, label_method: lambda { |visibility| safe_join([I18n.t("statuses.visibilities.#{visibility}"), I18n.t("statuses.visibilities.#{visibility}_long")], ' - ') }, required: false, hint: false - - .fields-group.fields-row__column.fields-row__column-6 - = f.input :setting_default_language, collection: [nil] + filterable_languages.sort, wrapper: :with_label, label_method: lambda { |locale| locale.nil? ? I18n.t('statuses.language_detection') : human_locale(locale) }, required: false, include_blank: false, hint: false - - .fields-group - = f.input :setting_default_sensitive, as: :boolean, wrapper: :with_label - - .fields-group - = f.input :setting_show_application, as: :boolean, wrapper: :with_label, recommended: true - - %h4= t 'preferences.public_timelines' - - .fields-group - = f.input :chosen_languages, collection: filterable_languages.sort, wrapper: :with_block_label, include_blank: false, label_method: lambda { |locale| human_locale(locale) }, required: false, as: :check_boxes, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li' - - .actions - = f.button :button, t('generic.save_changes'), type: :submit diff --git a/config/navigation.rb b/config/navigation.rb index 45e5bc562..df1024189 100644 --- a/config/navigation.rb +++ b/config/navigation.rb @@ -10,10 +10,10 @@ SimpleNavigation::Configuration.run do |navigation| s.item :identity_proofs, safe_join([fa_icon('key fw'), t('settings.identity_proofs')]), settings_identity_proofs_path, highlights_on: %r{/settings/identity_proofs*}, if: proc { current_account.identity_proofs.exists? } end - n.item :preferences, safe_join([fa_icon('cog fw'), t('settings.preferences')]), settings_preferences_appearance_url do |s| + n.item :preferences, safe_join([fa_icon('cog fw'), t('settings.preferences')]), settings_preferences_url do |s| s.item :appearance, safe_join([fa_icon('desktop fw'), t('settings.appearance')]), settings_preferences_appearance_url s.item :notifications, safe_join([fa_icon('bell fw'), t('settings.notifications')]), settings_preferences_notifications_url - s.item :other, safe_join([fa_icon('cog fw'), t('preferences.other')]), settings_preferences_url + s.item :other, safe_join([fa_icon('cog fw'), t('preferences.other')]), settings_preferences_other_url end n.item :relationships, safe_join([fa_icon('users fw'), t('settings.relationships')]), relationships_url diff --git a/config/routes.rb b/config/routes.rb index 2b35472bd..145079c69 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -87,15 +87,17 @@ Rails.application.routes.draw do get '/explore', to: 'directories#index', as: :explore get '/explore/:id', to: 'directories#show', as: :explore_hashtag - get '/settings', to: redirect('/settings/preferences') + get '/settings', to: redirect('/settings/profile') namespace :settings do resource :profile, only: [:show, :update] - resource :preferences, only: [:show, :update] + + get :preferences, to: redirect('/settings/preferences/appearance') namespace :preferences do resource :appearance, only: [:show, :update], controller: :appearance resource :notifications, only: [:show, :update] + resource :other, only: [:show, :update], controller: :other end resource :import, only: [:show, :create] diff --git a/spec/controllers/settings/preferences/other_controller_spec.rb b/spec/controllers/settings/preferences/other_controller_spec.rb new file mode 100644 index 000000000..1b556ac7f --- /dev/null +++ b/spec/controllers/settings/preferences/other_controller_spec.rb @@ -0,0 +1,46 @@ +require 'rails_helper' + +describe Settings::Preferences::OtherController do + render_views + + let(:user) { Fabricate(:user, filtered_languages: []) } + + before do + sign_in user, scope: :user + end + + describe 'GET #show' do + it 'returns http success' do + get :show + expect(response).to have_http_status(200) + end + end + + describe 'PUT #update' do + it 'updates the user record' do + put :update, params: { user: { locale: 'en', chosen_languages: ['es', 'fr', ''] } } + + expect(response).to redirect_to(settings_preferences_other_path) + user.reload + expect(user.locale).to eq 'en' + expect(user.chosen_languages).to eq ['es', 'fr'] + end + + it 'updates user settings' do + user.settings['boost_modal'] = false + user.settings['delete_modal'] = true + + put :update, params: { + user: { + setting_boost_modal: '1', + setting_delete_modal: '0', + } + } + + expect(response).to redirect_to(settings_preferences_other_path) + user.reload + expect(user.settings['boost_modal']).to be true + expect(user.settings['delete_modal']).to be false + end + end +end diff --git a/spec/controllers/settings/preferences_controller_spec.rb b/spec/controllers/settings/preferences_controller_spec.rb deleted file mode 100644 index f2028cf39..000000000 --- a/spec/controllers/settings/preferences_controller_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -require 'rails_helper' - -describe Settings::PreferencesController do - render_views - - let(:user) { Fabricate(:user, filtered_languages: []) } - - before do - sign_in user, scope: :user - end - - describe 'GET #show' do - it 'returns http success' do - get :show - expect(response).to have_http_status(200) - end - end - - describe 'PUT #update' do - it 'updates the user record' do - put :update, params: { user: { locale: 'en', chosen_languages: ['es', 'fr', ''] } } - - expect(response).to redirect_to(settings_preferences_path) - user.reload - expect(user.locale).to eq 'en' - expect(user.chosen_languages).to eq ['es', 'fr'] - end - - it 'updates user settings' do - user.settings['boost_modal'] = false - user.settings['delete_modal'] = true - - put :update, params: { - user: { - setting_boost_modal: '1', - setting_delete_modal: '0', - } - } - - expect(response).to redirect_to(settings_preferences_path) - user.reload - expect(user.settings['boost_modal']).to be true - expect(user.settings['delete_modal']).to be false - end - end -end -- cgit