DEV: remove assign_path and assign_icon from seralizers (#568)
Both fields are unnecessary and should not be included in the serializer to reduce payload.
This commit is contained in:
parent
c8f669d76b
commit
b796ae3fcc
|
@ -1,13 +1,5 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class AssignedGroupSerializer < ApplicationSerializer
|
class AssignedGroupSerializer < ApplicationSerializer
|
||||||
attributes :id, :name, :assign_icon, :assign_path
|
attributes :id, :name
|
||||||
|
|
||||||
def assign_icon
|
|
||||||
"group-plus"
|
|
||||||
end
|
|
||||||
|
|
||||||
def assign_path
|
|
||||||
"/g/#{object.name}/assigned/everyone"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -511,7 +511,7 @@ function initialize(api) {
|
||||||
} else {
|
} else {
|
||||||
assignedPath = `/t/${topic.id}`;
|
assignedPath = `/t/${topic.id}`;
|
||||||
}
|
}
|
||||||
const icon = iconHTML(assignee.assign_icon);
|
const icon = iconHTML(assignee.username ? "user-plus" : "group-plus");
|
||||||
const name = assignee.username || assignee.name;
|
const name = assignee.username || assignee.name;
|
||||||
const tagName = params.tagName || "a";
|
const tagName = params.tagName || "a";
|
||||||
const href =
|
const href =
|
||||||
|
|
|
@ -4,13 +4,7 @@ module DiscourseAssign
|
||||||
module Helpers
|
module Helpers
|
||||||
def self.build_assigned_to_user(user, topic)
|
def self.build_assigned_to_user(user, topic)
|
||||||
return if !user
|
return if !user
|
||||||
{
|
{ username: user.username, name: user.name, avatar_template: user.avatar_template }
|
||||||
username: user.username,
|
|
||||||
name: user.name,
|
|
||||||
avatar_template: user.avatar_template,
|
|
||||||
assign_icon: "user-plus",
|
|
||||||
assign_path: SiteSetting.assigns_user_url_path.gsub("{username}", user.username),
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.build_assigned_to_group(group, topic)
|
def self.build_assigned_to_group(group, topic)
|
||||||
|
@ -22,8 +16,6 @@ module DiscourseAssign
|
||||||
flair_color: group.flair_color,
|
flair_color: group.flair_color,
|
||||||
flair_icon: group.flair_icon,
|
flair_icon: group.flair_icon,
|
||||||
flair_upload_id: group.flair_upload_id,
|
flair_upload_id: group.flair_upload_id,
|
||||||
assign_icon: "group-plus",
|
|
||||||
assign_path: "/g/#{group.name}/assigned/everyone",
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -694,12 +694,6 @@ after_initialize do
|
||||||
AssignedGroupSerializer.new(assigned_to, scope: scope, root: false).as_json
|
AssignedGroupSerializer.new(assigned_to, scope: scope, root: false).as_json
|
||||||
end
|
end
|
||||||
|
|
||||||
add_to_serializer(:basic_user, :assign_icon) { "user-plus" }
|
|
||||||
add_to_serializer(:basic_user, :assign_path) do
|
|
||||||
return if !object.is_a?(User)
|
|
||||||
SiteSetting.assigns_user_url_path.gsub("{username}", object.username)
|
|
||||||
end
|
|
||||||
|
|
||||||
# PostSerializer
|
# PostSerializer
|
||||||
add_to_serializer(
|
add_to_serializer(
|
||||||
:post,
|
:post,
|
||||||
|
|
|
@ -61,8 +61,6 @@ describe Search do
|
||||||
expect(indirectly_assigned_to).to eq(
|
expect(indirectly_assigned_to).to eq(
|
||||||
post5.id => {
|
post5.id => {
|
||||||
assigned_to: {
|
assigned_to: {
|
||||||
assign_icon: "user-plus",
|
|
||||||
assign_path: "/u/#{user.username}/activity/assigned",
|
|
||||||
avatar_template: user.avatar_template,
|
avatar_template: user.avatar_template,
|
||||||
name: user.name,
|
name: user.name,
|
||||||
username: user.username,
|
username: user.username,
|
||||||
|
|
|
@ -34,8 +34,6 @@ describe SearchController do
|
||||||
|
|
||||||
expect(assigned_to_group_data["id"]).to eq(group.id)
|
expect(assigned_to_group_data["id"]).to eq(group.id)
|
||||||
expect(assigned_to_group_data["name"]).to eq(group.name)
|
expect(assigned_to_group_data["name"]).to eq(group.name)
|
||||||
expect(assigned_to_group_data["assign_icon"]).to eq("group-plus")
|
|
||||||
expect(assigned_to_group_data["assign_path"]).to eq("/g/#{group.name}/assigned/everyone")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not result in N+1 queries when search returns multiple results" do
|
it "does not result in N+1 queries when search returns multiple results" do
|
||||||
|
|
|
@ -40,13 +40,7 @@ describe FlaggedTopicSerializer do
|
||||||
json = FlaggedTopicSerializer.new(topic, scope: guardian).as_json
|
json = FlaggedTopicSerializer.new(topic, scope: guardian).as_json
|
||||||
|
|
||||||
expect(json[:flagged_topic][:assigned_to_user]).to match(
|
expect(json[:flagged_topic][:assigned_to_user]).to match(
|
||||||
{
|
{ username: user.username, name: user.name, avatar_template: /letter_avatar_proxy.*/ },
|
||||||
username: user.username,
|
|
||||||
name: user.name,
|
|
||||||
assign_icon: "user-plus",
|
|
||||||
avatar_template: /letter_avatar_proxy.*/,
|
|
||||||
assign_path: "/u/#{user.username}/activity/assigned",
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
expect(json[:flagged_topic]).to_not have_key(:assigned_to_group)
|
expect(json[:flagged_topic]).to_not have_key(:assigned_to_group)
|
||||||
end
|
end
|
||||||
|
@ -78,8 +72,6 @@ describe FlaggedTopicSerializer do
|
||||||
flair_color: assign_allowed_group.flair_color,
|
flair_color: assign_allowed_group.flair_color,
|
||||||
flair_icon: assign_allowed_group.flair_icon,
|
flair_icon: assign_allowed_group.flair_icon,
|
||||||
flair_upload_id: assign_allowed_group.flair_upload_id,
|
flair_upload_id: assign_allowed_group.flair_upload_id,
|
||||||
assign_icon: "group-plus",
|
|
||||||
assign_path: "/g/#{assign_allowed_group.name}/assigned/everyone",
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
expect(json[:flagged_topic]).to_not have_key(:assigned_to_user)
|
expect(json[:flagged_topic]).to_not have_key(:assigned_to_user)
|
||||||
|
|
|
@ -21,7 +21,6 @@ describe PostSerializer do
|
||||||
serializer = PostSerializer.new(post, scope: guardian)
|
serializer = PostSerializer.new(post, scope: guardian)
|
||||||
post = serializer.as_json[:post]
|
post = serializer.as_json[:post]
|
||||||
expect(post[:assigned_to_user][:id]).to eq(user.id)
|
expect(post[:assigned_to_user][:id]).to eq(user.id)
|
||||||
expect(post[:assigned_to_user][:assign_icon]).to eq("user-plus")
|
|
||||||
expect(post[:assigned_to_group]).to be(nil)
|
expect(post[:assigned_to_group]).to be(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -30,7 +29,6 @@ describe PostSerializer do
|
||||||
serializer = PostSerializer.new(post, scope: guardian)
|
serializer = PostSerializer.new(post, scope: guardian)
|
||||||
post = serializer.as_json[:post]
|
post = serializer.as_json[:post]
|
||||||
expect(post[:assigned_to_group][:id]).to eq(assign_allowed_group.id)
|
expect(post[:assigned_to_group][:id]).to eq(assign_allowed_group.id)
|
||||||
expect(post[:assigned_to_group][:assign_icon]).to eq("group-plus")
|
|
||||||
expect(post[:assigned_to_user]).to be(nil)
|
expect(post[:assigned_to_user]).to be(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@ describe UserBookmarkBaseSerializer do
|
||||||
bookmark = serializer.as_json[:user_topic_bookmark]
|
bookmark = serializer.as_json[:user_topic_bookmark]
|
||||||
|
|
||||||
expect(bookmark[:assigned_to_user][:id]).to eq(user.id)
|
expect(bookmark[:assigned_to_user][:id]).to eq(user.id)
|
||||||
expect(bookmark[:assigned_to_user][:assign_icon]).to eq("user-plus")
|
|
||||||
expect(bookmark[:assigned_to_group]).to be(nil)
|
expect(bookmark[:assigned_to_group]).to be(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -34,7 +33,6 @@ describe UserBookmarkBaseSerializer do
|
||||||
bookmark = serializer.as_json[:user_topic_bookmark]
|
bookmark = serializer.as_json[:user_topic_bookmark]
|
||||||
|
|
||||||
expect(bookmark[:assigned_to_group][:id]).to eq(assign_allowed_group.id)
|
expect(bookmark[:assigned_to_group][:id]).to eq(assign_allowed_group.id)
|
||||||
expect(bookmark[:assigned_to_group][:assign_icon]).to eq("group-plus")
|
|
||||||
expect(bookmark[:assigned_to_user]).to be(nil)
|
expect(bookmark[:assigned_to_user]).to be(nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -47,7 +45,6 @@ describe UserBookmarkBaseSerializer do
|
||||||
bookmark = serializer.as_json[:user_post_bookmark]
|
bookmark = serializer.as_json[:user_post_bookmark]
|
||||||
|
|
||||||
expect(bookmark[:assigned_to_user][:id]).to eq(user.id)
|
expect(bookmark[:assigned_to_user][:id]).to eq(user.id)
|
||||||
expect(bookmark[:assigned_to_user][:assign_icon]).to eq("user-plus")
|
|
||||||
expect(bookmark[:assigned_to_group]).to be(nil)
|
expect(bookmark[:assigned_to_group]).to be(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -57,7 +54,6 @@ describe UserBookmarkBaseSerializer do
|
||||||
bookmark = serializer.as_json[:user_post_bookmark]
|
bookmark = serializer.as_json[:user_post_bookmark]
|
||||||
|
|
||||||
expect(bookmark[:assigned_to_group][:id]).to eq(assign_allowed_group.id)
|
expect(bookmark[:assigned_to_group][:id]).to eq(assign_allowed_group.id)
|
||||||
expect(bookmark[:assigned_to_group][:assign_icon]).to eq("group-plus")
|
|
||||||
expect(bookmark[:assigned_to_user]).to be(nil)
|
expect(bookmark[:assigned_to_user]).to be(nil)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -108,6 +108,7 @@ acceptance("Discourse Assign | Assigned topic", function (needs) {
|
||||||
"shows assignment and indirect assignments in the first post"
|
"shows assignment and indirect assignments in the first post"
|
||||||
);
|
);
|
||||||
assert.dom("#post_1 .assigned-to svg.d-icon-user-plus").exists();
|
assert.dom("#post_1 .assigned-to svg.d-icon-user-plus").exists();
|
||||||
|
assert.dom("#post_1 .assigned-to a[href='/']").exists();
|
||||||
assert
|
assert
|
||||||
.dom(".discourse-tags .assigned-to[href='/t/28830'] span")
|
.dom(".discourse-tags .assigned-to[href='/t/28830'] span")
|
||||||
.hasAttribute("title", "Shark Doododooo", "shows topic assign notes");
|
.hasAttribute("title", "Shark Doododooo", "shows topic assign notes");
|
||||||
|
@ -137,6 +138,9 @@ acceptance("Discourse Assign | Assigned topic", function (needs) {
|
||||||
"shows assignment in the first post"
|
"shows assignment in the first post"
|
||||||
);
|
);
|
||||||
assert.dom("#post_1 .assigned-to svg.d-icon-group-plus").exists();
|
assert.dom("#post_1 .assigned-to svg.d-icon-group-plus").exists();
|
||||||
|
assert
|
||||||
|
.dom("#post_1 .assigned-to a[href='/g/Developers/assigned/everyone']")
|
||||||
|
.exists();
|
||||||
assert
|
assert
|
||||||
.dom("#topic-footer-dropdown-reassign")
|
.dom("#topic-footer-dropdown-reassign")
|
||||||
.exists("shows reassign dropdown at the bottom of the topic");
|
.exists("shows reassign dropdown at the bottom of the topic");
|
||||||
|
|
Loading…
Reference in New Issue