FEATURE: Add creator and logging for CustomEmoji (#28004)

* FEATURE: Add logging for CustomEmoji

We didn't provide any logs for CustomEmoji before, nor did we record the
person who added any emoji in the database. As a result, the staff had
no way to trace back who added a certain emoji.

This commit adds a new column `user_id` to `custom_emojis` to record the
creator of an emoji. At the same time, a log is added for staff logs to
record who added or deleted a custom emoji.
This commit is contained in:
锦心
2024-07-22 14:44:49 +08:00
committed by GitHub
parent 23d7800ff1
commit 199f980e6a
7 changed files with 77 additions and 2 deletions

View File

@ -28,9 +28,12 @@ class Admin::EmojisController < Admin::AdminController
data =
if upload.persisted?
custom_emoji = CustomEmoji.new(name: name, upload: upload, group: group)
custom_emoji =
CustomEmoji.new(name: name, upload: upload, group: group, user: current_user)
if custom_emoji.save
StaffActionLogger.new(current_user).log_custom_emoji_create(name, group: group)
Emoji.clear_cache
{ name: custom_emoji.name, url: custom_emoji.upload.url, group: group }
else
@ -50,7 +53,12 @@ class Admin::EmojisController < Admin::AdminController
name = params.require(:id)
# NOTE: the upload will automatically be removed by the 'clean_up_uploads' job
CustomEmoji.find_by(name: name)&.destroy!
emoji = CustomEmoji.find_by(name: name)
if emoji.present?
StaffActionLogger.new(current_user).log_custom_emoji_destroy(name)
emoji.destroy!
end
Emoji.clear_cache