docbrown/app/models/users/notification_setting.rb
Ridhwana 686976ced8
Round Robin Notifications Refactor (#19026)
* chore: rubocop

* feat: rename the worker in accordance to our guidelines and to be more verbose

* refactor: move the NotificationsModeration service to be a users query, and move the constants out to new files

* refactor: removed subscribed_to_mod_roundrobin_notifications? which was only being used once in a test

* refactor: remove the aliass from the user method and add them to notification_setting + update references
2023-02-01 15:21:36 +02:00

26 lines
975 B
Ruby

module Users
# @note When we destroy the related user, it's using dependent:
# :delete for the relationship. That means no before/after
# destroy callbacks will be called on this object.
class NotificationSetting < ApplicationRecord
self.table_name_prefix = "users_"
self.ignored_columns += %w[email_connect_messages]
belongs_to :user, touch: true
validates :email_digest_periodic, inclusion: { in: [true, false] }
alias_attribute :subscribed_to_welcome_notifications?, :welcome_notifications
alias_attribute :subscribed_to_email_follower_notifications?, :email_follower_notifications
after_commit :subscribe_to_mailchimp_newsletter
def subscribe_to_mailchimp_newsletter
return if Settings::General.mailchimp_api_key.blank?
return unless saved_changes.key?(:email_newsletter)
return if user.email.blank?
Users::SubscribeToMailchimpNewsletterWorker.perform_async(user.id)
end
end
end