Sha256: 3908161c37b1270ffad44df223462512b4e0f936d9bffada10293d3808d474ad

Contents?: true

Size: 1.49 KB

Versions: 72

Compression:

Stored size: 1.49 KB

Contents

module ForestLiana
  module Ability
    include ForestLiana::Ability::Permission

    ALLOWED_PERMISSION_LEVELS = %w[admin editor developer].freeze

    def forest_authorize!(action, user, collection, args = {})
      case action
      when 'browse', 'read', 'edit', 'add', 'delete', 'export'
        raise ForestLiana::Ability::Exceptions::AccessDenied.new unless is_crud_authorized?(action, user, collection)
      when 'chart'
        if ALLOWED_PERMISSION_LEVELS.exclude?(user['permission_level'])
          raise ForestLiana::Errors::HTTP422Error.new('The argument parameters is missing') if args[:parameters].nil?
          raise ForestLiana::Ability::Exceptions::AccessDenied.new unless is_chart_authorized?(user, args[:parameters])
        end
      when 'action'
        validate_collection collection
        raise ForestLiana::Errors::HTTP422Error.new('You must implement the arguments : parameters, endpoint & http_method') if args[:parameters].nil? || args[:endpoint].nil? || args[:http_method].nil?
        is_smart_action_authorized?(user, collection, args[:parameters], args[:endpoint], args[:http_method])
      else
        raise ForestLiana::Ability::Exceptions::AccessDenied.new
      end
    end

    private

    def validate_collection(collection)
      if collection.nil? || !SchemaUtils.model_included?(collection)
        raise ForestLiana::Errors::HTTP422Error.new('The conditional smart actions are not supported with Smart Collection. Please contact an administrator.')
      end
    end
  end
end

Version data entries

72 entries across 72 versions & 1 rubygems

Version Path
forest_liana-9.7.0 app/services/forest_liana/ability.rb
forest_liana-9.6.4 app/services/forest_liana/ability.rb
forest_liana-9.6.3 app/services/forest_liana/ability.rb
forest_liana-9.6.0 app/services/forest_liana/ability.rb
forest_liana-9.5.7 app/services/forest_liana/ability.rb
forest_liana-9.5.6 app/services/forest_liana/ability.rb
forest_liana-9.5.5 app/services/forest_liana/ability.rb
forest_liana-9.5.4 app/services/forest_liana/ability.rb
forest_liana-9.5.3 app/services/forest_liana/ability.rb
forest_liana-9.5.2 app/services/forest_liana/ability.rb
forest_liana-9.5.1 app/services/forest_liana/ability.rb
forest_liana-9.5.0 app/services/forest_liana/ability.rb
forest_liana-9.4.3 app/services/forest_liana/ability.rb
forest_liana-9.4.2 app/services/forest_liana/ability.rb
forest_liana-9.4.1 app/services/forest_liana/ability.rb
forest_liana-9.4.0 app/services/forest_liana/ability.rb
forest_liana-8.3.3 app/services/forest_liana/ability.rb
forest_liana-9.3.16 app/services/forest_liana/ability.rb
forest_liana-9.3.15 app/services/forest_liana/ability.rb
forest_liana-9.3.14 app/services/forest_liana/ability.rb