diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/api/v1/imports_controller.rb | 7 | ||||
| -rw-r--r-- | app/controllers/imports_controller.rb | 7 | ||||
| -rw-r--r-- | app/models/import.rb | 6 | ||||
| -rw-r--r-- | app/views/imports/_form.html.slim | 2 |
4 files changed, 20 insertions, 2 deletions
diff --git a/app/controllers/api/v1/imports_controller.rb b/app/controllers/api/v1/imports_controller.rb index 6050418d8..197e23337 100644 --- a/app/controllers/api/v1/imports_controller.rb +++ b/app/controllers/api/v1/imports_controller.rb @@ -5,7 +5,12 @@ 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 + binding.pry + render json: { status: "error", messages: @import.errors.full_messages } + end end private diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index 3c52dc935..66dccc243 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -38,6 +38,13 @@ class ImportsController < BreadcrumbController end end + def create + create! do |success, failure| + success.html { redirect_to workbench_imports_path } + failure.html { flash.now[:error] = @import.errors[:wrong_file_extension][0] if @import.file.file; render :new } + end + end + def download if params[:token] == resource.token_download send_file resource.file.path diff --git a/app/models/import.rb b/app/models/import.rb index 64f713914..72d9f2ce6 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -19,6 +19,12 @@ class Import < ActiveRecord::Base validates :file, presence: true validates_presence_of :workbench, :creator + validate def file_extension_must_be_zip + if self.file.file + errors.add(:wrong_file_extension, I18n.t('activerecord.errors.models.imports.wrong_file_extension')) unless self.file.file.extension == "zip" + end + end + before_create :initialize_fields def self.model_name 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' |
