Feature: Add new notification settings for user (#569)
Added new notification settings API for user Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
@@ -24,6 +24,7 @@ class Account < ApplicationRecord
|
||||
has_many :canned_responses, dependent: :destroy
|
||||
has_many :webhooks, dependent: :destroy
|
||||
has_one :subscription, dependent: :destroy
|
||||
has_many :notification_settings, dependent: :destroy
|
||||
|
||||
after_create :create_subscription
|
||||
after_create :notify_creation
|
||||
|
||||
34
app/models/notification_setting.rb
Normal file
34
app/models/notification_setting.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: notification_settings
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# email_flags :integer default(0), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# account_id :integer
|
||||
# user_id :integer
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# by_account_user (account_id,user_id) UNIQUE
|
||||
#
|
||||
|
||||
class NotificationSetting < ApplicationRecord
|
||||
# used for single column multi flags
|
||||
include FlagShihTzu
|
||||
|
||||
belongs_to :account
|
||||
belongs_to :user
|
||||
|
||||
DEFAULT_QUERY_SETTING = {
|
||||
flag_query_mode: :bit_operator
|
||||
}.freeze
|
||||
|
||||
EMAIL_NOTIFCATION_FLAGS = {
|
||||
1 => :conversation_creation,
|
||||
2 => :conversation_assignment
|
||||
}.freeze
|
||||
|
||||
has_flags EMAIL_NOTIFCATION_FLAGS.merge(column: 'email_flags').merge(DEFAULT_QUERY_SETTING)
|
||||
end
|
||||
@@ -74,12 +74,13 @@ class User < ApplicationRecord
|
||||
has_many :inbox_members, dependent: :destroy
|
||||
has_many :assigned_inboxes, through: :inbox_members, source: :inbox
|
||||
has_many :messages
|
||||
has_many :notification_settings, dependent: :destroy
|
||||
|
||||
before_validation :set_password_and_uid, on: :create
|
||||
|
||||
accepts_nested_attributes_for :account
|
||||
|
||||
after_create :notify_creation
|
||||
after_create :notify_creation, :create_notification_setting
|
||||
after_destroy :notify_deletion
|
||||
|
||||
def send_devise_notification(notification, *args)
|
||||
@@ -100,6 +101,12 @@ class User < ApplicationRecord
|
||||
Rails.configuration.dispatcher.dispatch(AGENT_ADDED, Time.zone.now, account: account)
|
||||
end
|
||||
|
||||
def create_notification_setting
|
||||
setting = notification_settings.new(account_id: account_id)
|
||||
setting.selected_email_flags = [:conversation_assignment]
|
||||
setting.save!
|
||||
end
|
||||
|
||||
def notify_deletion
|
||||
Rails.configuration.dispatcher.dispatch(AGENT_REMOVED, Time.zone.now, account: account)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user