mirror of
https://github.com/plankanban/planka.git
synced 2025-12-21 01:11:26 +03:00
feat: Add ability to use Gravatar as avatar provider (#1319)
Closes #1243
This commit is contained in:
@@ -52,6 +52,13 @@ const UserAvatar = React.memo(
|
||||
|
||||
const [t] = useTranslation();
|
||||
|
||||
let avatarUrl = null;
|
||||
if (user.avatar) {
|
||||
avatarUrl = user.avatar.thumbnailUrls.cover180;
|
||||
} else if (user.gravatarUrl) {
|
||||
avatarUrl = user.gravatarUrl;
|
||||
}
|
||||
|
||||
const contentNode = (
|
||||
<span
|
||||
title={
|
||||
@@ -65,13 +72,13 @@ const UserAvatar = React.memo(
|
||||
styles.wrapper,
|
||||
styles[`wrapper${upperFirst(size)}`],
|
||||
onClick && styles.wrapperHoverable,
|
||||
!user.avatar && styles[`background${upperFirst(camelCase(getColor(user.name)))}`],
|
||||
!avatarUrl && styles[`background${upperFirst(camelCase(getColor(user.name)))}`],
|
||||
)}
|
||||
style={{
|
||||
background: user.avatar && `url("${user.avatar.thumbnailUrls.cover180}") center / cover`,
|
||||
background: avatarUrl && `url("${avatarUrl}") center / cover`,
|
||||
}}
|
||||
>
|
||||
{!user.avatar && <span className={styles.initials}>{initials(user.name).slice(0, 2)}</span>}
|
||||
{!avatarUrl && <span className={styles.initials}>{initials(user.name).slice(0, 2)}</span>}
|
||||
{withCreatorIndicator && <span className={styles.creatorIndicator}>+</span>}
|
||||
</span>
|
||||
);
|
||||
|
||||
@@ -84,6 +84,10 @@ services:
|
||||
# - SMTP_PASSWORD=
|
||||
# - SMTP_FROM="Demo Demo" <demo@demo.demo>
|
||||
# - SMTP_TLS_REJECT_UNAUTHORIZED=false
|
||||
|
||||
# Using Gravatar directly exposes user IPs and hashed emails to a third party (GDPR risk).
|
||||
# Use a proxy you control for privacy, or leave commented out or empty to disable.
|
||||
# GRAVATAR_BASE_URL=https://www.gravatar.com/avatar/
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
|
||||
@@ -104,6 +104,10 @@ services:
|
||||
# - SMTP_PASSWORD__FILE=/run/secrets/smtp_password
|
||||
# - SMTP_FROM="Demo Demo" <demo@demo.demo>
|
||||
# - SMTP_TLS_REJECT_UNAUTHORIZED=false
|
||||
|
||||
# Using Gravatar directly exposes user IPs and hashed emails to a third party (GDPR risk).
|
||||
# Use a proxy you control for privacy, or leave commented out or empty to disable.
|
||||
# GRAVATAR_BASE_URL=https://www.gravatar.com/avatar/
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
|
||||
@@ -75,3 +75,7 @@ SECRET_KEY=notsecretkey
|
||||
# SMTP_PASSWORD=
|
||||
# SMTP_FROM="Demo Demo" <demo@demo.demo>
|
||||
# SMTP_TLS_REJECT_UNAUTHORIZED=false
|
||||
|
||||
# Using Gravatar directly exposes user IPs and hashed emails to a third party (GDPR risk).
|
||||
# Use a proxy you control for privacy, or leave commented out or empty to disable.
|
||||
# GRAVATAR_BASE_URL=https://www.gravatar.com/avatar/
|
||||
|
||||
26
server/api/helpers/users/build-gravatar-url.js
Normal file
26
server/api/helpers/users/build-gravatar-url.js
Normal file
@@ -0,0 +1,26 @@
|
||||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
const crypto = require('crypto');
|
||||
|
||||
module.exports = {
|
||||
sync: true,
|
||||
|
||||
inputs: {
|
||||
record: {
|
||||
type: 'ref',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
fn(inputs) {
|
||||
if (!sails.config.custom.gravatarBaseUrl) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const hash = crypto.createHash('md5').update(inputs.record.email).digest('hex');
|
||||
return `${sails.config.custom.gravatarBaseUrl}${hash}?s=180&d=initials`;
|
||||
},
|
||||
};
|
||||
@@ -36,6 +36,12 @@ module.exports = {
|
||||
termsType: sails.hooks.terms.getTypeByUserRole(inputs.record.role),
|
||||
};
|
||||
|
||||
const gravatarUrl = sails.helpers.users.buildGravatarUrl(inputs.record);
|
||||
|
||||
if (gravatarUrl) {
|
||||
data.gravatarUrl = gravatarUrl;
|
||||
}
|
||||
|
||||
if (inputs.user) {
|
||||
const isForCurrentUser = inputs.record.id === inputs.user.id;
|
||||
const isForAdmin = inputs.user.role === User.Roles.ADMIN;
|
||||
|
||||
@@ -105,4 +105,6 @@ module.exports.custom = {
|
||||
smtpPassword: process.env.SMTP_PASSWORD,
|
||||
smtpFrom: process.env.SMTP_FROM,
|
||||
smtpTlsRejectUnauthorized: process.env.SMTP_TLS_REJECT_UNAUTHORIZED !== 'false',
|
||||
|
||||
gravatarBaseUrl: process.env.GRAVATAR_BASE_URL,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user