Skip to content

Commit 5cc441e

Browse files
authored
🐛 Fixed contributors being able to delete draft posts as co-author (TryGhost#10239)
closes TryGhost#10238 - The user of contributor role should not be allowed editing a post while not being a primary author
1 parent bf295a9 commit 5cc441e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

core/server/models/relations/authors.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,22 +314,26 @@ module.exports.extendModel = function extendModel(Post, Posts, ghostBookshelf) {
314314
return isCorrectOwner;
315315
}
316316

317-
function isCurrentOwner() {
317+
function isPrimaryAuthor() {
318+
return (context.user === postModel.related('authors').models[0].id);
319+
}
320+
321+
function isCoAuthor() {
318322
return postModel.related('authors').models.map(author => author.id).includes(context.user);
319323
}
320324

321325
if (isContributor && isEdit) {
322-
hasUserPermission = !isChanging('author_id') && !isChangingAuthors() && isCurrentOwner();
326+
hasUserPermission = !isChanging('author_id') && !isChangingAuthors() && isCoAuthor();
323327
} else if (isContributor && isAdd) {
324328
hasUserPermission = isOwner();
325329
} else if (isContributor && isDestroy) {
326-
hasUserPermission = isCurrentOwner();
330+
hasUserPermission = isPrimaryAuthor();
327331
} else if (isAuthor && isEdit) {
328-
hasUserPermission = isCurrentOwner() && !isChanging('author_id') && !isChangingAuthors();
332+
hasUserPermission = isCoAuthor() && !isChanging('author_id') && !isChangingAuthors();
329333
} else if (isAuthor && isAdd) {
330334
hasUserPermission = isOwner();
331335
} else if (postModel) {
332-
hasUserPermission = hasUserPermission || isCurrentOwner();
336+
hasUserPermission = hasUserPermission || isPrimaryAuthor();
333337
}
334338

335339
if (hasUserPermission && hasAppPermission) {

0 commit comments

Comments
 (0)