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-7.6.0 lib/rhoconnect/condition/admin_required.rb
rhoconnect-7.5.1 lib/rhoconnect/condition/admin_required.rb
rhoconnect-7.4.1 lib/rhoconnect/condition/admin_required.rb
rhoconnect-7.1.17 lib/rhoconnect/condition/admin_required.rb
rhoconnect-6.2.0 lib/rhoconnect/condition/admin_required.rb
rhoconnect-6.0.11 lib/rhoconnect/condition/admin_required.rb
rhoconnect-5.5.18 lib/rhoconnect/condition/admin_required.rb
rhoconnect-5.5.17 lib/rhoconnect/condition/admin_required.rb
rhoconnect-5.5.15 lib/rhoconnect/condition/admin_required.rb
rhoconnect-5.5.0.22 lib/rhoconnect/condition/admin_required.rb
rhoconnect-5.5.2 lib/rhoconnect/condition/admin_required.rb
rhoconnect-5.5.0.7 lib/rhoconnect/condition/admin_required.rb
rhoconnect-5.5.0.3 lib/rhoconnect/condition/admin_required.rb
rhoconnect-5.5.0 lib/rhoconnect/condition/admin_required.rb
rhoconnect-5.1.1 lib/rhoconnect/condition/admin_required.rb
rhoconnect-4.0.4 lib/rhoconnect/condition/admin_required.rb
rhoconnect-4.0.3 lib/rhoconnect/condition/admin_required.rb
rhoconnect-4.0.2 lib/rhoconnect/condition/admin_required.rb
rhoconnect-4.0.1 lib/rhoconnect/condition/admin_required.rb
rhoconnect-4.0.0 lib/rhoconnect/condition/admin_required.rb