]> git.openstreetmap.org Git - rails.git/blob - app/controllers/api/permissions_controller.rb
Merge pull request #5932 from tomhughes/frozen-strings
[rails.git] / app / controllers / api / permissions_controller.rb
1 # frozen_string_literal: true
2
3 module Api
4   class PermissionsController < ApiController
5     authorize_resource :class => false
6
7     before_action :setup_user_auth
8     before_action :set_request_formats
9
10     # External apps that use the api are able to query which permissions
11     # they have. This currently returns a list of permissions granted to the current user:
12     # * if authenticated via OAuth, this list will contain all permissions granted by the user to the access_token.
13     # * unauthenticated users have no permissions, so the list will be empty.
14     def show
15       @permissions = if doorkeeper_token.present?
16                        doorkeeper_token.scopes.map { |s| :"allow_#{s}" }
17                      else
18                        []
19                      end
20
21       respond_to do |format|
22         format.xml
23         format.json
24       end
25     end
26   end
27 end