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