Sha256: dd73fe0290abf36d757b0dc898242d68bcd5e784f51991f37686794f741995f2

Contents?: true

Size: 1.09 KB

Versions: 22

Compression:

Stored size: 1.09 KB

Contents

class Avo::ResourceComponent < Avo::BaseComponent
  def can_create?
    return authorize_association_for(:create) if @reflection.present?

    @resource.authorization.authorize_action(:create, raise_exception: false)
  end

  def can_delete?
    return authorize_association_for(:destroy) if @reflection.present?

    @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)
      reflection_resource.hydrate(model: @parent_model) if @parent_model.present?
      association_name = params["related_name"]

      if association_name.present?
        method_name = "#{policy_method}_#{association_name}?".to_sym

        if reflection_resource.authorization.has_method?(method_name, raise_exception: false)
          association_policy = reflection_resource.authorization.authorize_action(method_name, raise_exception: false)
        end
      end
    end

    association_policy
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
avo-2.5.2.pre.7 app/components/avo/resource_component.rb
avo-2.5.2.pre.2 app/components/avo/resource_component.rb
avo-2.5.2.pre.1 app/components/avo/resource_component.rb
avo-2.5.1 app/components/avo/resource_component.rb
avo-2.5.0 app/components/avo/resource_component.rb
avo-2.4.1 app/components/avo/resource_component.rb
avo-2.4.0 app/components/avo/resource_component.rb
avo-2.3.1.pre.6 app/components/avo/resource_component.rb
avo-2.3.1.pre.5 app/components/avo/resource_component.rb
avo-2.3.1.pre.4 app/components/avo/resource_component.rb
avo-2.3.1.pre.3 app/components/avo/resource_component.rb
avo-2.3.1.pre.2 app/components/avo/resource_component.rb
avo-2.3.1.pre.1 app/components/avo/resource_component.rb
avo-2.3.0 app/components/avo/resource_component.rb
avo-2.2.2 app/components/avo/resource_component.rb
avo-2.2.1 app/components/avo/resource_component.rb
avo-2.2.0 app/components/avo/resource_component.rb
avo-2.1.2.pre2 app/components/avo/resource_component.rb
avo-2.1.2.pre1 app/components/avo/resource_component.rb
avo-2.1.1 app/components/avo/resource_component.rb