@@ -33,21 +33,25 @@ def active_admin_import options = {}, &block
3333 headers_rewrites : { }
3434 }
3535 options = default_options . deep_merge ( options )
36- options [ :template_object ] = ActiveAdminImport ::Model . new if options [ :template_object ] . blank?
37- params_key = ActiveModel ::Naming . param_key ( options [ :template_object ] )
36+ params_key = ActiveModel ::Naming . param_key ( options [ :template_object ] || ActiveAdminImport ::Model . new )
3837
3938 collection_action :import , method : :get do
40- @active_admin_import_model = options [ :template_object ]
39+ authorize! ( ActiveAdminImport ::Auth ::IMPORT , active_admin_config . resource_class )
40+
41+ @active_admin_import_model = options [ :template_object ] || ActiveAdminImport ::Model . new
4142 render template : options [ :template ]
4243 end
4344
4445 action_item only : :index do
45- link_to ( I18n . t ( 'active_admin_import.import_model' , model : options [ :resource_label ] ) , action : 'import' )
46+ if authorized? ( ActiveAdminImport ::Auth ::IMPORT , active_admin_config . resource_class )
47+ link_to ( I18n . t ( 'active_admin_import.import_model' , model : options [ :resource_label ] ) , action : 'import' )
48+ end
4649 end
4750
4851 collection_action :do_import , method : :post do
52+ authorize! ( ActiveAdminImport ::Auth ::IMPORT , active_admin_config . resource_class )
4953
50- @active_admin_import_model = options [ :template_object ]
54+ @active_admin_import_model = options [ :template_object ] || ActiveAdminImport :: Model . new
5155 @active_admin_import_model . assign_attributes ( params [ params_key ] . try ( :deep_symbolize_keys ) || { } )
5256 #go back to form
5357 return render template : options [ :template ] unless @active_admin_import_model . valid?
0 commit comments