mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 21:40:39 +03:00
🐛 fix email already in use (#7987)
refs #7981 - usage of data.id was wrong - usage of id comparison was wrong
This commit is contained in:
parent
d9e87aa793
commit
2a5927b4f9
@ -368,11 +368,10 @@ User = ghostBookshelf.Model.extend({
|
||||
options = options || {};
|
||||
options.withRelated = _.union(options.withRelated, options.include);
|
||||
|
||||
if (data.email && data.id) {
|
||||
if (data.email) {
|
||||
ops.push(function checkForDuplicateEmail() {
|
||||
return self.getByEmail(data.email).then(function then(user) {
|
||||
// don't allow update if another user already uses this email
|
||||
if (user && user.id !== data.id) {
|
||||
if (user && user.id !== options.id) {
|
||||
return Promise.reject(new errors.ValidationError({message: i18n.t('errors.models.user.userUpdateError.emailIsAlreadyInUse')}));
|
||||
}
|
||||
});
|
||||
|
@ -416,16 +416,17 @@ describe('User Model', function run() {
|
||||
});
|
||||
|
||||
it('can NOT set an already existing email address', function (done) {
|
||||
var firstUser = testUtils.DataGenerator.Content.users[0].id,
|
||||
secondEmail = testUtils.DataGenerator.Content.users[1].email;
|
||||
var firstUser = testUtils.DataGenerator.Content.users[0],
|
||||
secondUser = testUtils.DataGenerator.Content.users[1];
|
||||
|
||||
UserModel.findOne({id: firstUser}).then(function (user) {
|
||||
return user.edit({email: secondEmail});
|
||||
}).then(function () {
|
||||
done(new Error('Already existing email address was accepted'));
|
||||
}).catch(function () {
|
||||
done();
|
||||
});
|
||||
UserModel.edit({email: secondUser.email}, {id: firstUser.id})
|
||||
.then(function () {
|
||||
done(new Error('Already existing email address was accepted'));
|
||||
})
|
||||
.catch(function (err) {
|
||||
(err instanceof errors.ValidationError).should.eql(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can edit invited user', function (done) {
|
||||
|
Loading…
Reference in New Issue
Block a user