From 6e983ba5dcb605a1f7bb7e8d0a1eb0ad82b3d922 Mon Sep 17 00:00:00 2001 From: Erik Michelson Date: Fri, 7 Jan 2022 14:01:32 +0100 Subject: [PATCH 1/3] Use libravatar image if email address is defined We use the attribute `emails` (plural) for email addresses with other auth providers like LDAP or SAML. In case of OAuth2 we used the attribute `email` (singular) which resulted in problems. Furthermore the OAuth2 strategy fell into the default fallback of the provider switch statement. This statement did not check email addresses but did generate the letter-avatar instantly. Signed-off-by: Erik Michelson --- lib/models/user.js | 4 ++++ lib/web/auth/oauth2/index.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/models/user.js b/lib/models/user.js index d79530039..5532e5b31 100644 --- a/lib/models/user.js +++ b/lib/models/user.js @@ -133,6 +133,10 @@ module.exports = function (sequelize, DataTypes) { photo = generateAvatarURL(profile.username, profile.emails[0], bigger) break default: + if (profile.emails && profile.emails.length > 0) { + photo = generateAvatarURL(profile.username, profile.emails[0]) + break + } photo = generateAvatarURL(profile.username) break } diff --git a/lib/web/auth/oauth2/index.js b/lib/web/auth/oauth2/index.js index e9032e0b1..feef5e7f9 100644 --- a/lib/web/auth/oauth2/index.js +++ b/lib/web/auth/oauth2/index.js @@ -62,7 +62,7 @@ function parseProfile (data) { id: id || username, username: username, displayName: displayName, - email: email + emails: email ? [email] : [] } } From d8faf3e3423e61c63987d8376408fa21d2a6a392 Mon Sep 17 00:00:00 2001 From: Erik Michelson Date: Fri, 7 Jan 2022 14:03:26 +0100 Subject: [PATCH 2/3] Use identicons as fallback for libravatar The usage of identicons makes users more distinguishable as when only the default librvatar image is used. This only applies to users that have no avatar on libravatar or gravatar. Signed-off-by: Erik Michelson --- lib/letter-avatars.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/letter-avatars.js b/lib/letter-avatars.js index bb7a9fe8b..d9000ef9e 100644 --- a/lib/letter-avatars.js +++ b/lib/letter-avatars.js @@ -37,11 +37,11 @@ exports.generateAvatarURL = function (name, email = '', big = true) { const hexDigest = hash.digest('hex') if (email !== '' && config.allowGravatar) { - photo = 'https://cdn.libravatar.org/avatar/' + hexDigest + photo = `https://cdn.libravatar.org/avatar/${hexDigest}?default=identicon` if (big) { - photo += '?s=400' + photo += '&s=400' } else { - photo += '?s=96' + photo += '&s=96' } } else { photo = config.serverURL + '/user/' + (name || email.substring(0, email.lastIndexOf('@')) || hexDigest) + '/avatar.svg' From 8705c4abd1c809d3205222e770b0ea2b11eeeaf3 Mon Sep 17 00:00:00 2001 From: Erik Michelson Date: Fri, 7 Jan 2022 18:21:33 +0100 Subject: [PATCH 3/3] Update tests and changelog Signed-off-by: Erik Michelson --- public/docs/release-notes.md | 8 ++++++++ test/letter-avatars.js | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/public/docs/release-notes.md b/public/docs/release-notes.md index 306b7e085..3ad8e92d4 100644 --- a/public/docs/release-notes.md +++ b/public/docs/release-notes.md @@ -1,5 +1,13 @@ # Release Notes +## UNRELEASED + +### Bugfixes +- Fix error that Libravatar user avatars were not shown when using OAuth2 login + +### Enhancements +- Libravatar avatars render as ident-icons when no avatar image was uploaded to Libravatar or Gravatar + ## 1.9.2 2021-12-03 ### Bugfixes diff --git a/test/letter-avatars.js b/test/letter-avatars.js index 0645ef876..178075aa3 100644 --- a/test/letter-avatars.js +++ b/test/letter-avatars.js @@ -19,8 +19,8 @@ describe('generateAvatarURL() gravatar enabled', function () { }) it('should return correct urls', function () { - assert.strictEqual(avatars.generateAvatarURL('Daan Sprenkels', 'hello@dsprenkels.com', true), 'https://cdn.libravatar.org/avatar/d41b5f3508cc3f31865566a47dd0336b?s=400') - assert.strictEqual(avatars.generateAvatarURL('Daan Sprenkels', 'hello@dsprenkels.com', false), 'https://cdn.libravatar.org/avatar/d41b5f3508cc3f31865566a47dd0336b?s=96') + assert.strictEqual(avatars.generateAvatarURL('Daan Sprenkels', 'hello@dsprenkels.com', true), 'https://cdn.libravatar.org/avatar/d41b5f3508cc3f31865566a47dd0336b?default=identicon&s=400') + assert.strictEqual(avatars.generateAvatarURL('Daan Sprenkels', 'hello@dsprenkels.com', false), 'https://cdn.libravatar.org/avatar/d41b5f3508cc3f31865566a47dd0336b?default=identicon&s=96') }) it('should return correct urls for names with spaces', function () {