From cfc23c43e9988d971086aefaf0cf9f0ccd1d4619 Mon Sep 17 00:00:00 2001
From: benj <25828824+brrusselburg@users.noreply.github.com>
Date: Fri, 1 Nov 2024 10:32:59 -0500
Subject: [PATCH] FEATURE - Add username column to custom emoji table (#29522)
* Adds emoji column for creator username
---
.../admin/addon/templates/emojis.hbs | 3 +++
.../components/emoji-uploader-test.js | 24 +++++++++++++++++++
app/models/emoji.rb | 3 ++-
app/serializers/emoji_serializer.rb | 6 ++++-
config/locales/client.en.yml | 1 +
spec/requests/admin/emojis_controller_spec.rb | 3 ++-
spec/serializers/emoji_serializer_spec.rb | 4 ++++
7 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/app/assets/javascripts/admin/addon/templates/emojis.hbs b/app/assets/javascripts/admin/addon/templates/emojis.hbs
index db7773ca1cb..7f3e20cfa72 100644
--- a/app/assets/javascripts/admin/addon/templates/emojis.hbs
+++ b/app/assets/javascripts/admin/addon/templates/emojis.hbs
@@ -25,6 +25,8 @@
{{i18n "admin.emoji.image"}} |
{{i18n "admin.emoji.name"}} |
+ {{i18n "admin.emoji.group"}} |
+ {{i18n "admin.emoji.created_by"}} |
| :{{e.name}}: |
{{e.group}} |
+ {{e.created_by}} |
+ `);
+
+ const done = assert.async();
+
+ this.set("doneUpload", (upload) => {
+ assert.strictEqual(upload.created_by, "benji");
+ done();
+ });
+
+ const image = createFile("avatar.png");
+ await this.container
+ .lookup("service:app-events")
+ .trigger("upload-mixin:emoji-uploader:add-files", [image]);
+ });
});
diff --git a/app/models/emoji.rb b/app/models/emoji.rb
index e4eb76b4979..33bc4657e49 100644
--- a/app/models/emoji.rb
+++ b/app/models/emoji.rb
@@ -10,7 +10,7 @@ class Emoji
include ActiveModel::SerializerSupport
- attr_accessor :name, :url, :tonable, :group, :search_aliases
+ attr_accessor :name, :url, :tonable, :group, :search_aliases, :created_by
def self.global_emoji_cache
@global_emoji_cache ||= DistributedCache.new("global_emoji_cache", namespace: false)
@@ -190,6 +190,7 @@ class Emoji
e.name = emoji.name
e.url = emoji.upload&.url
e.group = emoji.group || DEFAULT_GROUP
+ e.created_by = User.where(id: emoji.user_id).pick(:username)
end
end
end
diff --git a/app/serializers/emoji_serializer.rb b/app/serializers/emoji_serializer.rb
index 08e388d09de..25666e73401 100644
--- a/app/serializers/emoji_serializer.rb
+++ b/app/serializers/emoji_serializer.rb
@@ -1,7 +1,11 @@
# frozen_string_literal: true
class EmojiSerializer < ApplicationSerializer
- attributes :name, :url, :group
+ attributes :name, :url, :group, :created_by
+
+ def created_by
+ object.created_by
+ end
def url
return nil if object.url.blank?
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 11f457b4764..6ab03ed126c 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -7201,6 +7201,7 @@ en:
uploading: "Uploading…"
name: "Name"
group: "Group"
+ created_by: "Created By"
image: "Image"
alt: "custom emoji preview"
delete_confirm: "Are you sure you want to delete the :%{name}: emoji?"
diff --git a/spec/requests/admin/emojis_controller_spec.rb b/spec/requests/admin/emojis_controller_spec.rb
index ec19f0d08e1..7ddda7f9b91 100644
--- a/spec/requests/admin/emojis_controller_spec.rb
+++ b/spec/requests/admin/emojis_controller_spec.rb
@@ -11,7 +11,7 @@ RSpec.describe Admin::EmojisController do
before { sign_in(admin) }
it "returns a list of custom emojis" do
- CustomEmoji.create!(name: "osama-test-emoji", upload: upload)
+ CustomEmoji.create!(name: "osama-test-emoji", upload: upload, user: admin)
Emoji.clear_cache
get "/admin/customize/emojis.json"
@@ -20,6 +20,7 @@ RSpec.describe Admin::EmojisController do
json = response.parsed_body
expect(json[0]["name"]).to eq("osama-test-emoji")
expect(json[0]["url"]).to eq(upload.url)
+ expect(json[0]["created_by"]).to eq(admin.username)
end
end
diff --git a/spec/serializers/emoji_serializer_spec.rb b/spec/serializers/emoji_serializer_spec.rb
index 8c9487f542a..1db59c61807 100644
--- a/spec/serializers/emoji_serializer_spec.rb
+++ b/spec/serializers/emoji_serializer_spec.rb
@@ -12,6 +12,10 @@ RSpec.describe EmojiSerializer do
expect(serializer.url).to start_with("/uploads/")
end
+ it "returns the creator's username" do
+ expect(serializer.created_by).to eq(emoji.created_by)
+ end
+
it "works with a CDN" do
set_cdn_url("https://cdn.com")
expect(serializer.url).to start_with("https://cdn.com")
|