diff --git a/core/server/models/base/listeners.js b/core/server/models/base/listeners.js index 57dc9110d3..d009c1d9b7 100644 --- a/core/server/models/base/listeners.js +++ b/core/server/models/base/listeners.js @@ -26,8 +26,13 @@ events.on('token.added', function (tokenModel) { * - if an active user get's deleted, we have to access the previous attributes, because this is how bookshelf works * if you delete a user. */ -events.on('user.deactivated', function (userModel) { - var options = {id: userModel.id || userModel.previousAttributes().id}; +events.on('user.deactivated', function (userModel, options) { + options = options || {}; + options = _.merge({}, options, {id: userModel.id || userModel.previousAttributes().id}); + + if (options.importing) { + return; + } models.Accesstoken.destroyByUser(options) .then(function () { @@ -46,17 +51,23 @@ events.on('user.deactivated', function (userModel) { * - reschedule all scheduled posts * - draft scheduled posts, when the published_at would be in the past */ -events.on('settings.active_timezone.edited', function (settingModel) { +events.on('settings.active_timezone.edited', function (settingModel, options) { + options = options || {}; + options = _.merge({}, options, {context: {internal: true}}); + var newTimezone = settingModel.attributes.value, previousTimezone = settingModel._updatedAttributes.value, - timezoneOffsetDiff = moment.tz(previousTimezone).utcOffset() - moment.tz(newTimezone).utcOffset(), - options = {context: {internal: true}}; + timezoneOffsetDiff = moment.tz(previousTimezone).utcOffset() - moment.tz(newTimezone).utcOffset(); // CASE: TZ was updated, but did not change if (previousTimezone === newTimezone) { return; } + if (options.importing) { + return; + } + /** * CASE: * `Post.findAll` and the Post.edit` must run in one single transaction. diff --git a/core/server/models/settings.js b/core/server/models/settings.js index 2cecf45f6e..1f5d1c5a30 100644 --- a/core/server/models/settings.js +++ b/core/server/models/settings.js @@ -57,23 +57,23 @@ Settings = ghostBookshelf.Model.extend({ }; }, - emitChange: function emitChange(event) { - events.emit('settings' + '.' + event, this); + emitChange: function emitChange(event, options) { + events.emit('settings' + '.' + event, this, options); }, - onDestroyed: function onDestroyed(model) { + onDestroyed: function onDestroyed(model, response, options) { model.emitChange('deleted'); - model.emitChange(model.attributes.key + '.' + 'deleted'); + model.emitChange(model.attributes.key + '.' + 'deleted', options); }, - onCreated: function onCreated(model) { + onCreated: function onCreated(model, response, options) { model.emitChange('added'); - model.emitChange(model.attributes.key + '.' + 'added'); + model.emitChange(model.attributes.key + '.' + 'added', options); }, - onUpdated: function onUpdated(model) { + onUpdated: function onUpdated(model, response, options) { model.emitChange('edited'); - model.emitChange(model.attributes.key + '.' + 'edited'); + model.emitChange(model.attributes.key + '.' + 'edited', options); }, onValidate: function onValidate() { diff --git a/core/server/models/user.js b/core/server/models/user.js index a47f153bdd..ca406ee9d8 100644 --- a/core/server/models/user.js +++ b/core/server/models/user.js @@ -52,13 +52,13 @@ User = ghostBookshelf.Model.extend({ }, baseDefaults); }, - emitChange: function emitChange(event) { - events.emit('user' + '.' + event, this); + emitChange: function emitChange(event, options) { + events.emit('user' + '.' + event, this, options); }, - onDestroyed: function onDestroyed(model) { + onDestroyed: function onDestroyed(model, response, options) { if (_.includes(activeStates, model.previous('status'))) { - model.emitChange('deactivated'); + model.emitChange('deactivated', options); } model.emitChange('deleted'); @@ -73,12 +73,12 @@ User = ghostBookshelf.Model.extend({ } }, - onUpdated: function onUpdated(model) { + onUpdated: function onUpdated(model, response, options) { model.statusChanging = model.get('status') !== model.updated('status'); model.isActive = _.includes(activeStates, model.get('status')); if (model.statusChanging) { - model.emitChange(model.isActive ? 'activated' : 'deactivated'); + model.emitChange(model.isActive ? 'activated' : 'deactivated', options); } else { if (model.isActive) { model.emitChange('activated.edited');