mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Stroy#105839906 more cleanup to remove legal_documents_versions + some code reading-refactorings
This commit is contained in:
parent
c0960e9184
commit
3f17f728eb
4 changed files with 14 additions and 46 deletions
|
@ -1,33 +0,0 @@
|
||||||
module VersionCreator
|
|
||||||
extend ActiveSupport::Concern
|
|
||||||
|
|
||||||
included do
|
|
||||||
before_create :add_creator
|
|
||||||
|
|
||||||
def add_creator
|
|
||||||
self.creator_str = ::PaperTrail.whodunnit
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
def add_updator
|
|
||||||
self.updator_str = ::PaperTrail.whodunnit
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
# returns a user object for a reference
|
|
||||||
def creator
|
|
||||||
return nil if creator_str.blank?
|
|
||||||
|
|
||||||
if creator_str =~ /^\d+-AdminUser:/
|
|
||||||
creator = AdminUser.find_by(id: creator_str)
|
|
||||||
elsif creator_str =~ /^\d+-ApiUser:/
|
|
||||||
creator = ApiUser.find_by(id: creator_str)
|
|
||||||
elsif creator_str =~ /^\d+-api-/ # depricated
|
|
||||||
creator = ApiUser.find_by(id: creator_str)
|
|
||||||
end
|
|
||||||
|
|
||||||
creator.present? ? creator : creator_str
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
|
@ -1,17 +1,19 @@
|
||||||
class LegalDocument < ActiveRecord::Base
|
class LegalDocument < ActiveRecord::Base
|
||||||
extend VersionCreator
|
|
||||||
|
|
||||||
belongs_to :documentable, polymorphic: true
|
|
||||||
|
|
||||||
if ENV['legal_document_types'].present?
|
if ENV['legal_document_types'].present?
|
||||||
TYPES = ENV['legal_document_types'].split(',').map(&:strip)
|
TYPES = ENV['legal_document_types'].split(',').map(&:strip)
|
||||||
else
|
else
|
||||||
TYPES = %w(pdf bdoc ddoc zip rar gz tar 7z odt doc docx)
|
TYPES = %w(pdf bdoc ddoc zip rar gz tar 7z odt doc docx).freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_accessor :body
|
attr_accessor :body
|
||||||
|
|
||||||
before_save :save_to_filesystem
|
belongs_to :documentable, polymorphic: true
|
||||||
|
|
||||||
|
before_create :add_creator
|
||||||
|
before_save :save_to_filesystem
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def save_to_filesystem
|
def save_to_filesystem
|
||||||
loop do
|
loop do
|
||||||
rand = SecureRandom.random_number.to_s.last(4)
|
rand = SecureRandom.random_number.to_s.last(4)
|
||||||
|
@ -26,4 +28,9 @@ class LegalDocument < ActiveRecord::Base
|
||||||
File.open(path, 'wb') { |f| f.write(Base64.decode64(body)) } unless Rails.env.test?
|
File.open(path, 'wb') { |f| f.write(Base64.decode64(body)) } unless Rails.env.test?
|
||||||
self.path = path
|
self.path = path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_creator
|
||||||
|
self.creator_str = ::PaperTrail.whodunnit
|
||||||
|
true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
class LegalDocumentVersion < PaperTrail::Version
|
|
||||||
include VersionSession
|
|
||||||
self.table_name = :log_legal_documents
|
|
||||||
self.sequence_name = :log_legal_documents_id_seq
|
|
||||||
end
|
|
|
@ -6,7 +6,6 @@ class DropLogLegalDocuments < ActiveRecord::Migration
|
||||||
end
|
end
|
||||||
|
|
||||||
def down
|
def down
|
||||||
# removed concern Version, which removed LegalDocumentVersion
|
# we don't want it back
|
||||||
fail ActiveRecord::IrreversibleMigration
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue