Skip to content

Commit

Permalink
🐛 respect owner user id references when importing (#8693)
Browse files Browse the repository at this point in the history
closes #8691 

There was a condition added when i've refactored the importer.

> if (models.User.isOwnerUser(obj[key])) {

This condition is absolutely wrong! If you import an owner user, this owner user get's imported as administrator. But the original owner user id reference must be updated as well, so that the reference points to the new administrator id ✌🏻
  • Loading branch information
kirrg001 authored and kevinansfield committed Jul 20, 2017
1 parent 91f36fc commit 90fc7a6
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 84 deletions.
18 changes: 11 additions & 7 deletions core/server/data/importer/importers/data/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class Base {
* - we update all fields after the import (!)
*/
afterImport(options) {
let self = this, dataToEdit = {}, oldUser;
let self = this, dataToEdit = {}, oldUser, context;

debug('afterImport', this.modelName);

Expand All @@ -164,12 +164,9 @@ class Base {
}

return Promise.each(['author_id', 'published_by', 'created_by', 'updated_by'], function (key) {
// CASE: not all fields exist on each model, skip them if so
if (!obj[key]) {
return;
}

if (models.User.isOwnerUser(obj[key])) {
return;
return Promise.resolve();
}

oldUser = _.find(self.users, {id: obj[key]});
Expand All @@ -191,7 +188,14 @@ class Base {
dataToEdit = {};
dataToEdit[key] = userModel.id;

return models[self.modelName].edit(dataToEdit, _.extend(options, {id: obj.model.id}));
// CASE: updated_by is taken from the context object
if (key === 'updated_by') {
context = {context: {user: userModel.id}};
} else {
context = {};
}

return models[self.modelName].edit(dataToEdit, _.merge({}, options, {id: obj.model.id}, context));
});
});
});
Expand Down
Loading

0 comments on commit 90fc7a6

Please sign in to comment.