Skip to content

Commit

Permalink
fix issue with removing even private attachment after destroy, not re…
Browse files Browse the repository at this point in the history
…al destroy
  • Loading branch information
tsubik committed Dec 5, 2023
1 parent 84fc6b9 commit f1ad53f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/models/gov_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ class GovDocument < ApplicationRecord

after_update :move_previous_attachment_to_private_directory, if: :saved_change_to_attachment?

skip_callback :commit, :after, :remove_attachment!
after_destroy :move_attachment_to_private_directory
after_restore :move_attachment_to_public_directory
after_real_destroy :remove_attachment!

scope :with_archived, -> { unscope(where: :deleted_at) }
scope :to_expire, ->(date) { where("expire_date < ?", date).where(status: EXPIRABLE_STATUSES) }
Expand Down
2 changes: 2 additions & 0 deletions app/models/observation_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class ObservationDocument < ApplicationRecord
belongs_to :user, inverse_of: :observation_documents, touch: true, optional: true
belongs_to :observation, inverse_of: :observation_documents, touch: true

skip_callback :commit, :after, :remove_attachment!
after_destroy :move_attachment_to_private_directory
after_restore :move_attachment_to_public_directory
after_real_destroy :remove_attachment!
end
2 changes: 2 additions & 0 deletions app/models/observation_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ class ObservationReport < ApplicationRecord
has_many :observers, through: :observation_report_observers
has_many :observations, dependent: :destroy

skip_callback :commit, :after, :remove_attachment!
after_destroy :move_attachment_to_private_directory
after_restore :move_attachment_to_public_directory
after_real_destroy :remove_attachment!

scope :bigger_date, ->(date) { where("observation_reports.created_at <= ?", date + 1.day) }

Expand Down

0 comments on commit f1ad53f

Please sign in to comment.