Added /ticket_articles/by_ticket/1 to retrieve all article of a ticket.

This commit is contained in:
Martin Edenhofer 2016-06-21 22:59:03 +02:00
parent 6112f1de0f
commit 6f63af9495
2 changed files with 62 additions and 7 deletions

View file

@ -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

View file

@ -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