fix: Current.user nil issue when using access tokens (#2012)

This commit is contained in:
Sojan Jose
2021-03-29 23:26:20 +05:30
committed by GitHub
parent 24fea5fbe0
commit 6bb026621d
5 changed files with 8 additions and 5 deletions

View File

@@ -8,10 +8,10 @@ class Api::V1::Accounts::Contacts::ConversationsController < Api::V1::Accounts::
private
def inbox_ids
if current_user.administrator?
if Current.user.administrator?
Current.account.inboxes.pluck(:id)
elsif current_user.agent?
current_user.assigned_inboxes.pluck(:id)
elsif Current.user.agent?
Current.user.assigned_inboxes.pluck(:id)
else
[]
end

View File

@@ -14,6 +14,7 @@ module AccessTokenAuthHelper
render_unauthorized('Invalid Access Token') && return if @access_token.blank?
@resource = @access_token.owner
Current.user = @resource if current_user.is_a?(User)
end
def super_admin?
@@ -21,7 +22,7 @@ module AccessTokenAuthHelper
end
def validate_bot_access_token!
return if current_user.is_a?(User)
return if Current.user.is_a?(User)
return if super_admin?
return if agent_bot_accessible?

View File

@@ -31,6 +31,7 @@ class Contact < ApplicationRecord
validates :account_id, presence: true
validates :email, allow_blank: true, uniqueness: { scope: [:account_id], case_sensitive: false }
validates :identifier, allow_blank: true, uniqueness: { scope: [:account_id] }
validates :phone_number, allow_blank: true, uniqueness: { scope: [:account_id] }
belongs_to :account
has_many :conversations, dependent: :destroy