X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/b38343e5bd95230c6bb2159700102dbca247fa03..694d45cd31c65e06a342ae3d038af563c5dc7731:/app/controllers/api/relations_controller.rb?ds=inline diff --git a/app/controllers/api/relations_controller.rb b/app/controllers/api/relations_controller.rb index a0740b382..9bb3eb87c 100644 --- a/app/controllers/api/relations_controller.rb +++ b/app/controllers/api/relations_controller.rb @@ -1,10 +1,8 @@ module Api - class RelationsController < ApplicationController + class RelationsController < ApiController require "xml/libxml" - skip_before_action :verify_authenticity_token before_action :authorize, :only => [:create, :update, :delete] - before_action :api_deny_access_handler authorize_resource @@ -13,10 +11,12 @@ module Api before_action :check_api_readable, :except => [:create, :update, :delete] around_action :api_call_handle_error, :api_call_timeout + before_action :set_request_formats, :except => [:create, :update, :delete] + def create assert_method :put - relation = Relation.from_xml(request.raw_post, true) + relation = Relation.from_xml(request.raw_post, :create => true) # Assume that Relation.from_xml has thrown an exception if there is an error parsing the xml relation.create_with_history current_user @@ -24,10 +24,14 @@ module Api end def show - relation = Relation.find(params[:id]) - response.last_modified = relation.timestamp - if relation.visible - render :xml => relation.to_xml.to_s + @relation = Relation.find(params[:id]) + response.last_modified = @relation.timestamp + if @relation.visible + # Render the result + respond_to do |format| + format.xml + format.json + end else head :gone end @@ -90,35 +94,38 @@ module Api node_ids += way_node_ids.flatten nodes = Node.where(:id => node_ids.uniq).includes(:node_tags) - # create XML. - doc = OSM::API.new.get_xml_doc visible_nodes = {} - changeset_cache = {} - user_display_name_cache = {} + @nodes = [] nodes.each do |node| next unless node.visible? # should be unnecessary if data is consistent. - doc.root << node.to_xml_node(changeset_cache, user_display_name_cache) + @nodes << node visible_nodes[node.id] = node end + @ways = [] ways.each do |way| next unless way.visible? # should be unnecessary if data is consistent. - doc.root << way.to_xml_node(visible_nodes, changeset_cache, user_display_name_cache) + @ways << way end + @relations = [] relations.each do |rel| next unless rel.visible? # should be unnecessary if data is consistent. - doc.root << rel.to_xml_node(changeset_cache, user_display_name_cache) + @relations << rel end - # finally add self and output - doc.root << relation.to_xml_node(changeset_cache, user_display_name_cache) - render :xml => doc.to_s + # finally add self + @relations << relation + # Render the result + respond_to do |format| + format.xml + format.json + end else head :gone end @@ -131,13 +138,13 @@ module Api raise OSM::APIBadUserInput, "No relations were given to search for" if ids.empty? - doc = OSM::API.new.get_xml_doc + @relations = Relation.find(ids) - Relation.find(ids).each do |relation| - doc.root << relation.to_xml_node + # Render the result + respond_to do |format| + format.xml + format.json end - - render :xml => doc.to_s end def relations_for_way @@ -157,13 +164,17 @@ module Api def relations_for_object(objtype) relationids = RelationMember.where(:member_type => objtype, :member_id => params[:id]).collect(&:relation_id).uniq - doc = OSM::API.new.get_xml_doc + @relations = [] Relation.find(relationids).each do |relation| - doc.root << relation.to_xml_node if relation.visible + @relations << relation if relation.visible end - render :xml => doc.to_s + # Render the result + respond_to do |format| + format.xml + format.json + end end end end