Skip to content

Commit

Permalink
🐛 Fixed contributors being able to delete draft posts as co-author
Browse files Browse the repository at this point in the history
closes TryGhost#10238

- The user of contributor role should not be allowed editing a post while not being a primary author
  • Loading branch information
naz committed Dec 4, 2018
1 parent bf295a9 commit 21d9853
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions core/server/models/relations/authors.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,22 +314,26 @@ module.exports.extendModel = function extendModel(Post, Posts, ghostBookshelf) {
return isCorrectOwner;
}

function isCurrentOwner() {
function isPrimaryAuthor() {
return (context.user === postModel.related('authors').models[0].id);
}

function isCoAuthor() {
return postModel.related('authors').models.map(author => author.id).includes(context.user);
}

if (isContributor && isEdit) {
hasUserPermission = !isChanging('author_id') && !isChangingAuthors() && isCurrentOwner();
hasUserPermission = !isChanging('author_id') && !isChangingAuthors() && isCoAuthor();
} else if (isContributor && isAdd) {
hasUserPermission = isOwner();
} else if (isContributor && isDestroy) {
hasUserPermission = isCurrentOwner();
hasUserPermission = isPrimaryAuthor();
} else if (isAuthor && isEdit) {
hasUserPermission = isCurrentOwner() && !isChanging('author_id') && !isChangingAuthors();
hasUserPermission = isCoAuthor() && !isChanging('author_id') && !isChangingAuthors();
} else if (isAuthor && isAdd) {
hasUserPermission = isOwner();
} else if (postModel) {
hasUserPermission = hasUserPermission || isCurrentOwner();
hasUserPermission = hasUserPermission || isPrimaryAuthor();
}

if (hasUserPermission && hasAppPermission) {
Expand Down

0 comments on commit 21d9853

Please sign in to comment.