From 71aae06dd14a956bec4ae6662ae0e10975314d39 Mon Sep 17 00:00:00 2001 From: Vladimir Krylov Date: Fri, 18 Mar 2016 15:59:14 +0200 Subject: [PATCH] Story#111864739 - epp validation --- app/models/legal_document.rb | 18 ++++++++++++++++++ config/locales/en.yml | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/app/models/legal_document.rb b/app/models/legal_document.rb index 5aef34675..32ed8e61b 100644 --- a/app/models/legal_document.rb +++ b/app/models/legal_document.rb @@ -1,4 +1,7 @@ class LegalDocument < ActiveRecord::Base + include EppErrors + MIN_BODY_SIZE = (1.37 * 8.kilobytes).ceil + if ENV['legal_document_types'].present? TYPES = ENV['legal_document_types'].split(',').map(&:strip) else @@ -9,9 +12,24 @@ class LegalDocument < ActiveRecord::Base belongs_to :documentable, polymorphic: true + + validate :val_body_length, if: ->(file){ file.path.blank? && !Rails.env.staging?} + before_create :add_creator before_save :save_to_filesystem + def epp_code_map + { + '2306' => [ + [:body, :length] + ] + } + end + + def val_body_length + errors.add(:body, :length) if body.nil? || body.size < MIN_BODY_SIZE + end + def save_to_filesystem diff --git a/config/locales/en.yml b/config/locales/en.yml index 2cc8b1387..ad662277d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -205,6 +205,10 @@ en: blank: 'Algorithm is missing' auth_info_pw: blank: 'Password is missing' + legal_document: + attributes: + body: + length: 'Parameter value policy error: legalDocument size should be more than 8kB' attributes: