]> git.openstreetmap.org Git - rails.git/blob - app/controllers/api/users_controller.rb
5c3a6cb8e7e12d01f775c43f8457dad490f2dd6a
[rails.git] / app / controllers / api / users_controller.rb
1 module Api
2   class UsersController < ApiController
3     layout "site", :except => [:api_details]
4
5     before_action :disable_terms_redirect, :only => [:api_details]
6     before_action :authorize, :only => [:api_details, :api_gpx_files]
7     before_action :api_deny_access_handler
8
9     authorize_resource
10
11     before_action :check_api_readable
12     around_action :api_call_handle_error
13     before_action :lookup_user_by_id, :only => [:api_read]
14
15     def api_read
16       if @user.visible?
17         render :action => :api_read, :content_type => "text/xml"
18       else
19         head :gone
20       end
21     end
22
23     def api_details
24       @user = current_user
25       render :action => :api_read, :content_type => "text/xml"
26     end
27
28     def api_users
29       raise OSM::APIBadUserInput, "The parameter users is required, and must be of the form users=id[,id[,id...]]" unless params["users"]
30
31       ids = params["users"].split(",").collect(&:to_i)
32
33       raise OSM::APIBadUserInput, "No users were given to search for" if ids.empty?
34
35       @users = User.visible.find(ids)
36
37       render :action => :api_users, :content_type => "text/xml"
38     end
39
40     def api_gpx_files
41       doc = OSM::API.new.get_xml_doc
42       current_user.traces.reload.each do |trace|
43         doc.root << trace.to_xml_node
44       end
45       render :xml => doc.to_s
46     end
47
48     private
49
50     ##
51     # ensure that there is a "user" instance variable
52     def lookup_user_by_id
53       @user = User.find(params[:id])
54     end
55
56     ##
57     #
58     def disable_terms_redirect
59       # this is necessary otherwise going to the user terms page, when
60       # having not agreed already would cause an infinite redirect loop.
61       # it's .now so that this doesn't propagate to other pages.
62       flash.now[:skip_terms] = true
63     end
64   end
65 end