Added /ticket_articles/by_ticket/1 to retrieve all article of a ticket.
This commit is contained in:
parent
6112f1de0f
commit
6f63af9495
2 changed files with 62 additions and 7 deletions
|
@ -32,7 +32,61 @@ class TicketArticlesController < ApplicationController
|
||||||
return
|
return
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
# POST /articles
|
# POST /articles
|
||||||
|
|
|
@ -37,6 +37,7 @@ Zammad::Application.routes.draw do
|
||||||
# ticket articles
|
# ticket articles
|
||||||
match api_path + '/ticket_articles', to: 'ticket_articles#index', 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/: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', to: 'ticket_articles#create', via: :post
|
||||||
match api_path + '/ticket_articles/:id', to: 'ticket_articles#update', via: :put
|
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/:ticket_id/:article_id/:id', to: 'ticket_articles#attachment', via: :get
|
||||||
|
|
Loading…
Reference in a new issue