chore: Add Assignable Agents API (#4722)
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
class Api::V1::Accounts::AssignableAgentsController < Api::V1::Accounts::BaseController
|
||||
before_action :fetch_inboxes
|
||||
|
||||
def index
|
||||
agent_ids = @inboxes.map do |inbox|
|
||||
authorize inbox, :show?
|
||||
member_ids = inbox.members.pluck(:user_id)
|
||||
member_ids
|
||||
end
|
||||
agent_ids = agent_ids.inject(:&)
|
||||
agents = Current.account.users.where(id: agent_ids)
|
||||
@assignable_agents = (agents + Current.account.administrators).uniq
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fetch_inboxes
|
||||
@inboxes = Current.account.inboxes.find(permitted_params[:inbox_ids])
|
||||
end
|
||||
|
||||
def permitted_params
|
||||
params.permit(inbox_ids: [])
|
||||
end
|
||||
end
|
||||
@@ -12,6 +12,7 @@ class Api::V1::Accounts::InboxesController < Api::V1::Accounts::BaseController
|
||||
|
||||
def show; end
|
||||
|
||||
# Deprecated: This API will be removed in 2.7.0
|
||||
def assignable_agents
|
||||
@assignable_agents = (Current.account.users.where(id: @inbox.members.select(:user_id)) + Current.account.administrators).uniq
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user