mirror of
https://github.com/lingble/chatwoot.git
synced 2025-10-30 10:42:38 +00:00
fix: Current.user nil issue when using access tokens (#2012)
This commit is contained in:
@@ -105,6 +105,7 @@ Rails/UniqueValidationWithoutIndex:
|
|||||||
Exclude:
|
Exclude:
|
||||||
- 'app/models/channel/twitter_profile.rb'
|
- 'app/models/channel/twitter_profile.rb'
|
||||||
- 'app/models/webhook.rb'
|
- 'app/models/webhook.rb'
|
||||||
|
- 'app/models/contact.rb'
|
||||||
Rails/RenderInline:
|
Rails/RenderInline:
|
||||||
Exclude:
|
Exclude:
|
||||||
- 'app/controllers/swagger_controller.rb'
|
- 'app/controllers/swagger_controller.rb'
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ class Api::V1::Accounts::Contacts::ConversationsController < Api::V1::Accounts::
|
|||||||
private
|
private
|
||||||
|
|
||||||
def inbox_ids
|
def inbox_ids
|
||||||
if current_user.administrator?
|
if Current.user.administrator?
|
||||||
Current.account.inboxes.pluck(:id)
|
Current.account.inboxes.pluck(:id)
|
||||||
elsif current_user.agent?
|
elsif Current.user.agent?
|
||||||
current_user.assigned_inboxes.pluck(:id)
|
Current.user.assigned_inboxes.pluck(:id)
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ module AccessTokenAuthHelper
|
|||||||
render_unauthorized('Invalid Access Token') && return if @access_token.blank?
|
render_unauthorized('Invalid Access Token') && return if @access_token.blank?
|
||||||
|
|
||||||
@resource = @access_token.owner
|
@resource = @access_token.owner
|
||||||
|
Current.user = @resource if current_user.is_a?(User)
|
||||||
end
|
end
|
||||||
|
|
||||||
def super_admin?
|
def super_admin?
|
||||||
@@ -21,7 +22,7 @@ module AccessTokenAuthHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def validate_bot_access_token!
|
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 super_admin?
|
||||||
return if agent_bot_accessible?
|
return if agent_bot_accessible?
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class Contact < ApplicationRecord
|
|||||||
validates :account_id, presence: true
|
validates :account_id, presence: true
|
||||||
validates :email, allow_blank: true, uniqueness: { scope: [:account_id], case_sensitive: false }
|
validates :email, allow_blank: true, uniqueness: { scope: [:account_id], case_sensitive: false }
|
||||||
validates :identifier, allow_blank: true, uniqueness: { scope: [:account_id] }
|
validates :identifier, allow_blank: true, uniqueness: { scope: [:account_id] }
|
||||||
|
validates :phone_number, allow_blank: true, uniqueness: { scope: [:account_id] }
|
||||||
|
|
||||||
belongs_to :account
|
belongs_to :account
|
||||||
has_many :conversations, dependent: :destroy
|
has_many :conversations, dependent: :destroy
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ FactoryBot.define do
|
|||||||
factory :contact do
|
factory :contact do
|
||||||
sequence(:name) { |n| "Contact #{n}" }
|
sequence(:name) { |n| "Contact #{n}" }
|
||||||
sequence(:email) { |n| "contact-#{n}@example.com" }
|
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') }
|
avatar { fixture_file_upload(Rails.root.join('spec/assets/avatar.png'), 'image/png') }
|
||||||
account
|
account
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user