Sha256: d15838d8da9104c5ad080b23b5ab56da7c07e5dcb0ff55120dd466840e9a65e3

Contents?: true

Size: 894 Bytes

Versions: 23

Compression:

Stored size: 894 Bytes

Contents

module MnoEnterprise
  class Jpi::V1::BaseResourceController < ApplicationController
    before_filter :check_authorization
    
    protected

      def timestamp
        @timestamp ||= (params[:timestamp] || 0).to_i
      end

      def parent_organization
        @parent_organization ||= current_user.organizations.to_a.find do |o|
          key = (params[:organization_id].to_i == 0) ? o.uid : o.id.to_s
          key == params[:organization_id].to_s
        end
      end

      # Check current user is logged in
      # Check organization is valid if specified
      def check_authorization
        unless current_user
          render nothing: true, status: :unauthorized
          return false
        end
        if params[:organization_id] && !parent_organization
          render nothing: true, status: :forbidden
          return false
        end
        true
      end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
mno-enterprise-api-3.1.4 app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb
mno-enterprise-api-3.0.7 app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb
mno-enterprise-api-2.0.9 app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb
mno-enterprise-api-3.1.3 app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb
mno-enterprise-api-3.0.6 app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb
mno-enterprise-api-2.0.8 app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb
mno-enterprise-api-3.1.2 app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb
mno-enterprise-api-3.0.5 app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb
mno-enterprise-api-2.0.7 app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb
mno-enterprise-api-2.0.6 app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb
mno-enterprise-api-2.0.5 app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb
mno-enterprise-api-3.1.1 app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb
mno-enterprise-api-3.0.4 app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb
mno-enterprise-api-2.0.4 app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb
mno-enterprise-api-3.1.0 app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb
mno-enterprise-api-3.0.3 app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb
mno-enterprise-api-2.0.3 app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb
mno-enterprise-api-3.0.2 app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb
mno-enterprise-api-2.0.2 app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb
mno-enterprise-api-3.0.1 app/controllers/mno_enterprise/jpi/v1/base_resource_controller.rb