links_controller.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. class LinksController < ApplicationController
  3. before_filter :authentication_check
  4. # GET /api/v1/links
  5. def index
  6. links = Link.list(
  7. :link_object => params[:link_object],
  8. :link_object_value => params[:link_object_value],
  9. )
  10. assets = {}
  11. link_list = []
  12. links.each { |item|
  13. link_list.push item
  14. if item['link_object'] == 'Ticket'
  15. ticket = Ticket.lookup( :id => item['link_object_value'] )
  16. assets = ticket.assets(assets)
  17. end
  18. }
  19. # return result
  20. render :json => {
  21. :links => link_list,
  22. :assets => assets,
  23. }
  24. end
  25. # POST /api/v1/links/add
  26. def add
  27. # lookup object id
  28. object_id = Ticket.where( :number => params[:link_object_source_number] ).first.id
  29. link = Link.add(
  30. :link_type => params[:link_type],
  31. :link_object_target => params[:link_object_target],
  32. :link_object_target_value => params[:link_object_target_value],
  33. :link_object_source => params[:link_object_source],
  34. :link_object_source_value => object_id
  35. )
  36. if link
  37. render :json => link, :status => :created
  38. else
  39. render :json => link.errors, :status => :unprocessable_entity
  40. end
  41. end
  42. # DELETE /api/v1/links/remove
  43. def remove
  44. link = Link.remove(params)
  45. if link
  46. render :json => link, :status => :created
  47. else
  48. render :json => link.errors, :status => :unprocessable_entity
  49. end
  50. end
  51. end