mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
fix: user should not crash if email is missing
This commit is contained in:
parent
9f86bce0ab
commit
bf7a246707
@ -41,7 +41,7 @@ class ContextFieldStore {
|
||||
}
|
||||
|
||||
async _createFromConfig(customContextFields) {
|
||||
if (customContextFields) {
|
||||
if (customContextFields && customContextFields.length > 0) {
|
||||
this.logger.info(
|
||||
'Create custom context fields',
|
||||
customContextFields,
|
||||
|
10
lib/user.js
10
lib/user.js
@ -24,7 +24,13 @@ module.exports = class User {
|
||||
this.email = email;
|
||||
this.systemId = systemId;
|
||||
this.permissions = permissions;
|
||||
this.imageUrl =
|
||||
imageUrl || gravatarUrl(email, { size: '42', default: 'retro' });
|
||||
this.imageUrl = imageUrl || this.generateImageUrl();
|
||||
}
|
||||
|
||||
generateImageUrl() {
|
||||
return gravatarUrl(this.email || this.username, {
|
||||
size: '42',
|
||||
default: 'retro',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -57,3 +57,12 @@ test('Should require valid email', t => {
|
||||
|
||||
t.is(error.message, 'Email "value" must be a valid email');
|
||||
});
|
||||
|
||||
test('Should create user with only username defined', t => {
|
||||
const user = new User({ username: 'some-user' });
|
||||
t.is(user.username, 'some-user');
|
||||
t.is(
|
||||
user.imageUrl,
|
||||
'https://gravatar.com/avatar/140fd5a002fb8d728a9848f8c9fcea2a?size=42&default=retro',
|
||||
);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user