Merge remote-tracking branch 'upstream/pull/5626'

This commit is contained in:
Tom Hughes 2025-02-09 15:02:14 +00:00
commit 699e73a22a
31 changed files with 438 additions and 242 deletions

View file

@ -15,9 +15,7 @@ class ApiAbility
can [:read, :download], Changeset
can :read, Tracepoint
can :read, User
can :read, Node
can [:read, :ways_for_node], Way
can [:read, :relations_for_node, :relations_for_way, :relations_for_relation], Relation
can :read, [Node, Way, Relation]
can [:history, :read], [OldNode, OldWay, OldRelation]
can :read, UserBlock

View file

@ -0,0 +1,25 @@
module Api
module Nodes
class RelationsController < ApiController
authorize_resource
before_action :set_request_formats
def index
relation_ids = RelationMember.where(:member_type => "Node", :member_id => params[:node_id]).collect(&:relation_id).uniq
@relations = []
Relation.find(relation_ids).each do |relation|
@relations << relation if relation.visible
end
# Render the result
respond_to do |format|
format.xml
format.json
end
end
end
end
end

View file

@ -0,0 +1,25 @@
module Api
module Nodes
class WaysController < ApiController
authorize_resource
before_action :set_request_formats
##
# returns all the ways which are currently using the node given in the
# :node_id parameter. note that this used to return deleted ways as well, but
# this seemed not to be the expected behaviour, so it was removed.
def index
way_ids = WayNode.where(:node_id => params[:node_id]).collect { |ws| ws.id[0] }.uniq
@ways = Way.where(:id => way_ids, :visible => true)
# Render the result
respond_to do |format|
format.xml
format.json
end
end
end
end
end

View file

@ -0,0 +1,25 @@
module Api
module Relations
class RelationsController < ApiController
authorize_resource
before_action :set_request_formats
def index
relation_ids = RelationMember.where(:member_type => "Relation", :member_id => params[:relation_id]).collect(&:relation_id).uniq
@relations = []
Relation.find(relation_ids).each do |relation|
@relations << relation if relation.visible
end
# Render the result
respond_to do |format|
format.xml
format.json
end
end
end
end
end

View file

@ -122,35 +122,5 @@ module Api
head :bad_request
end
end
def relations_for_way
relations_for_object("Way")
end
def relations_for_node
relations_for_object("Node")
end
def relations_for_relation
relations_for_object("Relation")
end
private
def relations_for_object(objtype)
relationids = RelationMember.where(:member_type => objtype, :member_id => params[:id]).collect(&:relation_id).uniq
@relations = []
Relation.find(relationids).each do |relation|
@relations << relation if relation.visible
end
# Render the result
respond_to do |format|
format.xml
format.json
end
end
end
end

View file

@ -0,0 +1,25 @@
module Api
module Ways
class RelationsController < ApiController
authorize_resource
before_action :set_request_formats
def index
relation_ids = RelationMember.where(:member_type => "Way", :member_id => params[:way_id]).collect(&:relation_id).uniq
@relations = []
Relation.find(relation_ids).each do |relation|
@relations << relation if relation.visible
end
# Render the result
respond_to do |format|
format.xml
format.json
end
end
end
end
end

View file

@ -80,21 +80,5 @@ module Api
head :bad_request
end
end
##
# returns all the ways which are currently using the node given in the
# :id parameter. note that this used to return deleted ways as well, but
# this seemed not to be the expected behaviour, so it was removed.
def ways_for_node
wayids = WayNode.where(:node_id => params[:id]).collect { |ws| ws.id[0] }.uniq
@ways = Way.where(:id => wayids, :visible => true)
# Render the result
respond_to do |format|
format.xml
format.json
end
end
end
end

View file

@ -0,0 +1,5 @@
json.partial! "api/root_attributes"
json.elements do
json.array! @relations, :partial => "api/relations/relation", :as => :relation
end

View file

@ -0,0 +1,5 @@
xml.instruct!
xml.osm(OSM::API.new.xml_root_attributes) do |osm|
osm << (render(:partial => "api/relations/relation", :collection => @relations) || "")
end

View file

@ -0,0 +1,5 @@
json.partial! "api/root_attributes"
json.elements do
json.array! @ways, :partial => "api/ways/way", :as => :way
end

View file

@ -0,0 +1,5 @@
xml.instruct!
xml.osm(OSM::API.new.xml_root_attributes) do |osm|
osm << (render(:partial => "api/ways/way", :collection => @ways) || "")
end

View file

@ -0,0 +1,5 @@
json.partial! "api/root_attributes"
json.elements do
json.array! @relations, :partial => "api/relations/relation", :as => :relation
end

View file

@ -0,0 +1,5 @@
xml.instruct!
xml.osm(OSM::API.new.xml_root_attributes) do |osm|
osm << (render(:partial => "api/relations/relation", :collection => @relations) || "")
end

View file

@ -1,5 +0,0 @@
json.partial! "api/root_attributes"
json.elements do
json.array! @relations, :partial => "relation", :as => :relation
end

View file

@ -1,5 +0,0 @@
xml.instruct!
xml.osm(OSM::API.new.xml_root_attributes) do |osm|
osm << (render(@relations) || "")
end

View file

@ -1,5 +0,0 @@
json.partial! "api/root_attributes"
json.elements do
json.array! @relations, :partial => "relation", :as => :relation
end

View file

@ -1,5 +0,0 @@
xml.instruct!
xml.osm(OSM::API.new.xml_root_attributes) do |osm|
osm << (render(@relations) || "")
end

View file

@ -1,5 +0,0 @@
json.partial! "api/root_attributes"
json.elements do
json.array! @relations, :partial => "relation", :as => :relation
end

View file

@ -1,5 +0,0 @@
xml.instruct!
xml.osm(OSM::API.new.xml_root_attributes) do |osm|
osm << (render(@relations) || "")
end

View file

@ -0,0 +1,5 @@
json.partial! "api/root_attributes"
json.elements do
json.array! @relations, :partial => "api/relations/relation", :as => :relation
end

View file

@ -0,0 +1,5 @@
xml.instruct!
xml.osm(OSM::API.new.xml_root_attributes) do |osm|
osm << (render(:partial => "api/relations/relation", :collection => @relations) || "")
end

View file

@ -1,5 +0,0 @@
json.partial! "api/root_attributes"
json.elements do
json.array! @ways, :partial => "way", :as => :way
end

View file

@ -1,5 +0,0 @@
xml.instruct!
xml.osm(OSM::API.new.xml_root_attributes) do |osm|
osm << (render(@ways) || "")
end