Map 'full' to api way show action

This commit is contained in:
Anton Khorev 2025-02-01 16:49:08 +03:00
parent 51dab659f5
commit 0f2aa939d4
8 changed files with 58 additions and 44 deletions

View file

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

View file

@ -26,12 +26,21 @@ module Api
end
def show
@way = Way.find(params[:id])
@way = Way
@way = @way.includes(:nodes => :node_tags) if params[:full]
@way = @way.find(params[:id])
response.last_modified = @way.timestamp
response.last_modified = @way.timestamp unless params[:full]
if @way.visible
# Render the result
if params[:full]
@nodes = []
@way.nodes.uniq.each do |node|
@nodes << node if node.visible
end
end
respond_to do |format|
format.xml
format.json
@ -72,26 +81,6 @@ module Api
end
end
def full
@way = Way.includes(:nodes => :node_tags).find(params[:id])
if @way.visible
@nodes = []
@way.nodes.uniq.each do |node|
@nodes << node if node.visible
end
# Render the result
respond_to do |format|
format.xml
format.json
end
else
head :gone
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

View file

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

View file

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

View file

@ -1,5 +1,6 @@
json.partial! "api/root_attributes"
json.elements do
json.array! @nodes, :partial => "/api/nodes/node", :as => :node if @nodes
json.array! [@way], :partial => "way", :as => :way
end

View file

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