trabajo-afectivo/app/controllers/links_controller.rb

62 lines
1.4 KiB
Ruby
Raw Normal View History

2016-10-19 03:11:36 +00:00
# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
2012-08-21 10:28:41 +00:00
class LinksController < ApplicationController
before_action :authentication_check
2012-08-21 10:28:41 +00:00
# GET /api/v1/links
2012-08-21 10:28:41 +00:00
def index
links = Link.list(
link_object: params[:link_object],
link_object_value: params[:link_object_value],
2012-08-21 10:28:41 +00:00
)
assets = {}
2012-08-21 10:28:41 +00:00
link_list = []
links.each { |item|
link_list.push item
if item['link_object'] == 'Ticket'
ticket = Ticket.lookup( id: item['link_object_value'] )
assets = ticket.assets(assets)
2012-08-21 10:28:41 +00:00
end
}
# return result
render json: {
links: link_list,
assets: assets,
2012-08-21 10:28:41 +00:00
}
end
# POST /api/v1/links/add
2012-08-21 10:28:41 +00:00
def add
2012-08-24 18:54:57 +00:00
# lookup object id
object_id = Ticket.where( number: params[:link_object_source_number] ).first.id
2012-08-21 10:28:41 +00:00
link = Link.add(
link_type: params[:link_type],
link_object_target: params[:link_object_target],
link_object_target_value: params[:link_object_target_value],
link_object_source: params[:link_object_source],
link_object_source_value: object_id
2012-08-21 10:28:41 +00:00
)
if link
render json: link, status: :created
2012-08-21 10:28:41 +00:00
else
render json: link.errors, status: :unprocessable_entity
2012-08-21 10:28:41 +00:00
end
end
# DELETE /api/v1/links/remove
def remove
link = Link.remove(params)
2012-08-21 10:28:41 +00:00
if link
render json: link, status: :created
2012-08-21 10:28:41 +00:00
else
render json: link.errors, status: :unprocessable_entity
2012-08-21 10:28:41 +00:00
end
end
end