]> git.openstreetmap.org Git - rails.git/blob - app/controllers/api/users_controller.rb
Merge remote-tracking branch 'upstream/pull/1926'
[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 => [:details]
6     before_action :authorize, :only => [:details, :gpx_files]
7
8     authorize_resource
9
10     before_action :check_api_readable
11     around_action :api_call_handle_error
12     before_action :lookup_user_by_id, :only => [:show]
13
14     def show
15       if @user.visible?
16         render :content_type => "text/xml"
17       else
18         head :gone
19       end
20     end
21
22     def details
23       @user = current_user
24       render :action => :show, :content_type => "text/xml"
25     end
26
27     def index
28       raise OSM::APIBadUserInput, "The parameter users is required, and must be of the form users=id[,id[,id...]]" unless params["users"]
29
30       ids = params["users"].split(",").collect(&:to_i)
31
32       raise OSM::APIBadUserInput, "No users were given to search for" if ids.empty?
33
34       @users = User.visible.find(ids)
35
36       render :content_type => "text/xml"
37     end
38
39     def gpx_files
40       @traces = current_user.traces.reload
41       render :content_type => "application/xml"
42     end
43
44     private
45
46     ##
47     # ensure that there is a "user" instance variable
48     def lookup_user_by_id
49       @user = User.find(params[:id])
50     end
51
52     ##
53     #
54     def disable_terms_redirect
55       # this is necessary otherwise going to the user terms page, when
56       # having not agreed already would cause an infinite redirect loop.
57       # it's .now so that this doesn't propagate to other pages.
58       flash.now[:skip_terms] = true
59     end
60   end
61 end