From bc9eff2ef534d97d44f6042d03c7dfa1794e21d0 Mon Sep 17 00:00:00 2001 From: Jure Grabnar Date: Thu, 21 Mar 2019 10:00:54 +0100 Subject: [PATCH] Add asset validation on wopi creation Missing file --- app/models/asset.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/models/asset.rb b/app/models/asset.rb index 1e11136ad..1dd2ac323 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb @@ -47,6 +47,8 @@ class Asset < ApplicationRecord # This could cause some problems if you create empty asset and want to # assign it to result validate :step_or_result_or_repository_asset_value + validate :name_should_not_be_empty_without_extension, + on: :wopi_file_creation belongs_to :created_by, foreign_key: 'created_by_id', @@ -517,6 +519,15 @@ class Asset < ApplicationRecord end end + def name_should_not_be_empty_without_extension + unless file.original_filename[0..-6].present? + errors.add( + :file, + I18n.t('general.text.not_blank') + ) + end + end + def cache fetched_file = file.fetch file_content = fetched_file.read