1

How to disable active_admin_import action by condition on index page

I have a code to disable 'new, create, destroy' actions by condition. Need to do same with active_admin_import

controller do
    def action_methods
      if Admin::PurchaseOrderDecorator.decorate(parent).received?
        super - %w(new create destroy)
      else
        super
      end
    end
  end

active_admin_import(
  ....
  )
Fivell
  • 11,829
  • 3
  • 61
  • 99
  • disable like delete it or hiding it? I don't know what exactly your refering to but you can try it buy doing it on the application controller –  Nov 07 '19 at 16:49
  • Not to delete, hide link, route. Disable this functional in general. If parent has some condition. For example order is already 'received' I can`t upload file via active_admin_import method – Grinko Dmitry Nov 08 '19 at 07:34

1 Answers1

2

you can use if option

https://github.com/activeadmin-plugins/active_admin_import/commit/aa0be4bbb3151ab50911c1041415044936fba068

something like this might work

active_admin_import if: -> { Admin::PurchaseOrderDecorator.decorate(parent).received? }

However one more option to handle conditional access to actions through policies

# frozen_string_literal: true
class OrderItemPolicy < ApplicationPolicy
  def import?
    !order.completed?
  end
end

Docs

https://activeadmin.info/13-authorization-adapter.html

Pundit https://github.com/varvet/pundit

Fivell
  • 11,829
  • 3
  • 61
  • 99