Separate notifications preferences from general preferences (#4447)
* Separate notifications preferences from general preferences * Refine settings/notifications/show * remove preferences.notificationsth-downstream
parent
dee5c22790
commit
6bd4e3bf97
@ -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
|
@ -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
|
@ -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
|
Loading…
Reference in new issue