FIX: Make avatar-flair component fail gracefully group info missing (#13398)

This can happen when an avatar-flair component is rendered to an anonymous user on a login_required site (e.g. when they are redeeming an invite). The lack of group information was causing an error to be raised. With this commit, it now simple skips rendering the flair.
This commit is contained in:
David Taylor 2021-06-16 11:22:11 +01:00 committed by GitHub
parent b0416cb1c1
commit 0f9d31a85e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -52,7 +52,7 @@ function initializeAutoGroupFlair(site) {
"trust_level_3",
"trust_level_4",
].forEach((groupName) => {
const group = site.groups.findBy("name", groupName);
const group = site.groups?.findBy("name", groupName);
if (group && group.flair_url) {
_noAutoFlair = false;
_autoGroupFlair[groupName] = {

View File

@ -147,6 +147,26 @@ discourseModule(
},
});
componentTest("avatar flair for login-required site, before login", {
template: hbs`{{user-avatar-flair user=args}}`,
beforeEach() {
resetFlair();
this.set("args", {
admin: false,
moderator: false,
trust_level: 3,
});
// Groups not serialized for anon on login_required
this.site.groups = undefined;
},
afterEach() {
resetFlair();
},
test(assert) {
assert.ok(!exists(".avatar-flair"), "it does not render a flair");
},
});
componentTest("avatar flair for primary group flair", {
template: hbs`{{user-avatar-flair user=args}}`,
beforeEach() {