mirror of
https://github.com/discourse/discourse.git
synced 2026-08-11 02:59:07 +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.
56 lines
1.2 KiB
Ruby
Vendored
56 lines
1.2 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
class CustomEmoji::Create
|
|
include Service::Base
|
|
|
|
params do
|
|
attribute :file
|
|
attribute :files
|
|
attribute :name, :string
|
|
attribute :group, :string
|
|
|
|
before_validation :prepare_attributes
|
|
|
|
validates :file, presence: true
|
|
|
|
private
|
|
|
|
def prepare_attributes
|
|
self.file ||= files&.first
|
|
self.name = File.basename(name.nil? ? file&.original_filename.to_s : name, ".*")
|
|
self.name = Emoji.sanitize_emoji_name(name)
|
|
self.group = group&.downcase
|
|
end
|
|
end
|
|
|
|
model :upload, :create_upload
|
|
|
|
transaction do
|
|
model :custom_emoji, :create_custom_emoji
|
|
step :log_creation
|
|
end
|
|
|
|
step :clear_cache
|
|
|
|
private
|
|
|
|
def create_upload(params:, guardian:)
|
|
UploadCreator.new(
|
|
params.file.tempfile,
|
|
params.file.original_filename,
|
|
type: "custom_emoji",
|
|
).create_for(guardian.user.id)
|
|
end
|
|
|
|
def create_custom_emoji(params:, upload:, guardian:)
|
|
CustomEmoji.create(name: params.name, upload:, group: params.group, user: guardian.user)
|
|
end
|
|
|
|
def log_creation(params:, guardian:)
|
|
StaffActionLogger.new(guardian.user).log_custom_emoji_create(params.name, group: params.group)
|
|
end
|
|
|
|
def clear_cache
|
|
Emoji.clear_cache
|
|
end
|
|
end
|