]> git.openstreetmap.org Git - rails.git/blob - app/controllers/api/permissions_controller.rb
Prefer String#match? over butt ugly Regexp#match?
[rails.git] / app / controllers / api / permissions_controller.rb
1 module Api
2   class PermissionsController < ApplicationController
3     skip_before_action :verify_authenticity_token
4     before_action :api_deny_access_handler
5
6     authorize_resource :class => false
7
8     before_action :check_api_readable
9     before_action :setup_user_auth
10     around_action :api_call_handle_error, :api_call_timeout
11
12     # External apps that use the api are able to query which permissions
13     # they have. This currently returns a list of permissions granted to the current user:
14     # * if authenticated via OAuth, this list will contain all permissions granted by the user to the access_token.
15     # * if authenticated via basic auth all permissions are granted, so the list will contain all permissions.
16     # * unauthenticated users have no permissions, so the list will be empty.
17     def show
18       @permissions = if current_token.present?
19                        ClientApplication.all_permissions.select { |p| current_token.read_attribute(p) }
20                      elsif current_user
21                        ClientApplication.all_permissions
22                      else
23                        []
24                      end
25     end
26   end
27 end