Skip to content

Commit

Permalink
🔥 user model: default author role
Browse files Browse the repository at this point in the history
refs TryGhost#7494

Our fixtures system is smart. You can define a user and a separated relation.
Right now we always expect static id's for everything: roles, permissions, users.
That's why we simply do for adding the owner: roles: [4] --> role id 4
So you can use separated relations or you can use a direct relation.

This does not work when generating ObjectId's. Ok it could work if we decide to define for ALL static resources a static ID, but i think that is not needed at all.

So this PR removes the default creation of an author role when user.roles is undefined or empty, to be able to create the owner without a static role id and instead use the fixture relation feature.

I looked in this git history, the default author role was invented without explaining. See TryGhost@5c6d45f
  • Loading branch information
kirrg001 committed Nov 4, 2016
1 parent be341b5 commit 16af0a4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
8 changes: 1 addition & 7 deletions core/server/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,7 @@ User = ghostBookshelf.Model.extend({
return Promise.reject(new errors.ValidationError({message: i18n.t('errors.models.user.onlyOneRolePerUserSupported')}));
}

function getAuthorRole() {
return ghostBookshelf.model('Role').findOne({name: 'Author'}, _.pick(options, 'transacting')).then(function then(authorRole) {
return [authorRole.get('id')];
});
}

roles = data.roles || getAuthorRole();
roles = data.roles || [];
delete data.roles;

return ghostBookshelf.Model.add.call(self, userData, options)
Expand Down
7 changes: 6 additions & 1 deletion core/test/utils/fixtures/export/export-003-mu-noOwner.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,14 @@
"user_id": 1
},
{
"id": 1,
"id": 2,
"role_id": 1,
"user_id": 2
},
{
"id": 3,
"role_id": 3,
"user_id": 3
}
],
"settings": [
Expand Down
9 changes: 7 additions & 2 deletions core/test/utils/fixtures/export/export-003-mu.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,14 @@
"user_id": 1
},
{
"id": 1,
"id": 2,
"role_id": 1,
"user_id": 2
},
{
"id": 3,
"role_id": 3,
"user_id": 3
}
],
"permissions": [
Expand Down Expand Up @@ -477,4 +482,4 @@
}
]
}
}
}

0 comments on commit 16af0a4

Please sign in to comment.