mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
parent
d4c74e74c4
commit
91f36fc241
2 changed files with 31 additions and 1 deletions
|
@ -201,6 +201,19 @@ invites = {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkIfUserExists(options) {
|
||||||
|
return dataProvider.User.findOne({email: options.data.invites[0].email}, options)
|
||||||
|
.then(function (user) {
|
||||||
|
if (user) {
|
||||||
|
return Promise.reject(new errors.ValidationError({
|
||||||
|
message: i18n.t('errors.api.users.userAlreadyRegistered')
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return options;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function fetchLoggedInUser(options) {
|
function fetchLoggedInUser(options) {
|
||||||
return dataProvider.User.findOne({id: loggedInUser}, _.merge({}, options, {include: ['roles']}))
|
return dataProvider.User.findOne({id: loggedInUser}, _.merge({}, options, {include: ['roles']}))
|
||||||
.then(function (user) {
|
.then(function (user) {
|
||||||
|
@ -219,6 +232,7 @@ invites = {
|
||||||
utils.convertOptions(allowedIncludes),
|
utils.convertOptions(allowedIncludes),
|
||||||
fetchLoggedInUser,
|
fetchLoggedInUser,
|
||||||
validation,
|
validation,
|
||||||
|
checkIfUserExists,
|
||||||
destroyOldInvite,
|
destroyOldInvite,
|
||||||
addInvite
|
addInvite
|
||||||
];
|
];
|
||||||
|
|
|
@ -13,7 +13,7 @@ var should = require('should'),
|
||||||
|
|
||||||
describe('Invites API', function () {
|
describe('Invites API', function () {
|
||||||
beforeEach(testUtils.teardown);
|
beforeEach(testUtils.teardown);
|
||||||
beforeEach(testUtils.setup('invites', 'users:roles', 'perms:invite', 'perms:init'));
|
beforeEach(testUtils.setup('invites', 'settings', 'users:roles', 'perms:invite', 'perms:init'));
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
sandbox.stub(mail, 'send', function () {
|
sandbox.stub(mail, 'send', function () {
|
||||||
|
@ -72,6 +72,22 @@ describe('Invites API', function () {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('add invite: invite existing user', function (done) {
|
||||||
|
InvitesAPI.add({
|
||||||
|
invites: [{
|
||||||
|
email: testUtils.DataGenerator.Content.users[0].email,
|
||||||
|
role_id: testUtils.roles.ids.author
|
||||||
|
}]
|
||||||
|
}, testUtils.context.owner)
|
||||||
|
.then(function () {
|
||||||
|
throw new Error('expected validation error');
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
(err instanceof errors.ValidationError).should.eql(true);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Browse', function () {
|
describe('Browse', function () {
|
||||||
|
|
Loading…
Add table
Reference in a new issue