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 /app | |
| 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…
Diffstat (limited to '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 |
3 files changed, 7 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' |
