Skip to content

Commit

Permalink
Merge pull request pepyatka#214 from davidmz/moderate-hidden-comments
Browse files Browse the repository at this point in the history
Allow post author to destroy hidden comments
  • Loading branch information
dsumin authored May 18, 2017
2 parents 96a9094 + fbb8cdc commit 8ff2a3b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/controllers/api/v1/CommentsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ export default class CommentsController {
throw new NotFoundException("Can't find comment")
}

if (comment.hideType !== Comment.VISIBLE) {
if (!comment.canBeDestroyed()) {
throw new ForbiddenException(
"You can't destroy deleted or hidden comment"
"You can't destroy deleted comment"
)
}

Expand Down
4 changes: 4 additions & 0 deletions app/models/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ export function addModel(dbAdapter) {
return dbAdapter.getPostById(this.postId)
}

Comment.prototype.canBeDestroyed = function () {
return this.hideType !== Comment.DELETED;
}

Comment.prototype.destroy = async function () {
await dbAdapter.deleteComment(this.id, this.postId);
await pubSub.destroyComment(this.id, this.postId);
Expand Down
26 changes: 26 additions & 0 deletions test/functional/hidden-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
createCommentAsync,
banUser,
updateUserAsync,
removeCommentAsync,
} from './functional_test_helper';

describe('Hidden comments', () => {
Expand Down Expand Up @@ -118,5 +119,30 @@ describe('Hidden comments', () => {
expect(reply.comments[0], 'to not have key', 'hideType');
});
});

describe('Delete hidden comment', () => {
beforeEach(async () => {
await banUser(mars, venus);
await updateUserAsync(
mars,
{ frontendPreferences: { 'net.freefeed': { comments: { hiddenTypes: [] } } } },
);
});

it('Mars should be able to delete hidden Venus comment', async () => {
const reply1 = await fetchPost(post.id, mars);
expect(reply1.comments, 'to have length', 2);
const venusComment = reply1.comments.find((c) => c.id === reply1.posts.comments[0]);
expect(venusComment, 'to satisfy', { hideType: Comment.HIDDEN_BANNED });

const delReply = await removeCommentAsync(mars, venusComment.id)
delReply.status.should.eql(200)

const reply2 = await fetchPost(post.id, mars);
expect(reply2.comments, 'to have length', 1);
const lunaComment = reply2.comments.find((c) => c.id === reply2.posts.comments[0]);
expect(lunaComment, 'to satisfy', { hideType: Comment.VISIBLE });
});
});
});
});

0 comments on commit 8ff2a3b

Please sign in to comment.