can [:history, :version], OldNode
can [:history, :version], OldWay
can [:history, :version], OldRelation
+ can [:show], UserBlock
end
if user&.active?
--- /dev/null
+module Api
+ class UserBlocksController < ApiController
+ before_action :check_api_readable
+
+ authorize_resource
+
+ around_action :api_call_handle_error, :api_call_timeout
+ before_action :set_request_formats
+
+ def show
+ raise OSM::APIBadUserInput, "No id was given" unless params[:id]
+
+ @user_block = UserBlock.find(params[:id])
+ rescue ActiveRecord::RecordNotFound
+ raise OSM::APINotFoundError
+ end
+ end
+end
--- /dev/null
+attrs = {
+ "id" => user_block.id,
+ "created_at" => user_block.created_at.xmlschema,
+ "updated_at" => user_block.updated_at.xmlschema,
+ "ends_at" => user_block.ends_at.xmlschema,
+ "needs_view" => user_block.needs_view
+}
+
+xml.user_block(attrs) do
+ xml.user :uid => user_block.user_id, :user => user_block.user.display_name
+ xml.creator :uid => user_block.creator_id, :user => user_block.creator.display_name
+ xml.revoker :uid => user_block.revoker_id, :user => user_block.revoker.display_name if user_block.revoker
+ xml.reason user_block.reason
+end
--- /dev/null
+xml.instruct!
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+ osm << (render(@user_block) || "")
+end
post "notes/editPOIexec" => "api/notes#comment"
get "notes/getGPX" => "api/notes#index", :format => "gpx"
get "notes/getRSSfeed" => "api/notes#feed", :format => "rss"
+
+ resources :user_blocks, :only => [:show], :constraints => { :id => /\d+/ }, :controller => "api/user_blocks", :as => :api_user_blocks
end
# Data browsing
--- /dev/null
+require "test_helper"
+
+module Api
+ class UserBlocksControllerTest < ActionDispatch::IntegrationTest
+ def test_routes
+ assert_routing(
+ { :path => "/api/0.6/user_blocks/1", :method => :get },
+ { :controller => "api/user_blocks", :action => "show", :id => "1" }
+ )
+ end
+
+ def test_show
+ block = create(:user_block)
+
+ get api_user_block_path(:id => block)
+ assert_response :success
+ assert_select "user_block[id='#{block.id}']", 1
+ end
+
+ def test_show_not_found
+ get api_user_block_path(:id => 123)
+ assert_response :not_found
+ assert_equal "text/plain", @response.media_type
+ end
+ end
+end