0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Replaced Promise.join() with .all() in user model (#14972)

refs: https://github.com/TryGhost/Ghost/issues/14882

- Usage of bluebird is deprecated in favour of using native promises
This commit is contained in:
Emmanuel Gatwech 2022-08-24 17:32:44 +03:00 committed by GitHub
parent 57a786c63c
commit d9f0db6a22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 7 deletions

View file

@ -1005,10 +1005,10 @@ User = ghostBookshelf.Model.extend({
let ownerRole; let ownerRole;
let contextUser; let contextUser;
return Promise.join( return Promise.all([
ghostBookshelf.model('Role').findOne({name: 'Owner'}), ghostBookshelf.model('Role').findOne({name: 'Owner'}),
User.findOne({id: options.context.user}, {withRelated: ['roles']}) User.findOne({id: options.context.user}, {withRelated: ['roles']})
) ])
.then((results) => { .then((results) => {
ownerRole = results[0]; ownerRole = results[0];
contextUser = results[1]; contextUser = results[1];
@ -1021,8 +1021,10 @@ User = ghostBookshelf.Model.extend({
})); }));
} }
return Promise.join(ghostBookshelf.model('Role').findOne({name: 'Administrator'}), return Promise.all([
User.findOne({id: object.id}, {withRelated: ['roles']})); ghostBookshelf.model('Role').findOne({name: 'Administrator'}),
User.findOne({id: object.id}, {withRelated: ['roles']})
]);
}) })
.then((results) => { .then((results) => {
const adminRole = results[0]; const adminRole = results[0];
@ -1049,9 +1051,11 @@ User = ghostBookshelf.Model.extend({
} }
// convert owner to admin // convert owner to admin
return Promise.join(contextUser.roles().updatePivot({role_id: adminRole.id}), return Promise.all([
contextUser.roles().updatePivot({role_id: adminRole.id}),
user.roles().updatePivot({role_id: ownerRole.id}), user.roles().updatePivot({role_id: ownerRole.id}),
user.id); user.id
]);
}) })
.then((results) => { .then((results) => {
return Users.forge() return Users.forge()

View file

@ -212,7 +212,10 @@ describe('User Model', function run() {
it('can findOne by role name', function () { it('can findOne by role name', function () {
return testUtils.fixtures.createExtraUsers().then(function () { return testUtils.fixtures.createExtraUsers().then(function () {
return Promise.join(UserModel.findOne({role: 'Owner'}), UserModel.findOne({role: 'Editor'})); return Promise.all([
UserModel.findOne({role: 'Owner'}),
UserModel.findOne({role: 'Editor'})
]);
}).then(function (results) { }).then(function (results) {
let owner = results[0]; let owner = results[0];
let editor = results[1]; let editor = results[1];