FEATURE - Add username column to custom emoji table (#29522)
* Adds emoji column for creator username
This commit is contained in:
parent
68c7c8e25d
commit
cfc23c43e9
|
@ -25,6 +25,8 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{i18n "admin.emoji.image"}}</th>
|
<th>{{i18n "admin.emoji.image"}}</th>
|
||||||
<th>{{i18n "admin.emoji.name"}}</th>
|
<th>{{i18n "admin.emoji.name"}}</th>
|
||||||
|
<th>{{i18n "admin.emoji.group"}}</th>
|
||||||
|
<th>{{i18n "admin.emoji.created_by"}}</th>
|
||||||
<th colspan="2">
|
<th colspan="2">
|
||||||
<ComboBox
|
<ComboBox
|
||||||
@value={{this.filter}}
|
@value={{this.filter}}
|
||||||
|
@ -47,6 +49,7 @@
|
||||||
/></td>
|
/></td>
|
||||||
<td>:{{e.name}}:</td>
|
<td>:{{e.name}}:</td>
|
||||||
<td>{{e.group}}</td>
|
<td>{{e.group}}</td>
|
||||||
|
<td>{{e.created_by}}</td>
|
||||||
<td class="action">
|
<td class="action">
|
||||||
<DButton
|
<DButton
|
||||||
@action={{fn this.destroyEmoji e}}
|
@action={{fn this.destroyEmoji e}}
|
||||||
|
|
|
@ -24,6 +24,7 @@ module("Integration | Component | emoji-uploader", function (hooks) {
|
||||||
return response({
|
return response({
|
||||||
group: "cool-emojis",
|
group: "cool-emojis",
|
||||||
name: "okay",
|
name: "okay",
|
||||||
|
created_by: "benji",
|
||||||
url: "//upload.s3.dualstack.us-east-2.amazonaws.com/original/1X/123.png",
|
url: "//upload.s3.dualstack.us-east-2.amazonaws.com/original/1X/123.png",
|
||||||
});
|
});
|
||||||
} else if (requestNumber === 2) {
|
} else if (requestNumber === 2) {
|
||||||
|
@ -125,4 +126,27 @@ module("Integration | Component | emoji-uploader", function (hooks) {
|
||||||
.lookup("service:app-events")
|
.lookup("service:app-events")
|
||||||
.trigger("upload-mixin:emoji-uploader:add-files", [image, image2]);
|
.trigger("upload-mixin:emoji-uploader:add-files", [image, image2]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("sets the created_by field with username", async function (assert) {
|
||||||
|
await render(hbs`
|
||||||
|
<EmojiUploader
|
||||||
|
@id="emoji-uploader"
|
||||||
|
@emojiGroups={{this.emojiGroups}}
|
||||||
|
@createdBy={{this.createdBy}}
|
||||||
|
@done={{this.doneUpload}}
|
||||||
|
/>
|
||||||
|
`);
|
||||||
|
|
||||||
|
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]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,7 +10,7 @@ class Emoji
|
||||||
|
|
||||||
include ActiveModel::SerializerSupport
|
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
|
def self.global_emoji_cache
|
||||||
@global_emoji_cache ||= DistributedCache.new("global_emoji_cache", namespace: false)
|
@global_emoji_cache ||= DistributedCache.new("global_emoji_cache", namespace: false)
|
||||||
|
@ -190,6 +190,7 @@ class Emoji
|
||||||
e.name = emoji.name
|
e.name = emoji.name
|
||||||
e.url = emoji.upload&.url
|
e.url = emoji.upload&.url
|
||||||
e.group = emoji.group || DEFAULT_GROUP
|
e.group = emoji.group || DEFAULT_GROUP
|
||||||
|
e.created_by = User.where(id: emoji.user_id).pick(:username)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class EmojiSerializer < ApplicationSerializer
|
class EmojiSerializer < ApplicationSerializer
|
||||||
attributes :name, :url, :group
|
attributes :name, :url, :group, :created_by
|
||||||
|
|
||||||
|
def created_by
|
||||||
|
object.created_by
|
||||||
|
end
|
||||||
|
|
||||||
def url
|
def url
|
||||||
return nil if object.url.blank?
|
return nil if object.url.blank?
|
||||||
|
|
|
@ -7201,6 +7201,7 @@ en:
|
||||||
uploading: "Uploading…"
|
uploading: "Uploading…"
|
||||||
name: "Name"
|
name: "Name"
|
||||||
group: "Group"
|
group: "Group"
|
||||||
|
created_by: "Created By"
|
||||||
image: "Image"
|
image: "Image"
|
||||||
alt: "custom emoji preview"
|
alt: "custom emoji preview"
|
||||||
delete_confirm: "Are you sure you want to delete the :%{name}: emoji?"
|
delete_confirm: "Are you sure you want to delete the :%{name}: emoji?"
|
||||||
|
|
|
@ -11,7 +11,7 @@ RSpec.describe Admin::EmojisController do
|
||||||
before { sign_in(admin) }
|
before { sign_in(admin) }
|
||||||
|
|
||||||
it "returns a list of custom emojis" do
|
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
|
Emoji.clear_cache
|
||||||
|
|
||||||
get "/admin/customize/emojis.json"
|
get "/admin/customize/emojis.json"
|
||||||
|
@ -20,6 +20,7 @@ RSpec.describe Admin::EmojisController do
|
||||||
json = response.parsed_body
|
json = response.parsed_body
|
||||||
expect(json[0]["name"]).to eq("osama-test-emoji")
|
expect(json[0]["name"]).to eq("osama-test-emoji")
|
||||||
expect(json[0]["url"]).to eq(upload.url)
|
expect(json[0]["url"]).to eq(upload.url)
|
||||||
|
expect(json[0]["created_by"]).to eq(admin.username)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,10 @@ RSpec.describe EmojiSerializer do
|
||||||
expect(serializer.url).to start_with("/uploads/")
|
expect(serializer.url).to start_with("/uploads/")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns the creator's username" do
|
||||||
|
expect(serializer.created_by).to eq(emoji.created_by)
|
||||||
|
end
|
||||||
|
|
||||||
it "works with a CDN" do
|
it "works with a CDN" do
|
||||||
set_cdn_url("https://cdn.com")
|
set_cdn_url("https://cdn.com")
|
||||||
expect(serializer.url).to start_with("https://cdn.com")
|
expect(serializer.url).to start_with("https://cdn.com")
|
||||||
|
|
Loading…
Reference in New Issue