FIX: Show auto-group flair according to user preferences (#21221)

This commit is contained in:
Jan Cernik 2023-04-24 16:04:26 -03:00 committed by GitHub
parent 6890beb95a
commit c03f83bbea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 87 additions and 13 deletions

View File

@ -7,7 +7,7 @@ export default Component.extend({
@discourseComputed("user")
flair(user) {
if (!user) {
if (!user || !user.flair_group_id) {
return;
}

View File

@ -26,6 +26,7 @@ export function transformBasicPost(post) {
flair_url: post.flair_url,
flair_bg_color: post.flair_bg_color,
flair_color: post.flair_color,
flair_group_id: post.flair_group_id,
wiki: post.wiki,
lastWikiEdit: post.last_wiki_edit,
firstPost: post.post_number === 1,

View File

@ -226,13 +226,15 @@ createWidget("post-avatar", {
const postAvatarBody = [body];
if (attrs.flair_url || attrs.flair_bg_color) {
postAvatarBody.push(this.attach("avatar-flair", attrs));
} else {
const autoFlairAttrs = autoGroupFlairForUser(this.site, attrs);
if (attrs.flair_group_id) {
if (attrs.flair_url || attrs.flair_bg_color) {
postAvatarBody.push(this.attach("avatar-flair", attrs));
} else {
const autoFlairAttrs = autoGroupFlairForUser(this.site, attrs);
if (autoFlairAttrs) {
postAvatarBody.push(this.attach("avatar-flair", autoFlairAttrs));
if (autoFlairAttrs) {
postAvatarBody.push(this.attach("avatar-flair", autoFlairAttrs));
}
}
}

View File

@ -80,12 +80,14 @@ createWidget("topic-participant", {
linkContents.push(h("span.post-count", attrs.post_count.toString()));
}
if (attrs.flair_url || attrs.flair_bg_color) {
linkContents.push(this.attach("avatar-flair", attrs));
} else {
const autoFlairAttrs = autoGroupFlairForUser(this.site, attrs);
if (autoFlairAttrs) {
linkContents.push(this.attach("avatar-flair", autoFlairAttrs));
if (attrs.flair_group_id) {
if (attrs.flair_url || attrs.flair_bg_color) {
linkContents.push(this.attach("avatar-flair", attrs));
} else {
const autoFlairAttrs = autoGroupFlairForUser(this.site, attrs);
if (autoFlairAttrs) {
linkContents.push(this.attach("avatar-flair", autoFlairAttrs));
}
}
}
return h(

View File

@ -54,6 +54,7 @@ module("Integration | Component | user-avatar-flair", function (hooks) {
admin: true,
moderator: false,
trust_level: 2,
flair_group_id: 12,
});
setupSiteGroups(this);
@ -73,6 +74,7 @@ module("Integration | Component | user-avatar-flair", function (hooks) {
admin: false,
moderator: true,
trust_level: 2,
flair_group_id: 12,
});
setupSiteGroups(this);
@ -92,6 +94,7 @@ module("Integration | Component | user-avatar-flair", function (hooks) {
admin: false,
moderator: false,
trust_level: 2,
flair_group_id: 12,
});
setupSiteGroups(this);
@ -106,11 +109,26 @@ module("Integration | Component | user-avatar-flair", function (hooks) {
);
});
test("avatar flair for trust level when set to none", async function (assert) {
this.set("args", {
admin: false,
moderator: false,
trust_level: 2,
flair_group_id: null,
});
setupSiteGroups(this);
await render(hbs`<UserAvatarFlair @user={{this.args}} />`);
assert.ok(!exists(".avatar-flair"), "it does not render a flair");
});
test("avatar flair for trust level with fallback", async function (assert) {
this.set("args", {
admin: false,
moderator: false,
trust_level: 3,
flair_group_id: 13,
});
setupSiteGroups(this);
@ -130,6 +148,7 @@ module("Integration | Component | user-avatar-flair", function (hooks) {
admin: false,
moderator: false,
trust_level: 3,
flair_group_id: 13,
});
// Groups not serialized for anon on login_required
this.site.groups = undefined;
@ -148,6 +167,7 @@ module("Integration | Component | user-avatar-flair", function (hooks) {
flair_url: "fa-times",
flair_bg_color: "123456",
flair_color: "B0B0B0",
flair_group_id: 41,
primary_group_name: "Band Geeks",
});
setupSiteGroups(this);
@ -168,6 +188,7 @@ module("Integration | Component | user-avatar-flair", function (hooks) {
admin: false,
moderator: false,
trust_level: 1,
flair_group_id: 11,
});
await render(hbs`<UserAvatarFlair @user={{this.args}} />`);

View File

@ -34,6 +34,7 @@ module(
flair_name: "devs",
flair_url: "/images/d-logo-sketch-small.png",
flair_bg_color: "222",
flair_group_id: "41",
});
await render(

View File

@ -37,6 +37,7 @@ class PostSerializer < BasicPostSerializer
:flair_url,
:flair_bg_color,
:flair_color,
:flair_group_id,
:version,
:can_edit,
:can_delete,
@ -213,6 +214,10 @@ class PostSerializer < BasicPostSerializer
object.user&.flair_group&.flair_color
end
def flair_group_id
object.user&.flair_group_id
end
def link_counts
return @single_post_link_counts if @single_post_link_counts.present?

View File

@ -7,6 +7,7 @@ class TopicPostCountSerializer < BasicUserSerializer
:flair_url,
:flair_color,
:flair_bg_color,
:flair_group_id,
:admin,
:moderator,
:trust_level
@ -44,6 +45,10 @@ class TopicPostCountSerializer < BasicUserSerializer
object[:user]&.flair_group&.flair_color
end
def flair_group_id
object[:user]&.flair_group_id
end
def include_admin?
object[:user].admin
end

View File

@ -116,6 +116,9 @@ RSpec.describe "posts" do
flair_color: {
type: %i[string null],
},
flair_group_id: {
type: %i[string null],
},
version: {
type: :integer,
},

View File

@ -413,6 +413,9 @@
"flair_color": {
"type": ["string", "null"]
},
"flair_group_id": {
"type": ["string", "null"]
},
"bio_raw": {
"type": ["string", "null"]
},

View File

@ -101,6 +101,12 @@
"null"
]
},
"flair_group_id": {
"type": [
"string",
"null"
]
},
"version": {
"type": "integer"
},

View File

@ -88,6 +88,12 @@
"null"
]
},
"flair_group_id": {
"type": [
"string",
"null"
]
},
"version": {
"type": "integer"
},

View File

@ -92,6 +92,12 @@
"null"
]
},
"flair_group_id": {
"type": [
"string",
"null"
]
},
"version": {
"type": "integer"
},

View File

@ -103,6 +103,12 @@
"null"
]
},
"flair_group_id": {
"type": [
"string",
"null"
]
},
"version": {
"type": "integer"
},

View File

@ -828,6 +828,12 @@
"null"
]
},
"flair_group_id": {
"type": [
"string",
"null"
]
},
"admin": {
"type": "boolean"
},

View File

@ -32,6 +32,7 @@ RSpec.describe WebHookPostSerializer do
:display_username,
:primary_group_name,
:flair_name,
:flair_group_id,
:version,
:user_title,
:bookmarked,