Skip to content

Commit

Permalink
chore: Add sla policy association to conversation (#7360)
Browse files Browse the repository at this point in the history
Adds the sla policy association to the conversation

Fixes: https://linear.app/chatwoot/issue/CW-1615/applying-an-sla-to-the-conversation
  • Loading branch information
sojan-official committed Jun 21, 2023
1 parent 93d8157 commit 595e6e7
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/models/conversation.rb
Expand Up @@ -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
Expand Down Expand Up @@ -294,3 +295,5 @@ def validate_referer_url
"NEW.display_id := nextval('conv_dpid_seq_' || NEW.account_id);"
end
end

Conversation.include_mod_with('EnterpriseConversationConcern')
5 changes: 5 additions & 0 deletions db/migrate/20230620132319_add_sla_policy_to_conversations.rb
@@ -0,0 +1,5 @@
class AddSlaPolicyToConversations < ActiveRecord::Migration[7.0]
def change
add_column :conversations, :sla_policy_id, :bigint
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Expand Up @@ -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"
Expand Down Expand Up @@ -448,6 +448,7 @@
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"
Expand Down
@@ -0,0 +1,7 @@
module Enterprise::EnterpriseConversationConcern
extend ActiveSupport::Concern

included do
belongs_to :sla_policy, optional: true
end
end
2 changes: 2 additions & 0 deletions enterprise/app/models/sla_policy.rb
Expand Up @@ -18,4 +18,6 @@
class SlaPolicy < ApplicationRecord
belongs_to :account
validates :name, presence: true

has_many :conversations, dependent: :nullify
end
7 changes: 7 additions & 0 deletions spec/enterprise/models/conversation_spec.rb
@@ -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
1 change: 1 addition & 0 deletions spec/enterprise/models/sla_policy_spec.rb
Expand Up @@ -11,6 +11,7 @@

describe 'associations' do
it { is_expected.to belong_to(:account) }
it { is_expected.to have_many(:conversations).dependent(:nullify) }
end

describe 'validates_factory' do
Expand Down
5 changes: 5 additions & 0 deletions spec/models/conversation_spec.rb
Expand Up @@ -8,6 +8,11 @@
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
Expand Down

0 comments on commit 595e6e7

Please sign in to comment.