Class: Decidim::Assemblies::Admin::AssemblyImportForm

Inherits:
Form show all
Includes:
HasBlobFile, HasUploadValidations, TranslatableAttributes
Defined in:
decidim-assemblies/app/forms/decidim/assemblies/admin/assembly_import_form.rb

Overview

A form object used to import an assembly from the admin dashboard.

Constant Summary collapse

JSON_MIME_TYPE =
"application/json"
ACCEPTED_TYPES =

Accepted mime types keys: are used for dynamic help text on admin form. values: are used to validate the file format of imported document.

WARNING: consider adding/removing the relative translation key at decidim.assemblies.admin.new_import.accepted_types when modifying this hash

{
  json: JSON_MIME_TYPE
}.freeze

Constants included from Decidim::AttributeObject::TypeMap

Decidim::AttributeObject::TypeMap::Boolean, Decidim::AttributeObject::TypeMap::Decimal

Instance Attribute Summary

Attributes inherited from Decidim::AttributeObject::Form

#context

Instance Method Summary collapse

Methods included from HasUploadValidations

#attached_uploader, #maximum_avatar_size, #maximum_upload_size

Methods included from TranslatableAttributes

#default_locale?

Methods inherited from Decidim::AttributeObject::Form

ensure_hash, from_model, from_params, hash_from, infer_model_name, #map_model, mimic, mimicked_model_name, model_name, #persisted?, #to_key, #to_model, #to_param, #valid?, #with_context

Methods included from Decidim::AttributeObject::Model

#[], #[]=, #attributes, #attributes_with_values, #initialize, #to_h

Instance Method Details

#document_textObject


46
47
48
# File 'decidim-assemblies/app/forms/decidim/assemblies/admin/assembly_import_form.rb', line 46

def document_text
  @document_text ||= blob&.download
end

#document_typeObject


61
62
63
# File 'decidim-assemblies/app/forms/decidim/assemblies/admin/assembly_import_form.rb', line 61

def document_type
  blob.content_type
end

#document_type_must_be_validObject


50
51
52
53
54
# File 'decidim-assemblies/app/forms/decidim/assemblies/admin/assembly_import_form.rb', line 50

def document_type_must_be_valid
  return if valid_mime_types.include?(document_type)

  errors.add(:document, i18n_invalid_document_type_text)
end

#i18n_invalid_document_type_textObject


65
66
67
68
69
# File 'decidim-assemblies/app/forms/decidim/assemblies/admin/assembly_import_form.rb', line 65

def i18n_invalid_document_type_text
  I18n.t("invalid_document_type",
         scope: "activemodel.errors.models.assembly.attributes.document",
         valid_mime_types: i18n_valid_mime_types_text)
end

#i18n_valid_mime_types_textObject


71
72
73
74
75
# File 'decidim-assemblies/app/forms/decidim/assemblies/admin/assembly_import_form.rb', line 71

def i18n_valid_mime_types_text
  ACCEPTED_TYPES.keys.map do |mime_type|
    I18n.t(mime_type, scope: "decidim.assemblies.admin.new_import.accepted_types")
  end.join(", ")
end

#valid_mime_typesObject

Return ACCEPTED_MIME_TYPES plus `text/plain` for better markdown support


57
58
59
# File 'decidim-assemblies/app/forms/decidim/assemblies/admin/assembly_import_form.rb', line 57

def valid_mime_types
  ACCEPTED_TYPES.values
end