0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Fixed x_by being detected as changed if owner updates resources

refs #9299

- `contextUser` returns a number and if the previous x_by is "1", then bookshelf marks it as changed ("1" !== 1)
- this is a left over from 0.x, because we still owner as id 1
- as soon as we fix 9299, we don't have to worry about this anymore, because we will fetch the owner id if we need it
This commit is contained in:
kirrg001 2019-02-23 22:00:24 +01:00
parent 4a1a245e9b
commit 641b67e784
2 changed files with 6 additions and 6 deletions

View file

@ -311,13 +311,13 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
onCreating: function onCreating(model, attr, options) {
if (schema.tables[this.tableName].hasOwnProperty('created_by')) {
if (!options.importing || (options.importing && !this.get('created_by'))) {
this.set('created_by', this.contextUser(options));
this.set('created_by', String(this.contextUser(options)));
}
}
if (schema.tables[this.tableName].hasOwnProperty('updated_by')) {
if (!options.importing) {
this.set('updated_by', this.contextUser(options));
this.set('updated_by', String(this.contextUser(options)));
}
}
@ -377,7 +377,7 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
if (schema.tables[this.tableName].hasOwnProperty('updated_by')) {
if (!options.importing && !options.migrating) {
this.set('updated_by', this.contextUser(options));
this.set('updated_by', String(this.contextUser(options)));
}
}
@ -390,7 +390,7 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
if (schema.tables[this.tableName].hasOwnProperty('created_by')) {
if (model.hasChanged('created_by')) {
model.set('created_by', this.previous('created_by'));
model.set('created_by', String(this.previous('created_by')));
}
}
}

View file

@ -388,12 +388,12 @@ Post = ghostBookshelf.Model.extend({
if (newStatus === 'published' && this.hasChanged('status')) {
// unless published_by is set and we're importing, set published_by to contextUser
if (!(this.get('published_by') && options.importing)) {
this.set('published_by', this.contextUser(options));
this.set('published_by', String(this.contextUser(options)));
}
} else {
// In any other case (except import), `published_by` should not be changed
if (this.hasChanged('published_by') && !options.importing) {
this.set('published_by', this.previous('published_by') || null);
this.set('published_by', this.previous('published_by') ? String(this.previous('published_by')) : null);
}
}