-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Erase comments that have been hidden for a while
TODO: Add a nightly cron task that calls `Comment.erase_old_hidden`
- Loading branch information
1 parent
15c547e
commit 28b246a
Showing
3 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class Comment::Erasure | ||
Check warning on line 1 in app/models/comment/erasure.rb GitHub Actions / build
|
||
def initialize(comment, editor: User.internal_admin_user, reason:) | ||
@comment = comment | ||
@editor = editor | ||
@reason = reason | ||
end | ||
|
||
def erase | ||
ActiveRecord::Base.transaction do | ||
erase_comment | ||
erase_comment_events | ||
end | ||
end | ||
|
||
protected | ||
|
||
attr_reader :comment, :editor, :reason | ||
|
||
private | ||
|
||
def erase_comment | ||
event_params = { | ||
comment_id: comment.id, | ||
editor: editor.url_name, | ||
reason: "Erased: #{reason}" | ||
} | ||
|
||
comment.update!(body: '') | ||
comment.info_request.log_event('erase_comment', event_params) | ||
end | ||
|
||
def erase_comment_events | ||
comment.info_request_events.edit_comment_events.find_each do |event| | ||
params = event.params.dup | ||
|
||
params.each do |key, _| | ||
params[key] = "[ERASED]" if key =~ /body/ | ||
end | ||
|
||
event.update(params: params) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters