Sha256: 5bcabdef9737ce108e19bf883efd635eb58a4f51e6be46983cca5e1244661268

Contents?: true

Size: 1.15 KB

Versions: 71

Compression:

Stored size: 1.15 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

71 entries across 71 versions & 1 rubygems

Version Path
avo-1.10.2 app/components/avo/index/resource_controls_component.rb
avo-1.10.1 app/components/avo/index/resource_controls_component.rb
avo-1.10.0 app/components/avo/index/resource_controls_component.rb
avo-1.9.1 app/components/avo/index/resource_controls_component.rb
avo-1.9.0 app/components/avo/index/resource_controls_component.rb
avo-1.8.4 app/components/avo/index/resource_controls_component.rb
avo-1.8.3 app/components/avo/index/resource_controls_component.rb
avo-1.8.2 app/components/avo/index/resource_controls_component.rb
avo-1.8.1 app/components/avo/index/resource_controls_component.rb
avo-1.8.0 app/components/avo/index/resource_controls_component.rb
avo-1.7.3 app/components/avo/index/resource_controls_component.rb
avo-1.7.3.pre.1 app/components/avo/index/resource_controls_component.rb
avo-1.7.2 app/components/avo/index/resource_controls_component.rb
avo-1.7.1 app/components/avo/index/resource_controls_component.rb
avo-1.7.0 app/components/avo/index/resource_controls_component.rb
avo-1.6.4.pre.1 app/components/avo/index/resource_controls_component.rb
avo-1.6.3.pre.3 app/components/avo/index/resource_controls_component.rb
avo-1.6.3.pre.2 app/components/avo/index/resource_controls_component.rb
avo-1.6.3.pre.1 app/components/avo/index/resource_controls_component.rb
avo-1.6.2.pre.1 app/components/avo/index/resource_controls_component.rb