Sha256: b10e035529f52453a729ab54b99f4ff4aedb4012c6ce2c30467a40979f559dd8

Contents?: true

Size: 1.14 KB

Versions: 9

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

class Avo::Index::ResourceControlsComponent < Avo::ResourceComponent
  def initialize(resource: nil, reflection: nil, parent_model: nil)
    @resource = resource
    @reflection = reflection
    @parent_model = parent_model
  end

  def can_detach?
    @reflection.present? &&
    @resource.model.present? &&
    (@reflection.is_a?(::ActiveRecord::Reflection::HasManyReflection) || @reflection.is_a?(::ActiveRecord::Reflection::ThroughReflection))
  end

  def can_edit?
    @resource.authorization.authorize_action(:edit, raise_exception: false)
  end

  def can_view?
    @resource.authorization.authorize_action(:show, raise_exception: false)
  end

  def show_path
    if @parent_model.present?
      helpers.resource_path(@resource.model, via_resource_class: @parent_model.class, via_resource_id: @parent_model.id)
    else
      helpers.resource_path(@resource.model)
    end
  end

  def edit_path
    if @parent_model.present?
      helpers.edit_resource_path(@resource.model, via_resource_class: @parent_model.class, via_resource_id: @parent_model.id)
    else
      helpers.edit_resource_path(@resource.model)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
avo-0.5.0.beta9 app/components/avo/index/resource_controls_component.rb
avo-0.5.0.beta8 app/components/avo/index/resource_controls_component.rb
avo-0.5.0.beta7 app/components/avo/index/resource_controls_component.rb
avo-0.5.0.beta6 app/components/avo/index/resource_controls_component.rb
avo-0.5.0.beta5 app/components/avo/index/resource_controls_component.rb
avo-0.5.0.beta4 app/components/avo/index/resource_controls_component.rb
avo-0.5.0.beta3 app/components/avo/index/resource_controls_component.rb
avo-0.5.0.beta2 app/components/avo/index/resource_controls_component.rb
avo-0.5.0.beta1 app/components/avo/index/resource_controls_component.rb