Sha256: 267bd2bd7105636e90bf4714a36fa1b286314fd33bd1759477fcd80bab57c2c4

Contents?: true

Size: 812 Bytes

Versions: 34

Compression:

Stored size: 812 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_class.model_name.singular_route_key.underscore + '?').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
end

Version data entries

34 entries across 34 versions & 1 rubygems

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