Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Purge old & hidden comments #8320

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class Comment < ApplicationRecord
where(visible: true)
}

scope :hidden, -> { where(visible: false) }

scope :embargoed, -> {
joins(info_request: :embargo).
where('embargoes.id IS NOT NULL').
Expand Down
39 changes: 39 additions & 0 deletions app/models/comment/purgable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Comment::Purgable

Check warning on line 1 in app/models/comment/purgable.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 Missing top-level documentation comment for `module Comment::Purgable`. Raw Output: app/models/comment/purgable.rb:1:1: C: Style/Documentation: Missing top-level documentation comment for `module Comment::Purgable`.
extend ActiveSupport::Concern

included do
cattr_accessor :old_age_in_days,
instance_reader: false,
instance_writer: false,
instance_accessor: false,
default: 30
end

class_methods do
def purge_old_hidden(editor: User.internal_admin_user)
old_hidden = hidden.where('updated_at > ?', old_age_in_days.days.ago)
reason = "Hidden for longer than #{old_age_in_days} days"

old_hidden.find_each do |comment|
comment.purge(editor: editor, reason: reason)
end
end
end

def purge(editor:, reason:)
return false unless hidden?

event_params = {
comment_id: id,
comment_created_at: created_at,
comment_user: user,
editor: editor.url_name,
reason: "Purged: #{reason}"
}

ActiveRecord::Base.transaction do
destroy!
info_request_events.create!('destroy_comment', event_params)
end
end
end
1 change: 1 addition & 0 deletions app/models/info_request_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class InfoRequestEvent < ApplicationRecord
'edit_outgoing', # outgoing message edited (in admin interface)
'edit_comment', # comment edited (in admin interface)
'hide_comment', # comment hidden by admin
'destroy_comment', # comment destroyed by admin
'report_comment', # comment reported for admin attention by user
'report_request', # a request reported for admin attention by user
'destroy_incoming', # deleted an incoming message (in admin interface)
Expand Down
Loading