External integrations can send WhatsApp template messages, but they do not have a focused API to discover the templates available for an inbox. This adds an authenticated endpoint that lists the inbox's cached WhatsApp templates and optionally filters them by exact template name. Existing inbox responses and template synchronization behavior remain unchanged. Fixes https://github.com/chatwoot/chatwoot/issues/13959 ### Things to know - The endpoint returns templates already synchronized and cached for a direct WhatsApp inbox; it does not make a new provider request. - Non-WhatsApp inboxes return an unprocessable entity response. ### How to test 1. Authenticate as a user assigned to a WhatsApp inbox. 2. Request `GET /api/v1/accounts/:account_id/inboxes/:id/message_templates` and verify the response contains the inbox's templates under `payload`. 3. Repeat the request with `?name=<template_name>` and verify only the exact matching template is returned. 4. Request the endpoint for a non-WhatsApp inbox and verify it returns an unprocessable entity response. --------- Co-authored-by: Muhsin <12408980+muhsin-k@users.noreply.github.com>
93 lines
1.5 KiB
Ruby
93 lines
1.5 KiB
Ruby
class InboxPolicy < ApplicationPolicy
|
|
class Scope
|
|
attr_reader :user_context, :user, :scope, :account, :account_user
|
|
|
|
def initialize(user_context, scope)
|
|
@user_context = user_context
|
|
@user = user_context[:user]
|
|
@account = user_context[:account]
|
|
@account_user = user_context[:account_user]
|
|
@scope = scope
|
|
end
|
|
|
|
def resolve
|
|
user.assigned_inboxes
|
|
end
|
|
end
|
|
|
|
def index?
|
|
true
|
|
end
|
|
|
|
def show?
|
|
# FIXME: for agent bots, lets bring this validation to policies as well in future
|
|
return true if @user.is_a?(AgentBot)
|
|
|
|
Current.user.assigned_inboxes.include? record
|
|
end
|
|
|
|
def assignable_agents?
|
|
true
|
|
end
|
|
|
|
def agent_bot?
|
|
true
|
|
end
|
|
|
|
def message_templates?
|
|
true
|
|
end
|
|
|
|
def campaigns?
|
|
@account_user.administrator?
|
|
end
|
|
|
|
def create?
|
|
@account_user.administrator?
|
|
end
|
|
|
|
def update?
|
|
@account_user.administrator?
|
|
end
|
|
|
|
def destroy?
|
|
@account_user.administrator?
|
|
end
|
|
|
|
def set_agent_bot?
|
|
@account_user.administrator?
|
|
end
|
|
|
|
def avatar?
|
|
@account_user.administrator?
|
|
end
|
|
|
|
def sync_templates?
|
|
@account_user.administrator?
|
|
end
|
|
|
|
def whatsapp_business_management_token?
|
|
@account_user.administrator?
|
|
end
|
|
|
|
def health?
|
|
@account_user.administrator?
|
|
end
|
|
|
|
def reset_secret?
|
|
@account_user.administrator?
|
|
end
|
|
|
|
def enable_whatsapp_calling?
|
|
@account_user.administrator?
|
|
end
|
|
|
|
def disable_whatsapp_calling?
|
|
@account_user.administrator?
|
|
end
|
|
|
|
def set_inbound_calls?
|
|
@account_user.administrator?
|
|
end
|
|
end
|