mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
Avoid setting profile name to not found (#8357)
* avoid setting profile name to not found * only set profile name when empty * profile.name is required * set profile name before validation * fix and add tests
This commit is contained in:
@@ -131,6 +131,16 @@ function _setProfileName (user) {
|
||||
return localUsername || _getFacebookName(user.auth.facebook) || googleUsername || anonymous;
|
||||
}
|
||||
|
||||
schema.pre('validate', function preValidateUser (next) {
|
||||
// Populate new user with profile name, not running in pre('save') because the field
|
||||
// is required and validation fails if it doesn't exists like for new users
|
||||
if (this.isNew && !this.profile.name) {
|
||||
this.profile.name = _setProfileName(this);
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
schema.pre('save', true, function preSaveUser (next, done) {
|
||||
next();
|
||||
|
||||
@@ -138,10 +148,6 @@ schema.pre('save', true, function preSaveUser (next, done) {
|
||||
this.preferences.dayStart = 0;
|
||||
}
|
||||
|
||||
if (!this.profile.name) {
|
||||
this.profile.name = _setProfileName(this);
|
||||
}
|
||||
|
||||
// Determines if Beast Master should be awarded
|
||||
let beastMasterProgress = shared.count.beastMasterProgress(this.items.pets);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user