mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 03:27:52 +00:00
- adds an audit log when an agent is added or removed from a team - adds an audit log when an agent is added or removed from an inbox Co-authored-by: Sojan Jose <sojan@pepalo.com>
40 lines
1.0 KiB
Ruby
40 lines
1.0 KiB
Ruby
# == Schema Information
|
|
#
|
|
# Table name: inbox_members
|
|
#
|
|
# id :integer not null, primary key
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
# inbox_id :integer not null
|
|
# user_id :integer not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_inbox_members_on_inbox_id (inbox_id)
|
|
# index_inbox_members_on_inbox_id_and_user_id (inbox_id,user_id) UNIQUE
|
|
#
|
|
|
|
class InboxMember < ApplicationRecord
|
|
validates :inbox_id, presence: true
|
|
validates :user_id, presence: true
|
|
validates :user_id, uniqueness: { scope: :inbox_id }
|
|
|
|
belongs_to :user
|
|
belongs_to :inbox
|
|
|
|
after_create :add_agent_to_round_robin
|
|
after_destroy :remove_agent_from_round_robin
|
|
|
|
private
|
|
|
|
def add_agent_to_round_robin
|
|
::AutoAssignment::InboxRoundRobinService.new(inbox: inbox).add_agent_to_queue(user_id)
|
|
end
|
|
|
|
def remove_agent_from_round_robin
|
|
::AutoAssignment::InboxRoundRobinService.new(inbox: inbox).remove_agent_from_queue(user_id) if inbox.present?
|
|
end
|
|
end
|
|
|
|
InboxMember.include_mod_with('Audit::InboxMember')
|