chore: Add sla policy association to conversation (#7360)
Adds the sla policy association to the conversation Fixes: https://linear.app/chatwoot/issue/CW-1615/applying-an-sla-to-the-conversation
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
# contact_inbox_id :bigint
|
# contact_inbox_id :bigint
|
||||||
# display_id :integer not null
|
# display_id :integer not null
|
||||||
# inbox_id :integer not null
|
# inbox_id :integer not null
|
||||||
|
# sla_policy_id :bigint
|
||||||
# team_id :bigint
|
# team_id :bigint
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
@@ -294,3 +295,5 @@ class Conversation < ApplicationRecord
|
|||||||
"NEW.display_id := nextval('conv_dpid_seq_' || NEW.account_id);"
|
"NEW.display_id := nextval('conv_dpid_seq_' || NEW.account_id);"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Conversation.include_mod_with('EnterpriseConversationConcern')
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddSlaPolicyToConversations < ActiveRecord::Migration[7.0]
|
||||||
|
def change
|
||||||
|
add_column :conversations, :sla_policy_id, :bigint
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.0].define(version: 2023_06_12_103936) do
|
ActiveRecord::Schema[7.0].define(version: 2023_06_20_132319) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "pg_stat_statements"
|
enable_extension "pg_stat_statements"
|
||||||
enable_extension "pg_trgm"
|
enable_extension "pg_trgm"
|
||||||
@@ -448,6 +448,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_06_12_103936) do
|
|||||||
t.datetime "assignee_last_seen_at", precision: nil
|
t.datetime "assignee_last_seen_at", precision: nil
|
||||||
t.datetime "first_reply_created_at", precision: nil
|
t.datetime "first_reply_created_at", precision: nil
|
||||||
t.integer "priority"
|
t.integer "priority"
|
||||||
|
t.bigint "sla_policy_id"
|
||||||
t.index ["account_id", "display_id"], name: "index_conversations_on_account_id_and_display_id", unique: true
|
t.index ["account_id", "display_id"], name: "index_conversations_on_account_id_and_display_id", unique: true
|
||||||
t.index ["account_id", "id"], name: "index_conversations_on_id_and_account_id"
|
t.index ["account_id", "id"], name: "index_conversations_on_id_and_account_id"
|
||||||
t.index ["account_id", "inbox_id", "status", "assignee_id"], name: "conv_acid_inbid_stat_asgnid_idx"
|
t.index ["account_id", "inbox_id", "status", "assignee_id"], name: "conv_acid_inbid_stat_asgnid_idx"
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
module Enterprise::EnterpriseConversationConcern
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
included do
|
||||||
|
belongs_to :sla_policy, optional: true
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -18,4 +18,6 @@
|
|||||||
class SlaPolicy < ApplicationRecord
|
class SlaPolicy < ApplicationRecord
|
||||||
belongs_to :account
|
belongs_to :account
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
|
|
||||||
|
has_many :conversations, dependent: :nullify
|
||||||
end
|
end
|
||||||
|
|||||||
7
spec/enterprise/models/conversation_spec.rb
Normal file
7
spec/enterprise/models/conversation_spec.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Conversation, type: :model do
|
||||||
|
describe 'associations' do
|
||||||
|
it { is_expected.to belong_to(:sla_policy).optional }
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -11,6 +11,7 @@ RSpec.describe SlaPolicy, type: :model do
|
|||||||
|
|
||||||
describe 'associations' do
|
describe 'associations' do
|
||||||
it { is_expected.to belong_to(:account) }
|
it { is_expected.to belong_to(:account) }
|
||||||
|
it { is_expected.to have_many(:conversations).dependent(:nullify) }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'validates_factory' do
|
describe 'validates_factory' do
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ RSpec.describe Conversation do
|
|||||||
describe 'associations' do
|
describe 'associations' do
|
||||||
it { is_expected.to belong_to(:account) }
|
it { is_expected.to belong_to(:account) }
|
||||||
it { is_expected.to belong_to(:inbox) }
|
it { is_expected.to belong_to(:inbox) }
|
||||||
|
it { is_expected.to belong_to(:contact) }
|
||||||
|
it { is_expected.to belong_to(:contact_inbox) }
|
||||||
|
it { is_expected.to belong_to(:assignee).optional }
|
||||||
|
it { is_expected.to belong_to(:team).optional }
|
||||||
|
it { is_expected.to belong_to(:campaign).optional }
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'concerns' do
|
describe 'concerns' do
|
||||||
|
|||||||
Reference in New Issue
Block a user