8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/rhoconnect/condition/admin_required.rb', line 8
def include_admin_required_condition
set(:admin_required) do |value|
condition do
if value
begin
api_token = ApiToken.load(env[API_TOKEN_HEADER])
api_token = ApiToken.load(params[:api_token]) unless api_token
raise Rhoconnect::ApiException.new(422, "No API token provided") unless api_token
raise Rhoconnect::ApiException.new(422, "Invalid/missing API user") unless api_token.user and api_token.user.admin == 1
env[Rhoconnect::CURRENT_USER] = api_token.user
rescue Rhoconnect::ApiException => ae
throw :halt, [422, {'Content-Type' => 'text/plain'}, ae.message]
end
end
end
end
end
|