feat: API to add label to contacts (#1563)
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
class Api::V1::Accounts::Contacts::LabelsController < Api::V1::Accounts::BaseController
|
||||
include LabelConcern
|
||||
|
||||
private
|
||||
|
||||
def model
|
||||
@model ||= Current.account.contacts.find(params[:contact_id])
|
||||
end
|
||||
|
||||
def permitted_params
|
||||
params.permit(:contact_id, :labels)
|
||||
end
|
||||
end
|
||||
@@ -1,11 +1,13 @@
|
||||
class Api::V1::Accounts::Conversations::LabelsController < Api::V1::Accounts::Conversations::BaseController
|
||||
def create
|
||||
@conversation.update_labels(params[:labels])
|
||||
@labels = @conversation.label_list
|
||||
include LabelConcern
|
||||
|
||||
private
|
||||
|
||||
def model
|
||||
@model ||= @conversation
|
||||
end
|
||||
|
||||
# all labels of the current conversation
|
||||
def index
|
||||
@labels = @conversation.label_list
|
||||
def permitted_params
|
||||
params.permit(:conversation_id, :labels)
|
||||
end
|
||||
end
|
||||
|
||||
10
app/controllers/concerns/label_concern.rb
Normal file
10
app/controllers/concerns/label_concern.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
module LabelConcern
|
||||
def create
|
||||
model.update_labels(permitted_params[:labels])
|
||||
@labels = model.label_list
|
||||
end
|
||||
|
||||
def index
|
||||
@labels = model.label_list
|
||||
end
|
||||
end
|
||||
11
app/models/concerns/labelable.rb
Normal file
11
app/models/concerns/labelable.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
module Labelable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
acts_as_taggable_on :labels
|
||||
end
|
||||
|
||||
def update_labels(labels = nil)
|
||||
update!(label_list: labels)
|
||||
end
|
||||
end
|
||||
@@ -26,6 +26,7 @@ class Contact < ApplicationRecord
|
||||
include Pubsubable
|
||||
include Avatarable
|
||||
include AvailabilityStatusable
|
||||
include Labelable
|
||||
|
||||
validates :account_id, presence: true
|
||||
validates :email, allow_blank: true, uniqueness: { scope: [:account_id], case_sensitive: false }
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
#
|
||||
|
||||
class Conversation < ApplicationRecord
|
||||
include Labelable
|
||||
|
||||
validates :account_id, presence: true
|
||||
validates :inbox_id, presence: true
|
||||
|
||||
@@ -57,8 +59,6 @@ class Conversation < ApplicationRecord
|
||||
after_create_commit :notify_conversation_creation, :queue_conversation_auto_resolution_job
|
||||
after_save :run_round_robin
|
||||
|
||||
acts_as_taggable_on :labels
|
||||
|
||||
delegate :auto_resolve_duration, to: :account
|
||||
|
||||
def can_reply?
|
||||
@@ -75,10 +75,6 @@ class Conversation < ApplicationRecord
|
||||
update!(assignee: agent)
|
||||
end
|
||||
|
||||
def update_labels(labels = nil)
|
||||
update!(label_list: labels)
|
||||
end
|
||||
|
||||
def toggle_status
|
||||
# FIXME: implement state machine with aasm
|
||||
self.status = open? ? :resolved : :open
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
json.payload @labels
|
||||
@@ -0,0 +1 @@
|
||||
json.payload @labels
|
||||
Reference in New Issue
Block a user