Allow import/export of instance-level domain blocks/allows (#1754)
* Allow import/export of instance-level domain blocks/allows. Fixes #15095 * Pacify circleci * Address simple code review feedback * Add headers to exported CSV * Extract common import/export functionality to AdminExportControllerConcern * Add additional fields to instance-blocked domain export * Address review feedback * Split instance domain block/allow import/export into separate pages/controllers * Address code review feedback * Pacify DeepSource * Work around Paperclip::HasAttachmentFile for Rails 6 * Fix deprecated API warning in export tests * Remove after_commit workaround
This commit is contained in:
parent
dc350be6f5
commit
94e98864e3
16 changed files with 414 additions and 1 deletions
29
app/models/admin/import.rb
Normal file
29
app/models/admin/import.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# A non-activerecord helper class for csv upload
|
||||
class Admin::Import
|
||||
extend ActiveModel::Callbacks
|
||||
include ActiveModel::Model
|
||||
include Paperclip::Glue
|
||||
|
||||
FILE_TYPES = %w(text/plain text/csv application/csv).freeze
|
||||
|
||||
# Paperclip required callbacks
|
||||
define_model_callbacks :save, only: [:after]
|
||||
define_model_callbacks :destroy, only: [:before, :after]
|
||||
|
||||
attr_accessor :data_file_name, :data_content_type
|
||||
|
||||
has_attached_file :data
|
||||
validates_attachment_content_type :data, content_type: FILE_TYPES
|
||||
validates_attachment_presence :data
|
||||
validates_with AdminImportValidator, on: :create
|
||||
|
||||
def save
|
||||
run_callbacks :save
|
||||
end
|
||||
|
||||
def destroy
|
||||
run_callbacks :destroy
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue