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:
Sojan Jose
2023-06-21 14:48:50 +05:30
committed by GitHub
parent 93d8157a55
commit 595e6e79f0
8 changed files with 32 additions and 1 deletions

View File

@@ -24,6 +24,7 @@
# contact_inbox_id :bigint
# display_id :integer not null
# inbox_id :integer not null
# sla_policy_id :bigint
# team_id :bigint
#
# Indexes
@@ -294,3 +295,5 @@ class Conversation < ApplicationRecord
"NEW.display_id := nextval('conv_dpid_seq_' || NEW.account_id);"
end
end
Conversation.include_mod_with('EnterpriseConversationConcern')

View File

@@ -0,0 +1,5 @@
class AddSlaPolicyToConversations < ActiveRecord::Migration[7.0]
def change
add_column :conversations, :sla_policy_id, :bigint
end
end

View File

@@ -10,7 +10,7 @@
#
# 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
enable_extension "pg_stat_statements"
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 "first_reply_created_at", precision: nil
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", "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"

View File

@@ -0,0 +1,7 @@
module Enterprise::EnterpriseConversationConcern
extend ActiveSupport::Concern
included do
belongs_to :sla_policy, optional: true
end
end

View File

@@ -18,4 +18,6 @@
class SlaPolicy < ApplicationRecord
belongs_to :account
validates :name, presence: true
has_many :conversations, dependent: :nullify
end

View 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

View File

@@ -11,6 +11,7 @@ RSpec.describe SlaPolicy, type: :model do
describe 'associations' do
it { is_expected.to belong_to(:account) }
it { is_expected.to have_many(:conversations).dependent(:nullify) }
end
describe 'validates_factory' do

View File

@@ -8,6 +8,11 @@ RSpec.describe Conversation do
describe 'associations' do
it { is_expected.to belong_to(:account) }
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
describe 'concerns' do