feat: Ability for super admin to impersonate a user (#6382)

This commit is contained in:
Sojan Jose
2023-02-07 00:30:08 +05:30
committed by GitHub
parent 0a2d3130e0
commit 6b839a0442
6 changed files with 46 additions and 4 deletions

View File

@@ -3,7 +3,7 @@
### Usage #####
#
# # Seed an account with all data types in this class
# Seeders::AccountSeeder.new(account: @Account.find(1)).perform!
# Seeders::AccountSeeder.new(account: Account.find(1)).perform!
#
#
############################################################
@@ -89,16 +89,25 @@ class Seeders::AccountSeeder
conversation = contact_inbox.conversations.create!(account: contact_inbox.inbox.account, contact: contact_inbox.contact,
inbox: contact_inbox.inbox, assignee: assignee)
create_messages(conversation: conversation, messages: conversation_data['messages'])
conversation.update_labels(conversation_data[:labels]) if conversation_data[:labels].present?
end
def create_messages(conversation:, messages:)
messages.each do |message_data|
sender = User.find_by(email: message_data['sender']) if message_data['sender'].present?
sender = find_message_sender(conversation, message_data)
conversation.messages.create!(message_data.slice('content', 'message_type').merge(account: conversation.inbox.account, sender: sender,
inbox: conversation.inbox))
end
end
def find_message_sender(conversation, message_data)
if message_data['message_type'] == 'incoming'
User.find_by(email: message_data['sender']) if message_data['sender'].present?
else
conversation.contact
end
end
def seed_inboxes
Seeders::InboxSeeder.new(account: @account, company_data: @account_data[:company]).perform!
end

View File

@@ -222,6 +222,7 @@ contacts:
gender: 'male'
conversations:
- channel: Channel::Whatsapp
source_id: "123456723"
messages:
- message_type: incoming
content: hello world
@@ -263,6 +264,7 @@ contacts:
gender: 'male'
conversations:
- channel: Channel::Whatsapp
source_id: "12323432"
messages:
- message_type: incoming
content: hello world
@@ -271,6 +273,7 @@ contacts:
gender: 'male'
conversations:
- channel: Channel::Whatsapp
source_id: "12342234324"
messages:
- message_type: incoming
content: hello world
@@ -330,6 +333,12 @@ contacts:
gender: 'female'
conversations:
- channel: Channel::Whatsapp
source_id: "1223423567"
labels:
- billing
- delivery
- ops-handover
- premium-customer
messages:
- message_type: incoming
content: "Hey \n I didn't get the product delivered, but it shows it is delivered to my address. Please check"
@@ -338,6 +347,9 @@ contacts:
gender: 'male'
conversations:
- channel: Channel::WebWidget
labels:
- software
- ops-handover
messages:
- message_type: incoming
content: "Hey there, \n I need some help with the product, my button is not working on the website."
@@ -347,6 +359,10 @@ contacts:
conversations:
- channel: Channel::WebWidget
assignee: michael_scott@paperlayer.test
labels:
- billing
- software
- lead
messages:
- message_type: incoming
content: "Hey, \n My card is not working on your website. Please help"
@@ -357,6 +373,9 @@ contacts:
- channel: Channel::Email
source_id: "cmathersonj@va.test"
assignee: michael_scott@paperlayer.test
labels:
- billing
- lead
messages:
- message_type: incoming
content: "Hey, \n I'm looking for some help to figure out if it is the right product for me."