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