mirror of
https://github.com/discourse/discourse.git
synced 2026-08-05 11:52:32 +08:00
This commit uses `DFilterControls` for emoji list filtering, and sorts the emoji by group then by name, with default always at the top: <img width="1101" height="803" alt="image" src="https://github.com/user-attachments/assets/77e384c1-33b1-4741-bd55-ca86cd5f2a03" /> I've also refactored the create + delete endpoints into services.
50 lines
990 B
Ruby
Vendored
50 lines
990 B
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class CustomEmoji::Destroy
|
|
include Service::Base
|
|
|
|
params do
|
|
attribute :name, :string
|
|
|
|
validates :name, presence: true
|
|
end
|
|
|
|
model :custom_emoji, optional: true
|
|
|
|
only_if :custom_emoji_exists do
|
|
transaction do
|
|
step :log_destruction
|
|
step :remove_custom_emoji
|
|
end
|
|
end
|
|
|
|
step :clear_cache
|
|
step :rebake_affected_posts
|
|
|
|
private
|
|
|
|
def fetch_custom_emoji(params:)
|
|
CustomEmoji.find_by(name: params.name)
|
|
end
|
|
|
|
def custom_emoji_exists(custom_emoji:)
|
|
custom_emoji.present?
|
|
end
|
|
|
|
def log_destruction(params:, guardian:)
|
|
StaffActionLogger.new(guardian.user).log_custom_emoji_destroy(params.name)
|
|
end
|
|
|
|
def remove_custom_emoji(custom_emoji:)
|
|
# The clean_up_uploads job removes the upload after it becomes unused.
|
|
custom_emoji.destroy!
|
|
end
|
|
|
|
def clear_cache
|
|
Emoji.clear_cache
|
|
end
|
|
|
|
def rebake_affected_posts(params:)
|
|
Jobs.enqueue(:rebake_custom_emoji_posts, name: params.name)
|
|
end
|
|
end
|