mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Optimised user model permissible fn
no issue
- reordered the checks
- optimisation for 2e3876b477
This commit is contained in:
parent
2e3876b477
commit
71b33c8bff
1 changed files with 10 additions and 10 deletions
|
@ -671,7 +671,7 @@ User = ghostBookshelf.Model.extend({
|
||||||
let role = unsafeAttrs.roles[0];
|
let role = unsafeAttrs.roles[0];
|
||||||
let roleId = role.id || role;
|
let roleId = role.id || role;
|
||||||
let editedUserId = userModel.id;
|
let editedUserId = userModel.id;
|
||||||
let contextRoleId = userModel.related('roles').toJSON()[0].id;
|
let contextRoleId = loadedPermissions.user.roles[0].id;
|
||||||
|
|
||||||
if (roleId !== contextRoleId && editedUserId === context.user) {
|
if (roleId !== contextRoleId && editedUserId === context.user) {
|
||||||
return Promise.reject(new common.errors.NoPermissionError({
|
return Promise.reject(new common.errors.NoPermissionError({
|
||||||
|
@ -681,7 +681,7 @@ User = ghostBookshelf.Model.extend({
|
||||||
|
|
||||||
return User.getOwnerUser()
|
return User.getOwnerUser()
|
||||||
.then((owner) => {
|
.then((owner) => {
|
||||||
if (userModel.id === owner.id) {
|
if (context.user === owner.id) {
|
||||||
if (hasUserPermission && hasAppPermission) {
|
if (hasUserPermission && hasAppPermission) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
@ -708,7 +708,8 @@ User = ghostBookshelf.Model.extend({
|
||||||
message: common.i18n.t('errors.models.user.notEnoughPermission')
|
message: common.i18n.t('errors.models.user.notEnoughPermission')
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
|
|
||||||
if (hasUserPermission && hasAppPermission) {
|
if (hasUserPermission && hasAppPermission) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
@ -716,7 +717,6 @@ User = ghostBookshelf.Model.extend({
|
||||||
return Promise.reject(new common.errors.NoPermissionError({
|
return Promise.reject(new common.errors.NoPermissionError({
|
||||||
message: common.i18n.t('errors.models.user.notEnoughPermission')
|
message: common.i18n.t('errors.models.user.notEnoughPermission')
|
||||||
}));
|
}));
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue