mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-23 21:15:05 +01:00
Separate notifications preferences from general preferences (#4447)
* Separate notifications preferences from general preferences * Refine settings/notifications/show * remove preferences.notifications
This commit is contained in:
parent
0e1b0f2747
commit
178f718a9b
32
app/controllers/settings/notifications_controller.rb
Normal file
32
app/controllers/settings/notifications_controller.rb
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Settings::NotificationsController < ApplicationController
|
||||||
|
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),
|
||||||
|
interactions: %i(must_be_follower must_be_following)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
@ -15,17 +15,17 @@ class UserSettingsDecorator
|
|||||||
private
|
private
|
||||||
|
|
||||||
def process_update
|
def process_update
|
||||||
user.settings['notification_emails'] = merged_notification_emails
|
user.settings['notification_emails'] = merged_notification_emails if change?('notification_emails')
|
||||||
user.settings['interactions'] = merged_interactions
|
user.settings['interactions'] = merged_interactions if change?('interactions')
|
||||||
user.settings['default_privacy'] = default_privacy_preference
|
user.settings['default_privacy'] = default_privacy_preference if change?('setting_default_privacy')
|
||||||
user.settings['default_sensitive'] = default_sensitive_preference
|
user.settings['default_sensitive'] = default_sensitive_preference if change?('setting_default_sensitive')
|
||||||
user.settings['unfollow_modal'] = unfollow_modal_preference
|
user.settings['unfollow_modal'] = unfollow_modal_preference if change?('setting_unfollow_modal')
|
||||||
user.settings['boost_modal'] = boost_modal_preference
|
user.settings['boost_modal'] = boost_modal_preference if change?('setting_boost_modal')
|
||||||
user.settings['delete_modal'] = delete_modal_preference
|
user.settings['delete_modal'] = delete_modal_preference if change?('setting_delete_modal')
|
||||||
user.settings['auto_play_gif'] = auto_play_gif_preference
|
user.settings['auto_play_gif'] = auto_play_gif_preference if change?('setting_auto_play_gif')
|
||||||
user.settings['system_font_ui'] = system_font_ui_preference
|
user.settings['system_font_ui'] = system_font_ui_preference if change?('setting_system_font_ui')
|
||||||
user.settings['noindex'] = noindex_preference
|
user.settings['noindex'] = noindex_preference if change?('setting_noindex')
|
||||||
user.settings['theme'] = theme_preference
|
user.settings['theme'] = theme_preference if change?('theme')
|
||||||
end
|
end
|
||||||
|
|
||||||
def merged_notification_emails
|
def merged_notification_emails
|
||||||
@ -83,4 +83,8 @@ class UserSettingsDecorator
|
|||||||
def coerce_values(params_hash)
|
def coerce_values(params_hash)
|
||||||
params_hash.transform_values { |x| x == '1' }
|
params_hash.transform_values { |x| x == '1' }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def change?(key)
|
||||||
|
!settings[key].nil?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
25
app/views/settings/notifications/show.html.haml
Normal file
25
app/views/settings/notifications/show.html.haml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
- content_for :page_title do
|
||||||
|
= t('settings.notifications')
|
||||||
|
|
||||||
|
= simple_form_for current_user, url: settings_notifications_path, html: { method: :put } do |f|
|
||||||
|
= render 'shared/error_messages', object: current_user
|
||||||
|
|
||||||
|
.fields-group
|
||||||
|
= f.simple_fields_for :notification_emails, hash_to_object(current_user.settings.notification_emails) do |ff|
|
||||||
|
= ff.input :follow, as: :boolean, wrapper: :with_label
|
||||||
|
= ff.input :follow_request, as: :boolean, wrapper: :with_label
|
||||||
|
= ff.input :reblog, as: :boolean, wrapper: :with_label
|
||||||
|
= ff.input :favourite, as: :boolean, wrapper: :with_label
|
||||||
|
= ff.input :mention, as: :boolean, wrapper: :with_label
|
||||||
|
|
||||||
|
.fields-group
|
||||||
|
= f.simple_fields_for :notification_emails, hash_to_object(current_user.settings.notification_emails) do |ff|
|
||||||
|
= ff.input :digest, as: :boolean, wrapper: :with_label
|
||||||
|
|
||||||
|
.fields-group
|
||||||
|
= f.simple_fields_for :interactions, hash_to_object(current_user.settings.interactions) do |ff|
|
||||||
|
= ff.input :must_be_follower, as: :boolean, wrapper: :with_label
|
||||||
|
= ff.input :must_be_following, as: :boolean, wrapper: :with_label
|
||||||
|
|
||||||
|
.actions
|
||||||
|
= f.button :button, t('generic.save_changes'), type: :submit
|
@ -18,25 +18,6 @@
|
|||||||
|
|
||||||
= f.input :setting_default_sensitive, as: :boolean, wrapper: :with_label
|
= f.input :setting_default_sensitive, as: :boolean, wrapper: :with_label
|
||||||
|
|
||||||
%h4= t 'preferences.notifications'
|
|
||||||
|
|
||||||
.fields-group
|
|
||||||
= f.simple_fields_for :notification_emails, hash_to_object(current_user.settings.notification_emails) do |ff|
|
|
||||||
= ff.input :follow, as: :boolean, wrapper: :with_label
|
|
||||||
= ff.input :follow_request, as: :boolean, wrapper: :with_label
|
|
||||||
= ff.input :reblog, as: :boolean, wrapper: :with_label
|
|
||||||
= ff.input :favourite, as: :boolean, wrapper: :with_label
|
|
||||||
= ff.input :mention, as: :boolean, wrapper: :with_label
|
|
||||||
|
|
||||||
.fields-group
|
|
||||||
= f.simple_fields_for :notification_emails, hash_to_object(current_user.settings.notification_emails) do |ff|
|
|
||||||
= ff.input :digest, as: :boolean, wrapper: :with_label
|
|
||||||
|
|
||||||
.fields-group
|
|
||||||
= f.simple_fields_for :interactions, hash_to_object(current_user.settings.interactions) do |ff|
|
|
||||||
= ff.input :must_be_follower, as: :boolean, wrapper: :with_label
|
|
||||||
= ff.input :must_be_following, as: :boolean, wrapper: :with_label
|
|
||||||
|
|
||||||
%h4= t 'preferences.other'
|
%h4= t 'preferences.other'
|
||||||
|
|
||||||
.fields-group
|
.fields-group
|
||||||
|
@ -319,7 +319,6 @@ de:
|
|||||||
truncate: "…"
|
truncate: "…"
|
||||||
preferences:
|
preferences:
|
||||||
languages: Sprachen
|
languages: Sprachen
|
||||||
notifications: Benachrichtigungen
|
|
||||||
other: Weiteres
|
other: Weiteres
|
||||||
publishing: Beiträge
|
publishing: Beiträge
|
||||||
web: Web
|
web: Web
|
||||||
@ -390,6 +389,7 @@ de:
|
|||||||
export: Datenexport
|
export: Datenexport
|
||||||
followers: Autorisierte Folgende
|
followers: Autorisierte Folgende
|
||||||
import: Datenimport
|
import: Datenimport
|
||||||
|
notifications: Benachrichtigungen
|
||||||
preferences: Einstellungen
|
preferences: Einstellungen
|
||||||
settings: Einstellungen
|
settings: Einstellungen
|
||||||
two_factor_authentication: Zwei-Faktor-Authentisierung
|
two_factor_authentication: Zwei-Faktor-Authentisierung
|
||||||
|
@ -395,7 +395,6 @@ en:
|
|||||||
truncate: "…"
|
truncate: "…"
|
||||||
preferences:
|
preferences:
|
||||||
languages: Languages
|
languages: Languages
|
||||||
notifications: Notifications
|
|
||||||
other: Other
|
other: Other
|
||||||
publishing: Publishing
|
publishing: Publishing
|
||||||
web: Web
|
web: Web
|
||||||
@ -466,6 +465,7 @@ en:
|
|||||||
export: Data export
|
export: Data export
|
||||||
followers: Authorized followers
|
followers: Authorized followers
|
||||||
import: Import
|
import: Import
|
||||||
|
notifications: Notifications
|
||||||
preferences: Preferences
|
preferences: Preferences
|
||||||
settings: Settings
|
settings: Settings
|
||||||
two_factor_authentication: Two-factor Authentication
|
two_factor_authentication: Two-factor Authentication
|
||||||
|
@ -395,7 +395,6 @@ ja:
|
|||||||
truncate: "…"
|
truncate: "…"
|
||||||
preferences:
|
preferences:
|
||||||
languages: 言語
|
languages: 言語
|
||||||
notifications: 通知
|
|
||||||
other: その他
|
other: その他
|
||||||
publishing: 投稿
|
publishing: 投稿
|
||||||
web: ウェブ
|
web: ウェブ
|
||||||
@ -466,6 +465,7 @@ ja:
|
|||||||
export: データのエクスポート
|
export: データのエクスポート
|
||||||
followers: 信頼済みのインスタンス
|
followers: 信頼済みのインスタンス
|
||||||
import: データのインポート
|
import: データのインポート
|
||||||
|
notifications: 通知
|
||||||
preferences: ユーザー設定
|
preferences: ユーザー設定
|
||||||
settings: 設定
|
settings: 設定
|
||||||
two_factor_authentication: 二段階認証
|
two_factor_authentication: 二段階認証
|
||||||
|
@ -393,7 +393,6 @@ ko:
|
|||||||
truncate: "…"
|
truncate: "…"
|
||||||
preferences:
|
preferences:
|
||||||
languages: 언어
|
languages: 언어
|
||||||
notifications: 알림
|
|
||||||
other: 기타
|
other: 기타
|
||||||
publishing: 퍼블리싱
|
publishing: 퍼블리싱
|
||||||
web: 웹
|
web: 웹
|
||||||
@ -464,6 +463,7 @@ ko:
|
|||||||
export: 데이터 내보내기
|
export: 데이터 내보내기
|
||||||
followers: 신뢰 중인 인스턴스
|
followers: 신뢰 중인 인스턴스
|
||||||
import: 데이터 가져오기
|
import: 데이터 가져오기
|
||||||
|
notifications: 알림
|
||||||
preferences: 사용자 설정
|
preferences: 사용자 설정
|
||||||
settings: 설정
|
settings: 설정
|
||||||
two_factor_authentication: 2단계 인증
|
two_factor_authentication: 2단계 인증
|
||||||
|
@ -473,7 +473,6 @@ oc:
|
|||||||
truncate: "…"
|
truncate: "…"
|
||||||
preferences:
|
preferences:
|
||||||
languages: Lengas
|
languages: Lengas
|
||||||
notifications: Notificacions
|
|
||||||
other: Autre
|
other: Autre
|
||||||
publishing: Publicar
|
publishing: Publicar
|
||||||
web: Interfàcia Web
|
web: Interfàcia Web
|
||||||
@ -544,6 +543,7 @@ oc:
|
|||||||
export: Export donadas
|
export: Export donadas
|
||||||
followers: Seguidors autorizats
|
followers: Seguidors autorizats
|
||||||
import: Importar
|
import: Importar
|
||||||
|
notifications: Notificacions
|
||||||
preferences: Preferéncias
|
preferences: Preferéncias
|
||||||
settings: Paramètres
|
settings: Paramètres
|
||||||
two_factor_authentication: Autentificacion en dos temps
|
two_factor_authentication: Autentificacion en dos temps
|
||||||
|
@ -396,7 +396,6 @@ pl:
|
|||||||
truncate: "…"
|
truncate: "…"
|
||||||
preferences:
|
preferences:
|
||||||
languages: Języki
|
languages: Języki
|
||||||
notifications: Powiadomienia
|
|
||||||
other: Pozostałe
|
other: Pozostałe
|
||||||
publishing: Publikowanie
|
publishing: Publikowanie
|
||||||
web: Sieć
|
web: Sieć
|
||||||
@ -467,6 +466,7 @@ pl:
|
|||||||
export: Eksportowanie danych
|
export: Eksportowanie danych
|
||||||
followers: Autoryzowani śledzący
|
followers: Autoryzowani śledzący
|
||||||
import: Importowanie danych
|
import: Importowanie danych
|
||||||
|
notifications: Powiadomienia
|
||||||
preferences: Preferencje
|
preferences: Preferencje
|
||||||
settings: Ustawienia
|
settings: Ustawienia
|
||||||
two_factor_authentication: Uwierzytelnianie dwuetapowe
|
two_factor_authentication: Uwierzytelnianie dwuetapowe
|
||||||
|
@ -7,6 +7,7 @@ SimpleNavigation::Configuration.run do |navigation|
|
|||||||
primary.item :settings, safe_join([fa_icon('cog fw'), t('settings.settings')]), settings_profile_url do |settings|
|
primary.item :settings, safe_join([fa_icon('cog fw'), t('settings.settings')]), settings_profile_url do |settings|
|
||||||
settings.item :profile, safe_join([fa_icon('user fw'), t('settings.edit_profile')]), settings_profile_url
|
settings.item :profile, safe_join([fa_icon('user fw'), t('settings.edit_profile')]), settings_profile_url
|
||||||
settings.item :preferences, safe_join([fa_icon('sliders fw'), t('settings.preferences')]), settings_preferences_url
|
settings.item :preferences, safe_join([fa_icon('sliders fw'), t('settings.preferences')]), settings_preferences_url
|
||||||
|
settings.item :notifications, safe_join([fa_icon('bell fw'), t('settings.notifications')]), settings_notifications_url
|
||||||
settings.item :password, safe_join([fa_icon('lock fw'), t('auth.change_password')]), edit_user_registration_url, highlights_on: %r{/auth/edit|/settings/delete}
|
settings.item :password, safe_join([fa_icon('lock fw'), t('auth.change_password')]), edit_user_registration_url, highlights_on: %r{/auth/edit|/settings/delete}
|
||||||
settings.item :two_factor_authentication, safe_join([fa_icon('mobile fw'), t('settings.two_factor_authentication')]), settings_two_factor_authentication_url, highlights_on: %r{/settings/two_factor_authentication}
|
settings.item :two_factor_authentication, safe_join([fa_icon('mobile fw'), t('settings.two_factor_authentication')]), settings_two_factor_authentication_url, highlights_on: %r{/settings/two_factor_authentication}
|
||||||
settings.item :import, safe_join([fa_icon('cloud-upload fw'), t('settings.import')]), settings_import_url
|
settings.item :import, safe_join([fa_icon('cloud-upload fw'), t('settings.import')]), settings_import_url
|
||||||
|
@ -67,6 +67,7 @@ Rails.application.routes.draw do
|
|||||||
namespace :settings do
|
namespace :settings do
|
||||||
resource :profile, only: [:show, :update]
|
resource :profile, only: [:show, :update]
|
||||||
resource :preferences, only: [:show, :update]
|
resource :preferences, only: [:show, :update]
|
||||||
|
resource :notifications, only: [:show, :update]
|
||||||
resource :import, only: [:show, :create]
|
resource :import, only: [:show, :create]
|
||||||
|
|
||||||
resource :export, only: [:show]
|
resource :export, only: [:show]
|
||||||
|
37
spec/controllers/settings/notifications_controller_spec.rb
Normal file
37
spec/controllers/settings/notifications_controller_spec.rb
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe Settings::NotificationsController do
|
||||||
|
render_views
|
||||||
|
|
||||||
|
let(:user) { Fabricate(:user) }
|
||||||
|
|
||||||
|
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(:success)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'PUT #update' do
|
||||||
|
it 'updates notifications settings' do
|
||||||
|
user.settings['notification_emails'] = user.settings['notification_emails'].merge('follow' => false)
|
||||||
|
user.settings['interactions'] = user.settings['interactions'].merge('must_be_follower' => true)
|
||||||
|
|
||||||
|
put :update, params: {
|
||||||
|
user: {
|
||||||
|
notification_emails: { follow: '1' },
|
||||||
|
interactions: { must_be_follower: '0' },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(response).to redirect_to(settings_notifications_path)
|
||||||
|
user.reload
|
||||||
|
expect(user.settings['notification_emails']['follow']).to be true
|
||||||
|
expect(user.settings['interactions']['must_be_follower']).to be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -29,15 +29,11 @@ describe Settings::PreferencesController do
|
|||||||
it 'updates user settings' do
|
it 'updates user settings' do
|
||||||
user.settings['boost_modal'] = false
|
user.settings['boost_modal'] = false
|
||||||
user.settings['delete_modal'] = true
|
user.settings['delete_modal'] = true
|
||||||
user.settings['notification_emails'] = user.settings['notification_emails'].merge('follow' => false)
|
|
||||||
user.settings['interactions'] = user.settings['interactions'].merge('must_be_follower' => true)
|
|
||||||
|
|
||||||
put :update, params: {
|
put :update, params: {
|
||||||
user: {
|
user: {
|
||||||
setting_boost_modal: '1',
|
setting_boost_modal: '1',
|
||||||
setting_delete_modal: '0',
|
setting_delete_modal: '0',
|
||||||
notification_emails: { follow: '1' },
|
|
||||||
interactions: { must_be_follower: '0' },
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,8 +41,6 @@ describe Settings::PreferencesController do
|
|||||||
user.reload
|
user.reload
|
||||||
expect(user.settings['boost_modal']).to be true
|
expect(user.settings['boost_modal']).to be true
|
||||||
expect(user.settings['delete_modal']).to be false
|
expect(user.settings['delete_modal']).to be false
|
||||||
expect(user.settings['notification_emails']['follow']).to be true
|
|
||||||
expect(user.settings['interactions']['must_be_follower']).to be false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user