Skip to content

Commit

Permalink
Replaced Promise.join() with .all() in user model (#14972)
Browse files Browse the repository at this point in the history
refs: #14882

- Usage of bluebird is deprecated in favour of using native promises
  • Loading branch information
Emmanuel-Melon authored Aug 24, 2022
1 parent 57a786c commit d9f0db6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
16 changes: 10 additions & 6 deletions ghost/core/core/server/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,10 +1005,10 @@ User = ghostBookshelf.Model.extend({
let ownerRole;
let contextUser;

return Promise.join(
return Promise.all([
ghostBookshelf.model('Role').findOne({name: 'Owner'}),
User.findOne({id: options.context.user}, {withRelated: ['roles']})
)
])
.then((results) => {
ownerRole = results[0];
contextUser = results[1];
Expand All @@ -1021,8 +1021,10 @@ User = ghostBookshelf.Model.extend({
}));
}

return Promise.join(ghostBookshelf.model('Role').findOne({name: 'Administrator'}),
User.findOne({id: object.id}, {withRelated: ['roles']}));
return Promise.all([
ghostBookshelf.model('Role').findOne({name: 'Administrator'}),
User.findOne({id: object.id}, {withRelated: ['roles']})
]);
})
.then((results) => {
const adminRole = results[0];
Expand All @@ -1049,9 +1051,11 @@ User = ghostBookshelf.Model.extend({
}

// 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.id);
user.id
]);
})
.then((results) => {
return Users.forge()
Expand Down
5 changes: 4 additions & 1 deletion ghost/core/test/regression/models/model_users.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ describe('User Model', function run() {

it('can findOne by role name', 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) {
let owner = results[0];
let editor = results[1];
Expand Down

0 comments on commit d9f0db6

Please sign in to comment.