Sha256: 9a0713a2461a047c6eb793fb6e88e84a61b7bc78b6c1a08d16d12589b5906cf7

Contents?: true

Size: 958 Bytes

Versions: 23

Compression:

Stored size: 958 Bytes

Contents

module Rhoconnect
  module Condition
    module AdminRequired
      def self.extended(base)
        base.include_admin_required_condition
      end

      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
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
rhoconnect-4.0.0.beta.24 lib/rhoconnect/condition/admin_required.rb
rhoconnect-4.0.0.beta.10 lib/rhoconnect/condition/admin_required.rb
rhoconnect-4.0.0.beta.12 lib/rhoconnect/condition/admin_required.rb