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