@@ -33,7 +33,6 @@ class GovDocument < ApplicationRecord
3333 belongs_to :required_gov_document , -> { with_archived } , inverse_of : :gov_documents
3434
3535 mount_base64_uploader :attachment , GovDocumentUploader
36- include MoveableAttachment
3736
3837 before_validation :set_expire_date , if : proc { |d | d . required_gov_document . valid_period? }
3938 before_validation :clear_wrong_fields
@@ -43,11 +42,7 @@ class GovDocument < ApplicationRecord
4342 validates :start_date , presence : true , if : proc { |d | d . required_gov_document . valid_period? && d . has_data? }
4443 validates :expire_date , presence : true , if : proc { |d | d . required_gov_document . valid_period? && d . has_data? }
4544
46- after_update :move_previous_attachment_to_private_directory , if : :saved_change_to_attachment?
47-
48- skip_callback :commit , :after , :remove_attachment!
49- after_destroy :move_attachment_to_private_directory
50- after_restore :move_attachment_to_public_directory
45+ skip_callback :commit , :after , :remove_attachment! # skip removal after destroying the record, skip after update done in uploader
5146 after_real_destroy :remove_attachment!
5247
5348 scope :with_archived , -> { unscope ( where : :deleted_at ) }
@@ -97,27 +92,6 @@ def set_country
9792 self . country_id = required_gov_document . country_id
9893 end
9994
100- def move_previous_attachment_to_private_directory
101- previous_attachment_filename = previous_changes [ :attachment ] [ 0 ]
102- return if previous_attachment_filename . blank?
103-
104- from = File . join ( attachment . public_root , attachment . store_dir , previous_attachment_filename )
105- to = File . join ( attachment . private_root , attachment . store_dir , previous_attachment_filename )
106- FileUtils . makedirs ( File . dirname ( to ) )
107- system "mv #{ Shellwords . escape ( from ) } #{ Shellwords . escape ( to ) } "
108- end
109-
110- # we only want to move current attachment back to public directory
111- def move_attachment_to_public_directory
112- attachment_attr = self [ :attachment ]
113- return if attachment_attr . nil?
114-
115- from = File . join ( attachment . private_root , attachment . store_dir , attachment_attr )
116- to = File . join ( attachment . public_root , attachment . store_dir , attachment_attr )
117- FileUtils . makedirs ( File . dirname ( to ) )
118- system "mv #{ Shellwords . escape ( from ) } #{ Shellwords . escape ( to ) } "
119- end
120-
12195 def clear_wrong_fields
12296 case required_gov_document . document_type
12397 when "file"
0 commit comments