fix: Handle invalid metric in ReportsController (#8086)

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>

Fixes CW-2643
This commit is contained in:
Vishnu Narayanan
2023-10-12 17:01:23 +05:30
committed by GitHub
parent 9e173fca3c
commit 415bb23c37
2 changed files with 42 additions and 1 deletions

View File

@@ -15,7 +15,10 @@ class V2::ReportBuilder
end
def timeseries
send(params[:metric])
return send(params[:metric]) if metric_valid?
Rails.logger.error "ReportBuilder: Invalid metric - #{params[:metric]}"
{}
end
# For backward compatible with old report
@@ -53,6 +56,16 @@ class V2::ReportBuilder
private
def metric_valid?
%w[conversations_count
incoming_messages_count
outgoing_messages_count
avg_first_response_time
avg_resolution_time reply_time
resolutions_count
reply_time].include?(params[:metric])
end
def inbox
@inbox ||= account.inboxes.find(params[:id])
end