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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 5 deletions

View file

@ -105,6 +105,7 @@ Rails/UniqueValidationWithoutIndex:
Exclude:
- 'app/models/channel/twitter_profile.rb'
- 'app/models/webhook.rb'
- 'app/models/contact.rb'
Rails/RenderInline:
Exclude:
- 'app/controllers/swagger_controller.rb'

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

View file

@ -4,7 +4,7 @@ FactoryBot.define do
factory :contact do
sequence(:name) { |n| "Contact #{n}" }
sequence(:email) { |n| "contact-#{n}@example.com" }
phone_number { '+123456789011' }
phone_number { Faker::PhoneNumber.cell_phone_in_e164 }
avatar { fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png') }
account
end