mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Ensured API can ask model.wasChanged
refs #10461 - the model layer (only post & user) fetches the model after update - i assume it was added to ensure a response with all fields - quick fixing it for now to ensure API layer can access ".wasChanged" to be able to decide if a request modified a resource or not @NOTE: Bookshelf does not physically update a resource if nothing has changed.
This commit is contained in:
parent
4fca28e643
commit
82c5fc7f5a
2 changed files with 8 additions and 4 deletions
|
@ -781,6 +781,7 @@ Post = ghostBookshelf.Model.extend({
|
|||
if (found) {
|
||||
// Pass along the updated attributes for checking status changes
|
||||
found._previousAttributes = post._previousAttributes;
|
||||
found._changed = post._changed;
|
||||
return found;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -449,7 +449,7 @@ User = ghostBookshelf.Model.extend({
|
|||
}
|
||||
|
||||
ops.push(function update() {
|
||||
return ghostBookshelf.Model.edit.call(self, data, options).then(function then(user) {
|
||||
return ghostBookshelf.Model.edit.call(self, data, options).then((user) => {
|
||||
var roleId;
|
||||
|
||||
if (!data.roles) {
|
||||
|
@ -458,13 +458,13 @@ User = ghostBookshelf.Model.extend({
|
|||
|
||||
roleId = data.roles[0].id || data.roles[0];
|
||||
|
||||
return user.roles().fetch().then(function then(roles) {
|
||||
return user.roles().fetch().then((roles) => {
|
||||
// return if the role is already assigned
|
||||
if (roles.models[0].id === roleId) {
|
||||
return;
|
||||
}
|
||||
return ghostBookshelf.model('Role').findOne({id: roleId});
|
||||
}).then(function then(roleToAssign) {
|
||||
}).then((roleToAssign) => {
|
||||
if (roleToAssign && roleToAssign.get('name') === 'Owner') {
|
||||
return Promise.reject(
|
||||
new common.errors.ValidationError({
|
||||
|
@ -475,9 +475,12 @@ User = ghostBookshelf.Model.extend({
|
|||
// assign all other roles
|
||||
return user.roles().updatePivot({role_id: roleId});
|
||||
}
|
||||
}).then(function then() {
|
||||
}).then(() => {
|
||||
options.status = 'all';
|
||||
return self.findOne({id: user.id}, options);
|
||||
}).then((model) => {
|
||||
model._changed = user._changed;
|
||||
return model;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue