forked from e621ng/e621ng
[ModActions] Ban Update Mod Action (#539)
* [ModActions] Ban Update Mod Action * Add back accidentally removed newline * Log expiration for user_ban_update ModAction The duration in days makes sense on creation but it falls apart when updating For this to correctly work the duration needs to be persisted as well which it isn't at the moment. --------- Co-authored-by: Earlopain <14981592+Earlopain@users.noreply.github.com>
This commit is contained in:
parent
10e9304f17
commit
b330a5f579
@ -73,6 +73,18 @@ class ModActionDecorator < ApplicationDecorator
|
||||
else
|
||||
"Banned #{user}"
|
||||
end
|
||||
when "user_ban_update"
|
||||
text = "Updated ban ##{vals['ban_id']} for #{user}"
|
||||
if vals["expires_at"] != vals["expires_at_was"]
|
||||
format_expires_at = ->(timestamp) { timestamp.nil? ? "never" : DateTime.parse(timestamp).strftime("%Y-%m-%d %H:%M") }
|
||||
expires_at = format_expires_at.call(vals["expires_at"])
|
||||
expires_at_was = format_expires_at.call(vals["expires_at_was"])
|
||||
text += "\nChanged expiration from #{expires_at_was} to #{expires_at}"
|
||||
end
|
||||
if vals["reason"] != vals["reason_was"]
|
||||
text += "\nChanged reason: [section=Old]#{vals['reason_was']}[/section] [section=New]#{vals['reason']}[/section]"
|
||||
end
|
||||
text
|
||||
when "user_unban"
|
||||
"Unbanned #{user}"
|
||||
|
||||
|
@ -3,6 +3,7 @@ class Ban < ApplicationRecord
|
||||
after_create :create_feedback
|
||||
after_create :update_user_on_create
|
||||
after_create :create_ban_mod_action
|
||||
after_update :create_ban_update_mod_action
|
||||
after_destroy :update_user_on_destroy
|
||||
after_destroy :create_unban_mod_action
|
||||
belongs_to :user
|
||||
@ -137,6 +138,10 @@ class Ban < ApplicationRecord
|
||||
ModAction.log(:user_ban, {duration: duration, reason: reason, user_id: user_id})
|
||||
end
|
||||
|
||||
def create_ban_update_mod_action
|
||||
ModAction.log(:user_ban_update, { user_id: user_id, ban_id: id, expires_at: expires_at, expires_at_was: expires_at_before_last_save, reason: reason, reason_was: reason_before_last_save })
|
||||
end
|
||||
|
||||
def create_unban_mod_action
|
||||
ModAction.log(:user_unban, {user_id: user_id})
|
||||
end
|
||||
|
@ -65,6 +65,7 @@ class ModAction < ApplicationRecord
|
||||
:user_name_change,
|
||||
:user_delete,
|
||||
:user_ban,
|
||||
:user_ban_update,
|
||||
:user_unban,
|
||||
:user_feedback_create,
|
||||
:user_feedback_update,
|
||||
|
Loading…
Reference in New Issue
Block a user