chore: Add controllers for conversation participants (#6462)

Co-authored-by: Aswin Dev P.S <aswindevps@gmail.com>
Co-authored-by: Sojan Jose <sojan@chatwoot.com>
This commit is contained in:
Pranav Raj S
2023-02-15 16:33:31 -08:00
committed by GitHub
parent 949ddf68ba
commit 7044eda281
34 changed files with 546 additions and 63 deletions

View File

@@ -48,6 +48,7 @@ class User < ApplicationRecord
include Rails.application.routes.url_helpers
include Reportable
include SsoAuthenticatable
include UserAttributeHelpers
devise :database_authenticatable,
:registerable,
@@ -76,6 +77,8 @@ class User < ApplicationRecord
has_many :assigned_conversations, foreign_key: 'assignee_id', class_name: 'Conversation', dependent: :nullify
alias_attribute :conversations, :assigned_conversations
has_many :csat_survey_responses, foreign_key: 'assigned_agent_id', dependent: :nullify
has_many :conversation_participants, dependent: :destroy_async
has_many :participating_conversations, through: :conversation_participants, source: :conversation
has_many :inbox_members, dependent: :destroy_async
has_many :inboxes, through: :inbox_members, source: :inbox
@@ -110,60 +113,10 @@ class User < ApplicationRecord
self.uid = email
end
def active_account_user
account_users.order(active_at: :desc)&.first
end
def current_account_user
# We want to avoid subsequent queries in case where the association is preloaded.
# using where here will trigger n+1 queries.
account_users.find { |ac_usr| ac_usr.account_id == Current.account.id } if Current.account
end
def available_name
self[:display_name].presence || name
end
# Used internally for Chatwoot in Chatwoot
def hmac_identifier
hmac_key = GlobalConfig.get('CHATWOOT_INBOX_HMAC_KEY')['CHATWOOT_INBOX_HMAC_KEY']
return OpenSSL::HMAC.hexdigest('sha256', hmac_key, email) if hmac_key.present?
''
end
def account
current_account_user&.account
end
def assigned_inboxes
administrator? ? Current.account.inboxes : inboxes.where(account_id: Current.account.id)
end
def administrator?
current_account_user&.administrator?
end
def agent?
current_account_user&.agent?
end
def role
current_account_user&.role
end
def availability_status
current_account_user&.availability_status
end
def auto_offline
current_account_user&.auto_offline
end
def inviter
current_account_user&.inviter
end
def serializable_hash(options = nil)
super(options).merge(confirmed: confirmed?)
end