Feature: Add ability to disable auto assignment of conversations (#513)
This commit is contained in:
parent
e0afb84502
commit
30e5edf6dc
15 changed files with 377 additions and 230 deletions
|
@ -1,6 +1,6 @@
|
|||
class Api::V1::InboxesController < Api::BaseController
|
||||
before_action :check_authorization
|
||||
before_action :fetch_inbox, only: [:destroy]
|
||||
before_action :fetch_inbox, only: [:destroy, :update]
|
||||
|
||||
def index
|
||||
@inboxes = policy_scope(current_account.inboxes)
|
||||
|
@ -11,6 +11,10 @@ class Api::V1::InboxesController < Api::BaseController
|
|||
head :ok
|
||||
end
|
||||
|
||||
def update
|
||||
@inbox.update(inbox_update_params)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fetch_inbox
|
||||
|
@ -20,4 +24,8 @@ class Api::V1::InboxesController < Api::BaseController
|
|||
def check_authorization
|
||||
authorize(Inbox)
|
||||
end
|
||||
|
||||
def inbox_update_params
|
||||
params.require(:inbox).permit(:enable_auto_assignment)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -74,7 +74,12 @@
|
|||
"EDIT": {
|
||||
"API": {
|
||||
"SUCCESS_MESSAGE": "Widget color updated successfully",
|
||||
"AUTO_ASSIGNMENT_SUCCESS_MESSAGE": "Auto assignment updated successfully",
|
||||
"ERROR_MESSAGE": "Could not update widget color. Please try again later."
|
||||
},
|
||||
"AUTO_ASSIGNMENT": {
|
||||
"ENABLED": "Enabled",
|
||||
"DISABLED": "Disabled"
|
||||
}
|
||||
},
|
||||
"DELETE": {
|
||||
|
@ -96,7 +101,9 @@
|
|||
"MESSENGER_SUB_HEAD": "Place this button inside your body tag",
|
||||
"INBOX_AGENTS": "Agents",
|
||||
"INBOX_AGENTS_SUB_TEXT": "Add or remove agents from this inbox",
|
||||
"UPDATE": "Update"
|
||||
"UPDATE": "Update",
|
||||
"AUTO_ASSIGNMENT": "Enable auto assignment",
|
||||
"AUTO_ASSIGNMENT_SUB_TEXT": "Enable or disable the automatic assignment of available agents on new conversations"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,6 +60,20 @@
|
|||
@select="$v.selectedAgents.$touch"
|
||||
/>
|
||||
</div>
|
||||
<div class="settings--content">
|
||||
<settings-form-header
|
||||
:title="$t('INBOX_MGMT.SETTINGS_POPUP.AUTO_ASSIGNMENT')"
|
||||
:sub-title="$t('INBOX_MGMT.SETTINGS_POPUP.AUTO_ASSIGNMENT_SUB_TEXT')"
|
||||
:button-text="$t('INBOX_MGMT.SETTINGS_POPUP.UPDATE')"
|
||||
:is-updating="uiFlags.isUpdatingAutoAssignment"
|
||||
@update="updateAutoAssignment"
|
||||
>
|
||||
</settings-form-header>
|
||||
<select v-model="autoAssignment">
|
||||
<option value="true">{{ $t('INBOX_MGMT.EDIT.AUTO_ASSIGNMENT.ENABLED') }}</option>
|
||||
<option value="false">{{ $t('INBOX_MGMT.EDIT.AUTO_ASSIGNMENT.DISABLED') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -82,6 +96,7 @@ export default {
|
|||
data() {
|
||||
return {
|
||||
selectedAgents: [],
|
||||
autoAssignment: false,
|
||||
isUpdating: false,
|
||||
isAgentListUpdating: false,
|
||||
};
|
||||
|
@ -123,6 +138,7 @@ export default {
|
|||
this.$store.dispatch('agents/get');
|
||||
this.$store.dispatch('inboxes/get').then(() => {
|
||||
this.fetchAttachedAgents();
|
||||
this.autoAssignment = this.inbox.enable_auto_assignment;
|
||||
});
|
||||
},
|
||||
async fetchAttachedAgents() {
|
||||
|
@ -172,6 +188,19 @@ export default {
|
|||
this.showAlert(this.$t('INBOX_MGMT.EDIT.API.SUCCESS_MESSAGE'));
|
||||
}
|
||||
},
|
||||
async updateAutoAssignment() {
|
||||
try {
|
||||
await this.$store.dispatch('inboxes/updateAutoAssignment', {
|
||||
id: this.currentInboxId,
|
||||
inbox: {
|
||||
enable_auto_assignment: this.autoAssignment,
|
||||
},
|
||||
});
|
||||
this.showAlert(this.$t('INBOX_MGMT.EDIT.API.AUTO_ASSIGNMENT_SUCCESS_MESSAGE'));
|
||||
} catch (error) {
|
||||
this.showAlert(this.$t('INBOX_MGMT.EDIT.API.AUTO_ASSIGNMENT_SUCCESS_MESSAGE'));
|
||||
}
|
||||
},
|
||||
getWidgetColor() {
|
||||
return typeof this.inbox.widget_color !== 'object'
|
||||
? this.inbox.widget_color
|
||||
|
|
|
@ -11,6 +11,7 @@ export const state = {
|
|||
isFetchingItem: false,
|
||||
isCreating: false,
|
||||
isUpdating: false,
|
||||
isUpdatingAutoAssignment: false,
|
||||
isDeleting: false,
|
||||
},
|
||||
};
|
||||
|
@ -76,6 +77,17 @@ export const actions = {
|
|||
throw new Error(error);
|
||||
}
|
||||
},
|
||||
updateAutoAssignment: async ({ commit }, { id, ...inboxParams }) => {
|
||||
commit(types.default.SET_INBOXES_UI_FLAG, { isUpdatingAutoAssignment: true });
|
||||
try {
|
||||
const response = await InboxesAPI.update(id, inboxParams);
|
||||
commit(types.default.EDIT_INBOXES, response.data);
|
||||
commit(types.default.SET_INBOXES_UI_FLAG, { isUpdatingAutoAssignment: false });
|
||||
} catch (error) {
|
||||
commit(types.default.SET_INBOXES_UI_FLAG, { isUpdatingAutoAssignment: false });
|
||||
throw new Error(error);
|
||||
}
|
||||
},
|
||||
delete: async ({ commit }, inboxId) => {
|
||||
commit(types.default.SET_INBOXES_UI_FLAG, { isDeleting: true });
|
||||
try {
|
||||
|
|
|
@ -92,6 +92,31 @@ describe('#actions', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('#updateAutoAssignment', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
let updatedInbox = inboxList[0];
|
||||
updatedInbox.enable_auto_assignment = false;
|
||||
|
||||
axios.patch.mockResolvedValue({ data: updatedInbox });
|
||||
await actions.updateAutoAssignment({ commit }, { id: updatedInbox.id, inbox: { enable_auto_assignment: false} });
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isUpdatingAutoAssignment: true }],
|
||||
[types.default.EDIT_INBOXES, updatedInbox],
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isUpdatingAutoAssignment: false }],
|
||||
]);
|
||||
});
|
||||
it('sends correct actions if API is error', async () => {
|
||||
axios.patch.mockRejectedValue({ message: 'Incorrect header' });
|
||||
await expect(
|
||||
actions.updateAutoAssignment({ commit }, { id: inboxList[0].id, inbox: { enable_auto_assignment: false} })
|
||||
).rejects.toThrow(Error);
|
||||
expect(commit.mock.calls).toEqual([
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isUpdatingAutoAssignment: true }],
|
||||
[types.default.SET_INBOXES_UI_FLAG, { isUpdatingAutoAssignment: false }],
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#delete', () => {
|
||||
it('sends correct actions if API is success', async () => {
|
||||
axios.delete.mockResolvedValue({ data: inboxList[0] });
|
||||
|
|
|
@ -8,6 +8,7 @@ export default [
|
|||
page_id: '12345',
|
||||
widget_color: null,
|
||||
website_token: null,
|
||||
enable_auto_assignment: true,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
|
@ -18,6 +19,7 @@ export default [
|
|||
page_id: null,
|
||||
widget_color: '#7B64FF',
|
||||
website_token: 'randomid123',
|
||||
enable_auto_assignment: true,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
|
@ -28,6 +30,7 @@ export default [
|
|||
page_id: null,
|
||||
widget_color: '#68BC00',
|
||||
website_token: 'randomid124',
|
||||
enable_auto_assignment: true,
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
|
@ -38,5 +41,6 @@ export default [
|
|||
page_id: null,
|
||||
widget_color: '#68BC00',
|
||||
website_token: 'randomid125',
|
||||
enable_auto_assignment: true,
|
||||
},
|
||||
];
|
||||
|
|
|
@ -22,6 +22,7 @@ describe('#getters', () => {
|
|||
page_id: '12345',
|
||||
widget_color: null,
|
||||
website_token: null,
|
||||
enable_auto_assignment: true,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -32,6 +33,7 @@ describe('#getters', () => {
|
|||
isFetchingItem: false,
|
||||
isCreating: false,
|
||||
isUpdating: false,
|
||||
isUpdatingAutoAssignment: false,
|
||||
isDeleting: false,
|
||||
},
|
||||
};
|
||||
|
@ -40,6 +42,7 @@ describe('#getters', () => {
|
|||
isFetchingItem: false,
|
||||
isCreating: false,
|
||||
isUpdating: false,
|
||||
isUpdatingAutoAssignment: false,
|
||||
isDeleting: false,
|
||||
});
|
||||
});
|
||||
|
|
|
@ -151,6 +151,7 @@ class Conversation < ApplicationRecord
|
|||
def run_round_robin
|
||||
# return unless conversation.account.has_feature?(round_robin)
|
||||
# return unless conversation.account.round_robin_enabled?
|
||||
return unless inbox.enable_auto_assignment
|
||||
return if assignee
|
||||
|
||||
inbox.next_available_agent.then { |new_assignee| update_assignee(new_assignee) }
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#
|
||||
# id :integer not null, primary key
|
||||
# channel_type :string
|
||||
# enable_auto_assignment :boolean default(TRUE)
|
||||
# name :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
|
|
|
@ -8,5 +8,6 @@ json.payload do
|
|||
json.page_id inbox.channel.try(:page_id)
|
||||
json.widget_color inbox.channel.try(:widget_color)
|
||||
json.website_token inbox.channel.try(:website_token)
|
||||
json.enable_auto_assignment inbox.enable_auto_assignment
|
||||
end
|
||||
end
|
||||
|
|
|
@ -44,7 +44,7 @@ Rails.application.routes.draw do
|
|||
|
||||
resource :profile, only: [:show, :update]
|
||||
resources :accounts, only: [:create]
|
||||
resources :inboxes, only: [:index, :destroy]
|
||||
resources :inboxes, only: [:index, :destroy, :update]
|
||||
resources :agents, except: [:show, :edit, :new]
|
||||
resources :labels, only: [:index] do
|
||||
collection do
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddEnableAutoAssignmentToInboxes < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
add_column :inboxes, :enable_auto_assignment, :boolean, default: true
|
||||
end
|
||||
end
|
440
db/schema.rb
440
db/schema.rb
|
@ -10,265 +10,267 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20_200_213_054_733) do
|
||||
ActiveRecord::Schema.define(version: 2020_02_17_192734) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension 'plpgsql'
|
||||
enable_extension "plpgsql"
|
||||
|
||||
create_table 'accounts', id: :serial, force: :cascade do |t|
|
||||
t.string 'name', null: false
|
||||
t.datetime 'created_at', null: false
|
||||
t.datetime 'updated_at', null: false
|
||||
create_table "accounts", id: :serial, force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table 'active_storage_attachments', force: :cascade do |t|
|
||||
t.string 'name', null: false
|
||||
t.string 'record_type', null: false
|
||||
t.bigint 'record_id', null: false
|
||||
t.bigint 'blob_id', null: false
|
||||
t.datetime 'created_at', null: false
|
||||
t.index ['blob_id'], name: 'index_active_storage_attachments_on_blob_id'
|
||||
t.index %w[record_type record_id name blob_id], name: 'index_active_storage_attachments_uniqueness', unique: true
|
||||
create_table "active_storage_attachments", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.string "record_type", null: false
|
||||
t.bigint "record_id", null: false
|
||||
t.bigint "blob_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
|
||||
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
|
||||
end
|
||||
|
||||
create_table 'active_storage_blobs', force: :cascade do |t|
|
||||
t.string 'key', null: false
|
||||
t.string 'filename', null: false
|
||||
t.string 'content_type'
|
||||
t.text 'metadata'
|
||||
t.bigint 'byte_size', null: false
|
||||
t.string 'checksum', null: false
|
||||
t.datetime 'created_at', null: false
|
||||
t.index ['key'], name: 'index_active_storage_blobs_on_key', unique: true
|
||||
create_table "active_storage_blobs", force: :cascade do |t|
|
||||
t.string "key", null: false
|
||||
t.string "filename", null: false
|
||||
t.string "content_type"
|
||||
t.text "metadata"
|
||||
t.bigint "byte_size", null: false
|
||||
t.string "checksum", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
|
||||
end
|
||||
|
||||
create_table 'attachments', id: :serial, force: :cascade do |t|
|
||||
t.integer 'file_type', default: 0
|
||||
t.string 'external_url'
|
||||
t.float 'coordinates_lat', default: 0.0
|
||||
t.float 'coordinates_long', default: 0.0
|
||||
t.integer 'message_id', null: false
|
||||
t.integer 'account_id', null: false
|
||||
t.datetime 'created_at', null: false
|
||||
t.datetime 'updated_at', null: false
|
||||
t.string 'fallback_title'
|
||||
t.string 'extension'
|
||||
create_table "attachments", id: :serial, force: :cascade do |t|
|
||||
t.integer "file_type", default: 0
|
||||
t.string "external_url"
|
||||
t.float "coordinates_lat", default: 0.0
|
||||
t.float "coordinates_long", default: 0.0
|
||||
t.integer "message_id", null: false
|
||||
t.integer "account_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "fallback_title"
|
||||
t.string "extension"
|
||||
end
|
||||
|
||||
create_table 'canned_responses', id: :serial, force: :cascade do |t|
|
||||
t.integer 'account_id', null: false
|
||||
t.string 'short_code'
|
||||
t.text 'content'
|
||||
t.datetime 'created_at', null: false
|
||||
t.datetime 'updated_at', null: false
|
||||
create_table "canned_responses", id: :serial, force: :cascade do |t|
|
||||
t.integer "account_id", null: false
|
||||
t.string "short_code"
|
||||
t.text "content"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table 'channel_facebook_pages', id: :serial, force: :cascade do |t|
|
||||
t.string 'name', null: false
|
||||
t.string 'page_id', null: false
|
||||
t.string 'user_access_token', null: false
|
||||
t.string 'page_access_token', null: false
|
||||
t.integer 'account_id', null: false
|
||||
t.datetime 'created_at', null: false
|
||||
t.datetime 'updated_at', null: false
|
||||
t.index %w[page_id account_id], name: 'index_channel_facebook_pages_on_page_id_and_account_id', unique: true
|
||||
t.index ['page_id'], name: 'index_channel_facebook_pages_on_page_id'
|
||||
create_table "channel_facebook_pages", id: :serial, force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.string "page_id", null: false
|
||||
t.string "user_access_token", null: false
|
||||
t.string "page_access_token", null: false
|
||||
t.integer "account_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["page_id", "account_id"], name: "index_channel_facebook_pages_on_page_id_and_account_id", unique: true
|
||||
t.index ["page_id"], name: "index_channel_facebook_pages_on_page_id"
|
||||
end
|
||||
|
||||
create_table 'channel_twitter_profiles', force: :cascade do |t|
|
||||
t.string 'name'
|
||||
t.string 'profile_id', null: false
|
||||
t.string 'twitter_access_token', null: false
|
||||
t.string 'twitter_access_token_secret', null: false
|
||||
t.integer 'account_id', null: false
|
||||
t.datetime 'created_at', precision: 6, null: false
|
||||
t.datetime 'updated_at', precision: 6, null: false
|
||||
create_table "channel_twitter_profiles", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "profile_id", null: false
|
||||
t.string "twitter_access_token", null: false
|
||||
t.string "twitter_access_token_secret", null: false
|
||||
t.integer "account_id", null: false
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
end
|
||||
|
||||
create_table 'channel_web_widgets', id: :serial, force: :cascade do |t|
|
||||
t.string 'website_name'
|
||||
t.string 'website_url'
|
||||
t.integer 'account_id'
|
||||
t.datetime 'created_at', null: false
|
||||
t.datetime 'updated_at', null: false
|
||||
t.string 'website_token'
|
||||
t.string 'widget_color', default: '#1f93ff'
|
||||
t.index ['website_token'], name: 'index_channel_web_widgets_on_website_token', unique: true
|
||||
create_table "channel_web_widgets", id: :serial, force: :cascade do |t|
|
||||
t.string "website_name"
|
||||
t.string "website_url"
|
||||
t.integer "account_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "website_token"
|
||||
t.string "widget_color", default: "#1f93ff"
|
||||
t.index ["website_token"], name: "index_channel_web_widgets_on_website_token", unique: true
|
||||
end
|
||||
|
||||
create_table 'contact_inboxes', force: :cascade do |t|
|
||||
t.bigint 'contact_id'
|
||||
t.bigint 'inbox_id'
|
||||
t.string 'source_id', null: false
|
||||
t.datetime 'created_at', precision: 6, null: false
|
||||
t.datetime 'updated_at', precision: 6, null: false
|
||||
t.index ['contact_id'], name: 'index_contact_inboxes_on_contact_id'
|
||||
t.index %w[inbox_id source_id], name: 'index_contact_inboxes_on_inbox_id_and_source_id', unique: true
|
||||
t.index ['inbox_id'], name: 'index_contact_inboxes_on_inbox_id'
|
||||
t.index ['source_id'], name: 'index_contact_inboxes_on_source_id'
|
||||
create_table "contact_inboxes", force: :cascade do |t|
|
||||
t.bigint "contact_id"
|
||||
t.bigint "inbox_id"
|
||||
t.string "source_id", null: false
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.index ["contact_id"], name: "index_contact_inboxes_on_contact_id"
|
||||
t.index ["inbox_id", "source_id"], name: "index_contact_inboxes_on_inbox_id_and_source_id", unique: true
|
||||
t.index ["inbox_id"], name: "index_contact_inboxes_on_inbox_id"
|
||||
t.index ["source_id"], name: "index_contact_inboxes_on_source_id"
|
||||
end
|
||||
|
||||
create_table 'contacts', id: :serial, force: :cascade do |t|
|
||||
t.string 'name'
|
||||
t.string 'email'
|
||||
t.string 'phone_number'
|
||||
t.integer 'account_id', null: false
|
||||
t.datetime 'created_at', null: false
|
||||
t.datetime 'updated_at', null: false
|
||||
t.string 'pubsub_token'
|
||||
t.jsonb 'additional_attributes'
|
||||
t.index ['account_id'], name: 'index_contacts_on_account_id'
|
||||
t.index ['pubsub_token'], name: 'index_contacts_on_pubsub_token', unique: true
|
||||
create_table "contacts", id: :serial, force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "email"
|
||||
t.string "phone_number"
|
||||
t.integer "account_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "pubsub_token"
|
||||
t.jsonb "additional_attributes"
|
||||
t.index ["account_id"], name: "index_contacts_on_account_id"
|
||||
t.index ["pubsub_token"], name: "index_contacts_on_pubsub_token", unique: true
|
||||
end
|
||||
|
||||
create_table 'conversations', id: :serial, force: :cascade do |t|
|
||||
t.integer 'account_id', null: false
|
||||
t.integer 'inbox_id', null: false
|
||||
t.integer 'status', default: 0, null: false
|
||||
t.integer 'assignee_id'
|
||||
t.datetime 'created_at', null: false
|
||||
t.datetime 'updated_at', null: false
|
||||
t.bigint 'contact_id'
|
||||
t.integer 'display_id', null: false
|
||||
t.datetime 'user_last_seen_at'
|
||||
t.datetime 'agent_last_seen_at'
|
||||
t.boolean 'locked', default: false
|
||||
t.jsonb 'additional_attributes'
|
||||
t.bigint 'contact_inbox_id'
|
||||
t.index %w[account_id display_id], name: 'index_conversations_on_account_id_and_display_id', unique: true
|
||||
t.index ['account_id'], name: 'index_conversations_on_account_id'
|
||||
t.index ['contact_inbox_id'], name: 'index_conversations_on_contact_inbox_id'
|
||||
create_table "conversations", id: :serial, force: :cascade do |t|
|
||||
t.integer "account_id", null: false
|
||||
t.integer "inbox_id", null: false
|
||||
t.integer "status", default: 0, null: false
|
||||
t.integer "assignee_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.bigint "contact_id"
|
||||
t.integer "display_id", null: false
|
||||
t.datetime "user_last_seen_at"
|
||||
t.datetime "agent_last_seen_at"
|
||||
t.boolean "locked", default: false
|
||||
t.jsonb "additional_attributes"
|
||||
t.bigint "contact_inbox_id"
|
||||
t.index ["account_id", "display_id"], name: "index_conversations_on_account_id_and_display_id", unique: true
|
||||
t.index ["account_id"], name: "index_conversations_on_account_id"
|
||||
t.index ["contact_inbox_id"], name: "index_conversations_on_contact_inbox_id"
|
||||
end
|
||||
|
||||
create_table 'inbox_members', id: :serial, force: :cascade do |t|
|
||||
t.integer 'user_id', null: false
|
||||
t.integer 'inbox_id', null: false
|
||||
t.datetime 'created_at', null: false
|
||||
t.datetime 'updated_at', null: false
|
||||
t.index ['inbox_id'], name: 'index_inbox_members_on_inbox_id'
|
||||
create_table "inbox_members", id: :serial, force: :cascade do |t|
|
||||
t.integer "user_id", null: false
|
||||
t.integer "inbox_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["inbox_id"], name: "index_inbox_members_on_inbox_id"
|
||||
end
|
||||
|
||||
create_table 'inboxes', id: :serial, force: :cascade do |t|
|
||||
t.integer 'channel_id', null: false
|
||||
t.integer 'account_id', null: false
|
||||
t.string 'name', null: false
|
||||
t.datetime 'created_at', null: false
|
||||
t.datetime 'updated_at', null: false
|
||||
t.string 'channel_type'
|
||||
t.index ['account_id'], name: 'index_inboxes_on_account_id'
|
||||
create_table "inboxes", id: :serial, force: :cascade do |t|
|
||||
t.integer "channel_id", null: false
|
||||
t.integer "account_id", null: false
|
||||
t.string "name", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "channel_type"
|
||||
t.boolean "enable_auto_assignment", default: true
|
||||
t.index ["account_id"], name: "index_inboxes_on_account_id"
|
||||
end
|
||||
|
||||
create_table 'messages', id: :serial, force: :cascade do |t|
|
||||
t.text 'content'
|
||||
t.integer 'account_id', null: false
|
||||
t.integer 'inbox_id', null: false
|
||||
t.integer 'conversation_id', null: false
|
||||
t.integer 'message_type', null: false
|
||||
t.datetime 'created_at', null: false
|
||||
t.datetime 'updated_at', null: false
|
||||
t.boolean 'private', default: false
|
||||
t.integer 'user_id'
|
||||
t.integer 'status', default: 0
|
||||
t.string 'source_id'
|
||||
t.integer 'content_type', default: 0
|
||||
t.json 'content_attributes', default: {}
|
||||
t.bigint 'contact_id'
|
||||
t.index ['contact_id'], name: 'index_messages_on_contact_id'
|
||||
t.index ['conversation_id'], name: 'index_messages_on_conversation_id'
|
||||
t.index ['source_id'], name: 'index_messages_on_source_id'
|
||||
create_table "messages", id: :serial, force: :cascade do |t|
|
||||
t.text "content"
|
||||
t.integer "account_id", null: false
|
||||
t.integer "inbox_id", null: false
|
||||
t.integer "conversation_id", null: false
|
||||
t.integer "message_type", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "private", default: false
|
||||
t.integer "user_id"
|
||||
t.integer "status", default: 0
|
||||
t.string "source_id"
|
||||
t.integer "content_type", default: 0
|
||||
t.json "content_attributes", default: {}
|
||||
t.bigint "contact_id"
|
||||
t.index ["contact_id"], name: "index_messages_on_contact_id"
|
||||
t.index ["conversation_id"], name: "index_messages_on_conversation_id"
|
||||
t.index ["source_id"], name: "index_messages_on_source_id"
|
||||
end
|
||||
|
||||
create_table 'subscriptions', id: :serial, force: :cascade do |t|
|
||||
t.string 'pricing_version'
|
||||
t.integer 'account_id'
|
||||
t.datetime 'expiry'
|
||||
t.string 'billing_plan', default: 'trial'
|
||||
t.string 'stripe_customer_id'
|
||||
t.datetime 'created_at', null: false
|
||||
t.datetime 'updated_at', null: false
|
||||
t.integer 'state', default: 0
|
||||
t.boolean 'payment_source_added', default: false
|
||||
create_table "subscriptions", id: :serial, force: :cascade do |t|
|
||||
t.string "pricing_version"
|
||||
t.integer "account_id"
|
||||
t.datetime "expiry"
|
||||
t.string "billing_plan", default: "trial"
|
||||
t.string "stripe_customer_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "state", default: 0
|
||||
t.boolean "payment_source_added", default: false
|
||||
end
|
||||
|
||||
create_table 'taggings', id: :serial, force: :cascade do |t|
|
||||
t.integer 'tag_id'
|
||||
t.string 'taggable_type'
|
||||
t.integer 'taggable_id'
|
||||
t.string 'tagger_type'
|
||||
t.integer 'tagger_id'
|
||||
t.string 'context', limit: 128
|
||||
t.datetime 'created_at'
|
||||
t.index ['context'], name: 'index_taggings_on_context'
|
||||
t.index %w[tag_id taggable_id taggable_type context tagger_id tagger_type], name: 'taggings_idx', unique: true
|
||||
t.index ['tag_id'], name: 'index_taggings_on_tag_id'
|
||||
t.index %w[taggable_id taggable_type context], name: 'index_taggings_on_taggable_id_and_taggable_type_and_context'
|
||||
t.index %w[taggable_id taggable_type tagger_id context], name: 'taggings_idy'
|
||||
t.index ['taggable_id'], name: 'index_taggings_on_taggable_id'
|
||||
t.index %w[taggable_type taggable_id], name: 'index_taggings_on_taggable_type_and_taggable_id'
|
||||
t.index ['taggable_type'], name: 'index_taggings_on_taggable_type'
|
||||
t.index %w[tagger_id tagger_type], name: 'index_taggings_on_tagger_id_and_tagger_type'
|
||||
t.index ['tagger_id'], name: 'index_taggings_on_tagger_id'
|
||||
t.index %w[tagger_type tagger_id], name: 'index_taggings_on_tagger_type_and_tagger_id'
|
||||
create_table "taggings", id: :serial, force: :cascade do |t|
|
||||
t.integer "tag_id"
|
||||
t.string "taggable_type"
|
||||
t.integer "taggable_id"
|
||||
t.string "tagger_type"
|
||||
t.integer "tagger_id"
|
||||
t.string "context", limit: 128
|
||||
t.datetime "created_at"
|
||||
t.index ["context"], name: "index_taggings_on_context"
|
||||
t.index ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true
|
||||
t.index ["tag_id"], name: "index_taggings_on_tag_id"
|
||||
t.index ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context"
|
||||
t.index ["taggable_id", "taggable_type", "tagger_id", "context"], name: "taggings_idy"
|
||||
t.index ["taggable_id"], name: "index_taggings_on_taggable_id"
|
||||
t.index ["taggable_type", "taggable_id"], name: "index_taggings_on_taggable_type_and_taggable_id"
|
||||
t.index ["taggable_type"], name: "index_taggings_on_taggable_type"
|
||||
t.index ["tagger_id", "tagger_type"], name: "index_taggings_on_tagger_id_and_tagger_type"
|
||||
t.index ["tagger_id"], name: "index_taggings_on_tagger_id"
|
||||
t.index ["tagger_type", "tagger_id"], name: "index_taggings_on_tagger_type_and_tagger_id"
|
||||
end
|
||||
|
||||
create_table 'tags', id: :serial, force: :cascade do |t|
|
||||
t.string 'name'
|
||||
t.integer 'taggings_count', default: 0
|
||||
t.index ['name'], name: 'index_tags_on_name', unique: true
|
||||
create_table "tags", id: :serial, force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.integer "taggings_count", default: 0
|
||||
t.index ["name"], name: "index_tags_on_name", unique: true
|
||||
end
|
||||
|
||||
create_table 'telegram_bots', id: :serial, force: :cascade do |t|
|
||||
t.string 'name'
|
||||
t.string 'auth_key'
|
||||
t.integer 'account_id'
|
||||
t.datetime 'created_at', null: false
|
||||
t.datetime 'updated_at', null: false
|
||||
create_table "telegram_bots", id: :serial, force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "auth_key"
|
||||
t.integer "account_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table 'users', id: :serial, force: :cascade do |t|
|
||||
t.string 'provider', default: 'email', null: false
|
||||
t.string 'uid', default: '', null: false
|
||||
t.string 'encrypted_password', default: '', null: false
|
||||
t.string 'reset_password_token'
|
||||
t.datetime 'reset_password_sent_at'
|
||||
t.datetime 'remember_created_at'
|
||||
t.integer 'sign_in_count', default: 0, null: false
|
||||
t.datetime 'current_sign_in_at'
|
||||
t.datetime 'last_sign_in_at'
|
||||
t.string 'current_sign_in_ip'
|
||||
t.string 'last_sign_in_ip'
|
||||
t.string 'confirmation_token'
|
||||
t.datetime 'confirmed_at'
|
||||
t.datetime 'confirmation_sent_at'
|
||||
t.string 'unconfirmed_email'
|
||||
t.string 'name', null: false
|
||||
t.string 'nickname'
|
||||
t.string 'email'
|
||||
t.json 'tokens'
|
||||
t.integer 'account_id', null: false
|
||||
t.datetime 'created_at', null: false
|
||||
t.datetime 'updated_at', null: false
|
||||
t.string 'pubsub_token'
|
||||
t.integer 'role', default: 0
|
||||
t.bigint 'inviter_id'
|
||||
t.index ['email'], name: 'index_users_on_email'
|
||||
t.index ['inviter_id'], name: 'index_users_on_inviter_id'
|
||||
t.index ['pubsub_token'], name: 'index_users_on_pubsub_token', unique: true
|
||||
t.index ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true
|
||||
t.index %w[uid provider], name: 'index_users_on_uid_and_provider', unique: true
|
||||
create_table "users", id: :serial, force: :cascade do |t|
|
||||
t.string "provider", default: "email", null: false
|
||||
t.string "uid", default: "", null: false
|
||||
t.string "encrypted_password", default: "", null: false
|
||||
t.string "reset_password_token"
|
||||
t.datetime "reset_password_sent_at"
|
||||
t.datetime "remember_created_at"
|
||||
t.integer "sign_in_count", default: 0, null: false
|
||||
t.datetime "current_sign_in_at"
|
||||
t.datetime "last_sign_in_at"
|
||||
t.string "current_sign_in_ip"
|
||||
t.string "last_sign_in_ip"
|
||||
t.string "confirmation_token"
|
||||
t.datetime "confirmed_at"
|
||||
t.datetime "confirmation_sent_at"
|
||||
t.string "unconfirmed_email"
|
||||
t.string "name", null: false
|
||||
t.string "nickname"
|
||||
t.string "email"
|
||||
t.json "tokens"
|
||||
t.integer "account_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "pubsub_token"
|
||||
t.integer "role", default: 0
|
||||
t.bigint "inviter_id"
|
||||
t.index ["email"], name: "index_users_on_email"
|
||||
t.index ["inviter_id"], name: "index_users_on_inviter_id"
|
||||
t.index ["pubsub_token"], name: "index_users_on_pubsub_token", unique: true
|
||||
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
||||
t.index ["uid", "provider"], name: "index_users_on_uid_and_provider", unique: true
|
||||
end
|
||||
|
||||
create_table 'webhooks', force: :cascade do |t|
|
||||
t.integer 'account_id'
|
||||
t.integer 'inbox_id'
|
||||
t.string 'urls'
|
||||
t.datetime 'created_at', precision: 6, null: false
|
||||
t.datetime 'updated_at', precision: 6, null: false
|
||||
create_table "webhooks", force: :cascade do |t|
|
||||
t.integer "account_id"
|
||||
t.integer "inbox_id"
|
||||
t.string "urls"
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
end
|
||||
|
||||
add_foreign_key 'active_storage_attachments', 'active_storage_blobs', column: 'blob_id'
|
||||
add_foreign_key 'contact_inboxes', 'contacts'
|
||||
add_foreign_key 'contact_inboxes', 'inboxes'
|
||||
add_foreign_key 'conversations', 'contact_inboxes'
|
||||
add_foreign_key 'messages', 'contacts'
|
||||
add_foreign_key 'users', 'users', column: 'inviter_id', on_delete: :nullify
|
||||
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
|
||||
add_foreign_key "contact_inboxes", "contacts"
|
||||
add_foreign_key "contact_inboxes", "inboxes"
|
||||
add_foreign_key "conversations", "contact_inboxes"
|
||||
add_foreign_key "messages", "contacts"
|
||||
add_foreign_key "users", "users", column: "inviter_id", on_delete: :nullify
|
||||
end
|
||||
|
|
|
@ -62,7 +62,7 @@ RSpec.describe 'Inboxes API', type: :request do
|
|||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(Inbox.count).to eq(0)
|
||||
expect { inbox.reload }.to raise_exception(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
it 'is unable to delete inbox of another account' do
|
||||
|
@ -87,4 +87,42 @@ RSpec.describe 'Inboxes API', type: :request do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PATCH /api/v1/inboxes/:id' do
|
||||
let(:inbox) { create(:inbox, account: account) }
|
||||
|
||||
context 'when it is an unauthenticated user' do
|
||||
it 'returns unauthorized' do
|
||||
patch "/api/v1/inboxes/#{inbox.id}"
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is an authenticated user' do
|
||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||
let(:valid_params) { { inbox: { enable_auto_assignment: false } } }
|
||||
|
||||
it 'updates inbox' do
|
||||
patch "/api/v1/inboxes/#{inbox.id}",
|
||||
headers: admin.create_new_auth_token,
|
||||
params: valid_params,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(inbox.reload.enable_auto_assignment).to be_falsey
|
||||
end
|
||||
|
||||
it 'will not update inbox for agent' do
|
||||
agent = create(:user, account: account, role: :agent)
|
||||
|
||||
patch "/api/v1/inboxes/#{inbox.id}",
|
||||
headers: agent.create_new_auth_token,
|
||||
params: valid_params,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -97,6 +97,17 @@ RSpec.describe Conversation, type: :model do
|
|||
# run_round_robin
|
||||
expect(conversation.reload.assignee).to eq(agent)
|
||||
end
|
||||
|
||||
it 'will not auto assign agent if enable_auto_assignment is false' do
|
||||
inbox.update(enable_auto_assignment: false)
|
||||
|
||||
# send_events
|
||||
expect(Rails.configuration.dispatcher).to have_received(:dispatch)
|
||||
.with(described_class::CONVERSATION_CREATED, kind_of(Time), conversation: conversation)
|
||||
|
||||
# run_round_robin
|
||||
expect(conversation.reload.assignee).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#update_assignee' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue