feat: API to download breached conversations (#9150)

* feat: add download conversations endpoint

* feat: template for conversation list download

* feat: setup download API and tests

* chore: revert formatting change

* feat: rename download method

* feat: rename template

* feat: include sla_policy table in download query

* refactor: add nil safety to assignee

* chore: Update en.yml

* fix: remove applied_sla relation
This commit is contained in:
Shivam Mishra
2024-03-26 09:22:49 +05:30
committed by GitHub
parent 9917cb4273
commit d1dd319091
5 changed files with 81 additions and 1 deletions

View File

@@ -4,7 +4,7 @@ class Api::V1::Accounts::AppliedSlasController < Api::V1::Accounts::EnterpriseAc
RESULTS_PER_PAGE = 25
before_action :set_applied_slas, only: [:index, :metrics]
before_action :set_applied_slas, only: [:index, :metrics, :download]
before_action :set_current_page, only: [:index]
before_action :paginate_slas, only: [:index]
before_action :check_admin_authorization?
@@ -19,8 +19,22 @@ class Api::V1::Accounts::AppliedSlasController < Api::V1::Accounts::EnterpriseAc
@hit_rate = hit_rate
end
def download
@breached_slas = breached_slas
response.headers['Content-Type'] = 'text/csv'
response.headers['Content-Disposition'] = 'attachment; filename=breached_conversation.csv'
render layout: false, formats: [:csv]
end
private
def breached_slas
@applied_slas.includes(:sla_policy).joins(:conversation)
.where.not(conversations: { status: :resolved })
.where(applied_slas: { sla_status: :missed })
end
def total_applied_slas
@total_applied_slas ||= @applied_slas.count
end

View File

@@ -0,0 +1,26 @@
<% headers = [
I18n.t('reports.sla_csv.conversation_id'),
I18n.t('reports.sla_csv.sla_policy_breached'),
I18n.t('reports.sla_csv.assignee'),
I18n.t('reports.sla_csv.team'),
I18n.t('reports.sla_csv.inbox'),
I18n.t('reports.sla_csv.labels'),
I18n.t('reports.sla_csv.conversation_link'),
I18n.t('reports.sla_csv.breached_events')
] %>
<%= CSV.generate_line headers %>
<% @breached_slas.each do |sla| %>
<% breached_events = sla.sla_events.map(&:event_type).join(', ') %>
<% conversation = sla.conversation %>
<%= CSV.generate_line([
conversation.display_id,
sla.sla_policy.name,
conversation.assignee&.name,
conversation.team&.name,
conversation.inbox&.name,
conversation.cached_label_list,
app_account_conversation_url(account_id: conversation.account_id, id: conversation.display_id),
breached_events
]) %>
<% end %>