How to DISABLE active_admin_import action by condition

279 views Asked by At

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(
  ....
  )
1

There are 1 answers

0
Fivell On BEST ANSWER

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