Sha256: 76f22642cef0bd0b30b6ff847787ae5d3378045b9b4c1334a02840f7710fd0c6

Contents?: true

Size: 1.08 KB

Versions: 34

Compression:

Stored size: 1.08 KB

Contents

class Avo::ResourceComponent < ViewComponent::Base
  def can_create?
    @resource.authorization.authorize_action(:create, raise_exception: false)
  end

  def can_delete?
    @resource.authorization.authorize_action(:destroy, raise_exception: false)
  end

  def authorize_association_for(policy_method)
    association_policy = true
    if @reflection.present?
      reflection_resource = ::Avo::App.get_resource_by_model_name(@reflection.active_record.name)
      if reflection_resource.present?
        method_name = ("#{policy_method}_#{@reflection.name.to_s.underscore}?").to_sym
        defined_policy_methods = reflection_resource.authorization.defined_methods(reflection_resource.model_class, raise_exception: false)
        if defined_policy_methods.present? && defined_policy_methods.include?(method_name)
          association_policy = reflection_resource.authorization.authorize_action(method_name, raise_exception: false)
        end
      end
    end

    association_policy
  end

  private

  def simple_relation?
    @reflection.is_a? ::ActiveRecord::Reflection::HasManyReflection
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
avo-1.18.2 app/components/avo/resource_component.rb
avo-1.18.2.pre.0 app/components/avo/resource_component.rb
avo-1.18.1 app/components/avo/resource_component.rb
avo-1.18.0 app/components/avo/resource_component.rb
avo-1.18.0.pre.3 app/components/avo/resource_component.rb
avo-1.18.0.pre.2 app/components/avo/resource_component.rb
avo-1.18.0.pre.1 app/components/avo/resource_component.rb
avo-1.17.1 app/components/avo/resource_component.rb
avo-1.17.0 app/components/avo/resource_component.rb
avo-1.16.4 app/components/avo/resource_component.rb
avo-1.16.3 app/components/avo/resource_component.rb
avo-1.16.2 app/components/avo/resource_component.rb
avo-1.16.1 app/components/avo/resource_component.rb
avo-1.16.0 app/components/avo/resource_component.rb
avo-1.15.0 app/components/avo/resource_component.rb
avo-1.15.0.pre.1 app/components/avo/resource_component.rb
avo-1.14.0 app/components/avo/resource_component.rb
avo-1.13.3 app/components/avo/resource_component.rb
avo-1.13.2 app/components/avo/resource_component.rb
avo-1.13.1 app/components/avo/resource_component.rb