Sha256: 4d9e86d339b24d32c8cf9ef2066e61b013d1689a511417b14c95788a3d7ff806

Contents?: true

Size: 899 Bytes

Versions: 81

Compression:

Stored size: 899 Bytes

Contents

# frozen_string_literal: true

class Avo::Fields::HasOneField::ShowComponent < Avo::Fields::ShowComponent
  include Avo::ApplicationHelper

  def can_attach?
    attach_policy = true
    if @field.present?
      reflection_resource = @field.target_resource
      if reflection_resource.present? && @resource.present?
        method_name = ("attach_#{reflection_resource.model_key}?").to_sym
        defined_policy_methods = @resource.authorization.defined_methods(@resource.model_class, raise_exception: false)

        if defined_policy_methods.present? && defined_policy_methods.include?(method_name)
          attach_policy = @resource.authorization.authorize_action(method_name, raise_exception: false)
        end
      end
    end
    attach_policy
  end

  def attach_path
    helpers.avo.resources_associations_new_path(@resource.singular_model_key, @resource.model.id, @field.id)
  end
end

Version data entries

81 entries across 81 versions & 1 rubygems

Version Path
avo-2.11.1 app/components/avo/fields/has_one_field/show_component.rb
avo-2.11.1.pre.2 app/components/avo/fields/has_one_field/show_component.rb
avo-2.11.1.pre.1 app/components/avo/fields/has_one_field/show_component.rb
avo-2.11.0 app/components/avo/fields/has_one_field/show_component.rb
avo-2.10.3.pre.1 app/components/avo/fields/has_one_field/show_component.rb
avo-1.25.2 app/components/avo/fields/has_one_field/show_component.rb
avo-2.10.2 app/components/avo/fields/has_one_field/show_component.rb
avo-2.9.2.pre1 app/components/avo/fields/has_one_field/show_component.rb
avo-2.10.0 app/components/avo/fields/has_one_field/show_component.rb
avo-2.9.1.pre7 app/components/avo/fields/has_one_field/show_component.rb
avo-2.9.1.pre6 app/components/avo/fields/has_one_field/show_component.rb
avo-2.9.1.pre5 app/components/avo/fields/has_one_field/show_component.rb
avo-2.9.1.pre4 app/components/avo/fields/has_one_field/show_component.rb
avo-2.9.1.pre3 app/components/avo/fields/has_one_field/show_component.rb
avo-2.9.1.pre2 app/components/avo/fields/has_one_field/show_component.rb
avo-2.9.1.pre1 app/components/avo/fields/has_one_field/show_component.rb
avo-2.9.0 app/components/avo/fields/has_one_field/show_component.rb
avo-2.8.0 app/components/avo/fields/has_one_field/show_component.rb
avo-2.7.1.pre.1 app/components/avo/fields/has_one_field/show_component.rb
avo-2.7.0 app/components/avo/fields/has_one_field/show_component.rb