Skip to content

Commit c1e4fe1

Browse files
committed
mod warning creation should also be audited
1 parent ece8019 commit c1e4fe1

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

app/controllers/mod_warning_controller.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def create
4747
body: params[:mod_warning][:body], is_suspension: is_suspension,
4848
suspension_end: suspension_end, active: true, read: false)
4949
if @warning.save
50+
audit_warning('warning_create', @warning)
51+
5052
if is_suspension
5153
@user.community_user.update(is_suspended: is_suspension, suspension_end: suspension_end,
5254
suspension_public_comment: params[:mod_warning][:suspension_public_notice])
@@ -65,8 +67,7 @@ def lift
6567
@warning.update(active: false, read: false)
6668
@user.community_user.update is_suspended: false, suspension_public_comment: nil, suspension_end: nil
6769

68-
AuditLog.moderator_audit(event_type: 'warning_lift', related: @warning, user: current_user,
69-
comment: "<<Warning #{@warning.attributes_print} >>")
70+
audit_warning('warning_lift', @warning)
7071

7172
flash[:success] = 'The warning or suspension has been lifted. Please consider adding an annotation ' \
7273
'explaining your reasons.'
@@ -88,4 +89,13 @@ def set_user
8889
def user_scope
8990
User.joins(:community_user).includes(:community_user, :avatar_attachment)
9091
end
92+
93+
# Adds an audit log for a given mod warning
94+
# @param event_type [String] type of the event
95+
# @param warning [ModWarning] warning to audit
96+
def audit_warning(event_type, warning)
97+
AuditLog.moderator_audit(event_type: event_type,
98+
related: warning, user: current_user,
99+
comment: "<<Warning #{warning.attributes_print} >>")
100+
end
91101
end

0 commit comments

Comments
 (0)