mirror of
https://github.com/lingble/chatwoot.git
synced 2025-10-29 10:12:34 +00:00
fix: Current.user nil issue when using access tokens (#2012)
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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?
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user