aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcedricnjanga2017-10-24 15:50:43 +0200
committercedricnjanga2017-10-24 15:50:43 +0200
commit489d2b19f4039daa14799122901f6e27b6c0dba5 (patch)
tree8c1b3c3d18646b8dc4cad1560ee1fa17cc0ac745
parent4e3fefe39274424c14c12cd93016fdf495e7cc08 (diff)
downloadchouette-core-489d2b19f4039daa14799122901f6e27b6c0dba5.tar.bz2
Simplify extension file validation
-rw-r--r--app/controllers/api/v1/imports_controller.rb1
-rw-r--r--app/controllers/imports_controller.rb7
-rw-r--r--app/models/import.rb7
3 files changed, 1 insertions, 14 deletions
diff --git a/app/controllers/api/v1/imports_controller.rb b/app/controllers/api/v1/imports_controller.rb
index 197e23337..3d7f4ca79 100644
--- a/app/controllers/api/v1/imports_controller.rb
+++ b/app/controllers/api/v1/imports_controller.rb
@@ -8,7 +8,6 @@ class Api::V1::ImportsController < Api::V1::IbooController
if @import.valid?
create!
else
- binding.pry
render json: { status: "error", messages: @import.errors.full_messages }
end
end
diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb
index 66dccc243..3c52dc935 100644
--- a/app/controllers/imports_controller.rb
+++ b/app/controllers/imports_controller.rb
@@ -38,13 +38,6 @@ 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 72d9f2ce6..4ff8326ab 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -18,12 +18,7 @@ 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
+ validates_format_of :file, with: %r{\.zip\z}i, message: I18n.t('activerecord.errors.models.imports.wrong_file_extension')
before_create :initialize_fields