aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcedricnjanga2018-05-16 10:26:15 -0700
committerJohan Van Ryseghem2018-05-29 08:41:43 +0200
commitd1f7307f3aaf595cc46cbd1249eef10ab0092321 (patch)
tree9f66e1bea571a2015f5338d3cffc062bcf3d219d
parentf5cb11a5dc3b77d6fd238578401b0a06e408cb79 (diff)
downloadchouette-core-d1f7307f3aaf595cc46cbd1249eef10ab0092321.tar.bz2
Refs #6916 Fix import file format validation
-rw-r--r--app/models/concerns/iev_interfaces/task.rb2
-rw-r--r--app/models/import/base.rb1
-rw-r--r--config/locales/imports.en.yml10
-rw-r--r--config/locales/imports.fr.yml11
4 files changed, 8 insertions, 16 deletions
diff --git a/app/models/concerns/iev_interfaces/task.rb b/app/models/concerns/iev_interfaces/task.rb
index e40808009..76bcec699 100644
--- a/app/models/concerns/iev_interfaces/task.rb
+++ b/app/models/concerns/iev_interfaces/task.rb
@@ -7,6 +7,8 @@ module IevInterfaces::Task
belongs_to :referential
mount_uploader :file, ImportUploader
+ validates_presence_of :file, presence: true, unless: Proc.new {|import| import.errors[:file].present? }
+ validates_integrity_of :file
has_many :children, foreign_key: :parent_id, class_name: self.name, dependent: :destroy
diff --git a/app/models/import/base.rb b/app/models/import/base.rb
index dcd710e58..7c1cfaa50 100644
--- a/app/models/import/base.rb
+++ b/app/models/import/base.rb
@@ -1,6 +1,5 @@
class Import::Base < ApplicationModel
self.table_name = "imports"
- validates :file, presence: true
def self.messages_class_name
"Import::Message"
diff --git a/config/locales/imports.en.yml b/config/locales/imports.en.yml
index ed34043c5..51939c1fb 100644
--- a/config/locales/imports.en.yml
+++ b/config/locales/imports.en.yml
@@ -80,13 +80,6 @@ en:
zero: "import"
one: "NeTEx import"
other: "imports"
- errors:
- models:
- import:
- base:
- attributes:
- file:
- wrong_file_extension: "The imported file must be a zip file"
attributes:
attrs: &attrs
resources: "File to import"
@@ -107,6 +100,9 @@ en:
<<: *attrs
base:
<<: *attrs
+ errors:
+ messages:
+ extension_whitelist_error: "You are not allowed to upload %{extension} files, allowed types: %{allowed_types}"
flash:
imports:
create:
diff --git a/config/locales/imports.fr.yml b/config/locales/imports.fr.yml
index 5affd2c0c..219414e57 100644
--- a/config/locales/imports.fr.yml
+++ b/config/locales/imports.fr.yml
@@ -84,13 +84,6 @@ fr:
zero: "import"
one: "import NeTEx"
other: "imports"
- errors:
- models:
- import:
- base:
- attributes:
- file:
- wrong_file_extension: "Le fichier importé doit être au format zip"
attributes:
attrs: &attrs
resources: "Fichier à importer"
@@ -111,7 +104,9 @@ fr:
<<: *attrs
base:
<<: *attrs
-
+ errors:
+ messages:
+ extension_whitelist_error: "Vous n'êtes pas autorisé à uploader des fichiers %{extension}, types autorisés: %{allowed_types}"
flash:
imports:
create: