mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 09:27:19 +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
|
||||
extend VersionCreator
|
||||
|
||||
belongs_to :documentable, polymorphic: true
|
||||
|
||||
if ENV['legal_document_types'].present?
|
||||
TYPES = ENV['legal_document_types'].split(',').map(&:strip)
|
||||
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
|
||||
|
||||
attr_accessor :body
|
||||
|
||||
belongs_to :documentable, polymorphic: true
|
||||
|
||||
before_create :add_creator
|
||||
before_save :save_to_filesystem
|
||||
|
||||
|
||||
|
||||
def save_to_filesystem
|
||||
loop do
|
||||
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?
|
||||
self.path = path
|
||||
end
|
||||
|
||||
def add_creator
|
||||
self.creator_str = ::PaperTrail.whodunnit
|
||||
true
|
||||
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
|
||||
|
||||
def down
|
||||
# removed concern Version, which removed LegalDocumentVersion
|
||||
fail ActiveRecord::IrreversibleMigration
|
||||
# we don't want it back
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue