mirror of
https://github.com/internetee/registry.git
synced 2025-07-23 11:16:00 +02:00
Check legaldoc size only if it's not persisted
This commit is contained in:
parent
b0d5605712
commit
eb09447ee1
1 changed files with 9 additions and 2 deletions
|
@ -14,8 +14,7 @@ class LegalDocument < ApplicationRecord
|
||||||
|
|
||||||
belongs_to :documentable, polymorphic: true
|
belongs_to :documentable, polymorphic: true
|
||||||
|
|
||||||
|
validate :val_body_length, if: ->(file) { file.path.blank? }
|
||||||
validate :val_body_length, if: ->(file){ file.path.blank? && !Rails.env.staging?}
|
|
||||||
|
|
||||||
before_create :add_creator
|
before_create :add_creator
|
||||||
before_save :save_to_filesystem, if: :body
|
before_save :save_to_filesystem, if: :body
|
||||||
|
@ -29,6 +28,14 @@ class LegalDocument < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def val_body_length
|
def val_body_length
|
||||||
|
if body.start_with? ENV['legal_documents_dir']
|
||||||
|
if File.exist? body
|
||||||
|
self.path = body
|
||||||
|
self.body = nil
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
errors.add(:body, :length) if body.nil? || body.size < MIN_BODY_SIZE
|
errors.add(:body, :length) if body.nil? || body.size < MIN_BODY_SIZE
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue