Skip to content

Commit

Permalink
blogging: Let users delete their own comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yekalkan committed Mar 9, 2020
1 parent 4a0567a commit b0adb9f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ protected override async Task HandleRequirementAsync(

private async Task<bool> HasDeletePermission(AuthorizationHandlerContext context, Comment resource)
{
if (resource.CreatorId != null && resource.CreatorId == context.User.FindUserId())
{
return true;
}

if (await _permissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Comments.Delete))
{
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ protected override async Task HandleRequirementAsync(

private async Task<bool> HasDeletePermission(AuthorizationHandlerContext context, Post resource)
{
if (resource.CreatorId != null && resource.CreatorId == context.User.FindUserId())
{
return true;
}

if (await _permissionChecker.IsGrantedAsync(context.User, BloggingPermissions.Posts.Delete))
{
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Task<CommentWithDetailsDto> UpdateAsync(Guid id, UpdateCommentDto input)
[Route("{id}")]
public Task DeleteAsync(Guid id)
{
throw new NotImplementedException();
return _commentAppService.DeleteAsync(id);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
</a>
}

@if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Delete))
@if (await Authorization.IsGrantedAsync(BloggingPermissions.Comments.Delete) || (CurrentUser.Id == commentWithRepliesDto.Comment.CreatorId))
{
<span class="seperator">|</span>
<a href="#" class="tag deleteLink" data-deleteid="@commentWithRepliesDto.Comment.Id">
Expand Down

0 comments on commit b0adb9f

Please sign in to comment.