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