Merge remote-tracking branch 'upstream/pull/5626'
This commit is contained in:
commit
699e73a22a
31 changed files with 438 additions and 242 deletions
|
@ -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
|
||||
|
||||
|
|
25
app/controllers/api/nodes/relations_controller.rb
Normal file
25
app/controllers/api/nodes/relations_controller.rb
Normal 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
|
25
app/controllers/api/nodes/ways_controller.rb
Normal file
25
app/controllers/api/nodes/ways_controller.rb
Normal 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
|
25
app/controllers/api/relations/relations_controller.rb
Normal file
25
app/controllers/api/relations/relations_controller.rb
Normal 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
|
|
@ -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
|
||||
|
|
25
app/controllers/api/ways/relations_controller.rb
Normal file
25
app/controllers/api/ways/relations_controller.rb
Normal 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
|
|
@ -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
|
||||
|
|
5
app/views/api/nodes/relations/index.json.jbuilder
Normal file
5
app/views/api/nodes/relations/index.json.jbuilder
Normal file
|
@ -0,0 +1,5 @@
|
|||
json.partial! "api/root_attributes"
|
||||
|
||||
json.elements do
|
||||
json.array! @relations, :partial => "api/relations/relation", :as => :relation
|
||||
end
|
5
app/views/api/nodes/relations/index.xml.builder
Normal file
5
app/views/api/nodes/relations/index.xml.builder
Normal 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
|
5
app/views/api/nodes/ways/index.json.jbuilder
Normal file
5
app/views/api/nodes/ways/index.json.jbuilder
Normal file
|
@ -0,0 +1,5 @@
|
|||
json.partial! "api/root_attributes"
|
||||
|
||||
json.elements do
|
||||
json.array! @ways, :partial => "api/ways/way", :as => :way
|
||||
end
|
5
app/views/api/nodes/ways/index.xml.builder
Normal file
5
app/views/api/nodes/ways/index.xml.builder
Normal 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
|
5
app/views/api/relations/relations/index.json.jbuilder
Normal file
5
app/views/api/relations/relations/index.json.jbuilder
Normal file
|
@ -0,0 +1,5 @@
|
|||
json.partial! "api/root_attributes"
|
||||
|
||||
json.elements do
|
||||
json.array! @relations, :partial => "api/relations/relation", :as => :relation
|
||||
end
|
5
app/views/api/relations/relations/index.xml.builder
Normal file
5
app/views/api/relations/relations/index.xml.builder
Normal 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
|
|
@ -1,5 +0,0 @@
|
|||
json.partial! "api/root_attributes"
|
||||
|
||||
json.elements do
|
||||
json.array! @relations, :partial => "relation", :as => :relation
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
xml.instruct!
|
||||
|
||||
xml.osm(OSM::API.new.xml_root_attributes) do |osm|
|
||||
osm << (render(@relations) || "")
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
json.partial! "api/root_attributes"
|
||||
|
||||
json.elements do
|
||||
json.array! @relations, :partial => "relation", :as => :relation
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
xml.instruct!
|
||||
|
||||
xml.osm(OSM::API.new.xml_root_attributes) do |osm|
|
||||
osm << (render(@relations) || "")
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
json.partial! "api/root_attributes"
|
||||
|
||||
json.elements do
|
||||
json.array! @relations, :partial => "relation", :as => :relation
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
xml.instruct!
|
||||
|
||||
xml.osm(OSM::API.new.xml_root_attributes) do |osm|
|
||||
osm << (render(@relations) || "")
|
||||
end
|
5
app/views/api/ways/relations/index.json.jbuilder
Normal file
5
app/views/api/ways/relations/index.json.jbuilder
Normal file
|
@ -0,0 +1,5 @@
|
|||
json.partial! "api/root_attributes"
|
||||
|
||||
json.elements do
|
||||
json.array! @relations, :partial => "api/relations/relation", :as => :relation
|
||||
end
|
5
app/views/api/ways/relations/index.xml.builder
Normal file
5
app/views/api/ways/relations/index.xml.builder
Normal 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
|
|
@ -1,5 +0,0 @@
|
|||
json.partial! "api/root_attributes"
|
||||
|
||||
json.elements do
|
||||
json.array! @ways, :partial => "way", :as => :way
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
xml.instruct!
|
||||
|
||||
xml.osm(OSM::API.new.xml_root_attributes) do |osm|
|
||||
osm << (render(@ways) || "")
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue