docbrown/app/controllers/users/notification_settings_controller.rb
Michael Kohl 09828853f6
✂✂✂ Remove Connect (#14734)
* Remove Connect

* Remove more Connect specs

* Remove a lot more Connect code

* 🚮

* It all has to go

* Explicitly add httpclient

* Update application layout

* Remove messages association from User

* Start fixing specs

* reintroduce util function and refactor references

* Remove Connect Cypress test

* Fix more specs

* Remove Connect from listings

* Ignore contact_via_connect column on listings

* Remove contact_via_connect usages

* Ignore mod_chat_channel_id on tags

* Drop Connect tables

* Remove email_connect_messages from user notification settings

* Re-add httpclient 2.8.3

This was mistakenly removed as a merge conflict

* Don't need to exclude removed chat channel file

* Remove unneeded style for chat channels

* Remove unneeded channel list prop type

* Remove chat channels index/connect-link from getPageEntries

* Re-add comment from httpclient in Gemfile

* Remove connect references from mailers

Tag Moderators no longer have a chat channel

No longer will users be notified about new messages (there won't be
any)

No longer will users be notified about channel invites (you can't
invite anyone anymore)

* Don't configure Pusher and remove PUSHER_* from .env_sample

since it's removed from gemfile, the Pusher constant will not resolve, if this is
configured in the environment variables we'll fail to boot.

Co-authored-by: Suzanne Aitchison <suzanne@forem.com>
Co-authored-by: Dan Uber <dan@forem.com>
2021-11-18 08:21:00 -06:00

62 lines
2.3 KiB
Ruby

module Users
class NotificationSettingsController < ApplicationController
before_action :raise_suspended
before_action :authenticate_user!
after_action :verify_authorized
ALLOWED_PARAMS = %i[email_badge_notifications
email_comment_notifications
email_community_mod_newsletter
email_digest_periodic
email_follower_notifications
email_membership_newsletter
email_mention_notifications
email_newsletter
email_tag_mod_newsletter
email_unread_notifications
mobile_comment_notifications
mod_roundrobin_notifications
reaction_notifications
welcome_notifications].freeze
ONBOARDING_ALLOWED_PARAMS = %i[email_newsletter email_digest_periodic].freeze
def update
authorize current_user, policy_class: UserPolicy
if current_user.notification_setting.update(users_notification_setting_params)
flash[:settings_notice] = "Your notification settings have been updated."
else
Honeycomb.add_field("error", current_user.notification_setting.errors.messages.compact_blank)
Honeycomb.add_field("errored", true)
flash[:error] = current_user.notification_setting.errors_as_sentence
end
redirect_to user_settings_path(:notifications)
end
def onboarding_notifications_checkbox_update
authorize User
if params[:notifications]
current_user.notification_setting.assign_attributes(params[:notifications].permit(ONBOARDING_ALLOWED_PARAMS))
end
current_user.saw_onboarding = true
success = current_user.notification_setting.save
render_update_response(success, current_user.notification_setting.errors_as_sentence)
end
private
def render_update_response(success, errors = nil)
status = success ? 200 : 422
respond_to do |format|
format.json { render json: { errors: errors }, status: status }
end
end
def users_notification_setting_params
params.require(:users_notification_setting).permit(ALLOWED_PARAMS)
end
end
end