diff options
| author | Luc Donnet | 2017-10-24 15:55:11 +0200 |
|---|---|---|
| committer | GitHub | 2017-10-24 15:55:11 +0200 |
| commit | d36f86eabbb749d30e70c45dae3cc4343ce137ee (patch) | |
| tree | 27e0421f49827fd2af4c94815c71a588260f0ade | |
| parent | efe056fb645f0380e594f57ad058409194f3becd (diff) | |
| parent | 489d2b19f4039daa14799122901f6e27b6c0dba5 (diff) | |
| download | chouette-core-d36f86eabbb749d30e70c45dae3cc4343ce137ee.tar.bz2 | |
Merge pull request #99 from af83/import_file_extension
Refs #4762 Add file extension checking before importing (standard app…
| -rw-r--r-- | app/controllers/api/v1/imports_controller.rb | 6 | ||||
| -rw-r--r-- | app/models/import.rb | 1 | ||||
| -rw-r--r-- | app/views/imports/_form.html.slim | 2 | ||||
| -rw-r--r-- | config/locales/imports.en.yml | 4 | ||||
| -rw-r--r-- | config/locales/imports.fr.yml | 4 |
5 files changed, 15 insertions, 2 deletions
diff --git a/app/controllers/api/v1/imports_controller.rb b/app/controllers/api/v1/imports_controller.rb index 6050418d8..3d7f4ca79 100644 --- a/app/controllers/api/v1/imports_controller.rb +++ b/app/controllers/api/v1/imports_controller.rb @@ -5,7 +5,11 @@ class Api::V1::ImportsController < Api::V1::IbooController def create args = workbench_import_params.merge(creator: 'Webservice') @import = parent.workbench_imports.create(args) - create! + if @import.valid? + create! + else + render json: { status: "error", messages: @import.errors.full_messages } + end end private diff --git a/app/models/import.rb b/app/models/import.rb index 64f713914..4ff8326ab 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -18,6 +18,7 @@ class Import < ActiveRecord::Base validates :file, presence: true validates_presence_of :workbench, :creator + validates_format_of :file, with: %r{\.zip\z}i, message: I18n.t('activerecord.errors.models.imports.wrong_file_extension') before_create :initialize_fields diff --git a/app/views/imports/_form.html.slim b/app/views/imports/_form.html.slim index 0fbf578be..95d97c534 100644 --- a/app/views/imports/_form.html.slim +++ b/app/views/imports/_form.html.slim @@ -9,6 +9,6 @@ .form-group = form.label :file, t('activerecord.attributes.import.resources'), class: 'control-label col-sm-4 col-xs-5' .col-sm-8.col-xs-7 - = form.input_field :file, label: false, class: 'form-control' + = form.input :file, label: false, class: 'form-control' = form.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'wb_import_form' diff --git a/config/locales/imports.en.yml b/config/locales/imports.en.yml index 9bf877c86..f3bcad9e9 100644 --- a/config/locales/imports.en.yml +++ b/config/locales/imports.en.yml @@ -53,6 +53,10 @@ en: zero: "import" one: "NeTEx import" other: "imports" + errors: + models: + imports: + wrong_file_extension: "The imported file must be a zip file" attributes: import: resources: "File to import" diff --git a/config/locales/imports.fr.yml b/config/locales/imports.fr.yml index 6998c89d2..6e74fa33c 100644 --- a/config/locales/imports.fr.yml +++ b/config/locales/imports.fr.yml @@ -53,6 +53,10 @@ fr: zero: "import" one: "import NeTEx" other: "imports" + errors: + models: + imports: + wrong_file_extension: "Le fichier importé doit être au format zip" attributes: import: resources: "Fichier à importer" |
