From 6f63af94954cbad6a999979dbc2eb6b0e65fc540 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 21 Jun 2016 22:59:03 +0200 Subject: [PATCH] Added /ticket_articles/by_ticket/1 to retrieve all article of a ticket. --- app/controllers/ticket_articles_controller.rb | 56 ++++++++++++++++++- config/routes/ticket.rb | 13 +++-- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/app/controllers/ticket_articles_controller.rb b/app/controllers/ticket_articles_controller.rb index ca8ac5e89..9648e47c6 100644 --- a/app/controllers/ticket_articles_controller.rb +++ b/app/controllers/ticket_articles_controller.rb @@ -32,7 +32,61 @@ class TicketArticlesController < ApplicationController return end - render json: article + render json: article.attributes_with_relation_names + end + + # GET /ticket_articles/by_ticket/1 + def index_by_ticket + + # permission check + ticket = Ticket.find(params[:id]) + return if !ticket_permission(ticket) + + articles = [] + + if params[:expand] + ticket.articles.each {|article| + + # ignore internal article if customer is requesting + next if article.internal == true && role?(Z_ROLENAME_CUSTOMER) + + result = article.attributes_with_relation_names + + # add attachments + result[:attachments] = article.attachments + articles.push result + } + + render json: articles, status: :ok + return + end + + if params[:full] + assets = {} + record_ids = [] + ticket.articles.each {|article| + + # ignore internal article if customer is requesting + next if article.internal == true && role?(Z_ROLENAME_CUSTOMER) + + record_ids.push article.id + assets = article.assets({}) + } + render json: { + record_ids: record_ids, + assets: assets, + } + return + end + + ticket.articles.each {|article| + + # ignore internal article if customer is requesting + next if article.internal == true && role?(Z_ROLENAME_CUSTOMER) + + articles.push article.attributes_with_relation_names + } + render json: articles end # POST /articles diff --git a/config/routes/ticket.rb b/config/routes/ticket.rb index fd572aff6..882538d37 100644 --- a/config/routes/ticket.rb +++ b/config/routes/ticket.rb @@ -35,13 +35,14 @@ Zammad::Application.routes.draw do match api_path + '/ticket_states/:id', to: 'ticket_states#destroy', via: :delete # ticket articles - match api_path + '/ticket_articles', to: 'ticket_articles#index', via: :get - match api_path + '/ticket_articles/:id', to: 'ticket_articles#show', via: :get - match api_path + '/ticket_articles', to: 'ticket_articles#create', via: :post - match api_path + '/ticket_articles/:id', to: 'ticket_articles#update', via: :put - match api_path + '/ticket_attachment/:ticket_id/:article_id/:id', to: 'ticket_articles#attachment', via: :get + match api_path + '/ticket_articles', to: 'ticket_articles#index', via: :get + match api_path + '/ticket_articles/:id', to: 'ticket_articles#show', via: :get + match api_path + '/ticket_articles/by_ticket/:id', to: 'ticket_articles#index_by_ticket', via: :get + match api_path + '/ticket_articles', to: 'ticket_articles#create', via: :post + match api_path + '/ticket_articles/:id', to: 'ticket_articles#update', via: :put + match api_path + '/ticket_attachment/:ticket_id/:article_id/:id', to: 'ticket_articles#attachment', via: :get match api_path + '/ticket_attachment_upload', to: 'ticket_articles#ticket_attachment_upload_add', via: :post match api_path + '/ticket_attachment_upload', to: 'ticket_articles#ticket_attachment_upload_delete', via: :delete - match api_path + '/ticket_article_plain/:id', to: 'ticket_articles#article_plain', via: :get + match api_path + '/ticket_article_plain/:id', to: 'ticket_articles#article_plain', via: :get end