Просмотр исходного кода

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

Martin Edenhofer 8 лет назад
Родитель
Сommit
6f63af9495
2 измененных файлов с 62 добавлено и 7 удалено
  1. 55 1
      app/controllers/ticket_articles_controller.rb
  2. 7 6
      config/routes/ticket.rb

+ 55 - 1
app/controllers/ticket_articles_controller.rb

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

+ 7 - 6
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
   match api_path + '/ticket_states/:id',                             to: 'ticket_states#destroy',     via: :delete
 
 
   # ticket articles
   # 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_add', via: :post
   match api_path + '/ticket_attachment_upload',                      to: 'ticket_articles#ticket_attachment_upload_delete', via: :delete
   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
 end