diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs index 056c8384aa..0c61a22f02 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs @@ -16,7 +16,7 @@ namespace Volo.CmsKit.Comments ); Task DeleteWithRepliesAsync( - Guid id, + Comment comment, CancellationToken cancellationToken = default ); } diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs index f8cb15fb5d..9dec7877f8 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs @@ -42,23 +42,22 @@ namespace Volo.CmsKit.Comments } public async Task DeleteWithRepliesAsync( - Guid id, + Comment comment, CancellationToken cancellationToken = default) { var replies = await DbSet - .Where(x => x.RepliedCommentId == id) + .Where(x => x.RepliedCommentId == comment.Id) .ToListAsync(GetCancellationToken(cancellationToken)); foreach (var reply in replies) { - //TODO: Discuss if it is better to mark it as deleted and show in the ui as "This is deleted" instead of deleting it and replies completely - await base.DeleteAsync( - reply.Id, + await DeleteAsync( + reply, cancellationToken: GetCancellationToken(cancellationToken) ); } - await base.DeleteAsync(id, cancellationToken: GetCancellationToken(cancellationToken)); + await DeleteAsync(comment, cancellationToken: GetCancellationToken(cancellationToken)); } } } diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs index 26e8ae0cee..a779111e57 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs @@ -50,11 +50,11 @@ namespace Volo.CmsKit.MongoDB.Comments } public async Task DeleteWithRepliesAsync( - Guid id, - CancellationToken cancellationToken = default) + Comment comment, + CancellationToken cancellationToken = default) { var replies = await GetMongoQueryable() - .Where(x => x.RepliedCommentId == id) + .Where(x => x.RepliedCommentId == comment.Id) .ToListAsync(GetCancellationToken(cancellationToken)); foreach (var reply in replies) @@ -66,7 +66,7 @@ namespace Volo.CmsKit.MongoDB.Comments ); } - await base.DeleteAsync(id, cancellationToken: GetCancellationToken(cancellationToken)); + await base.DeleteAsync(comment, cancellationToken: GetCancellationToken(cancellationToken)); } } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs index c881b59b9b..836dbcb1d1 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs @@ -7,8 +7,6 @@ using Microsoft.Extensions.Options; using Volo.Abp; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; -using Volo.Abp.Authorization; -using Volo.Abp.MultiTenancy; using Volo.Abp.Users; using Volo.CmsKit.Comments; using Volo.CmsKit.Users; @@ -84,13 +82,12 @@ namespace Volo.CmsKit.Public.Comments public virtual async Task DeleteAsync(Guid id) { var comment = await CommentRepository.GetAsync(id); - if (comment.CreatorId != CurrentUser.GetId()) { throw new BusinessException(); } - await CommentRepository.DeleteWithRepliesAsync(id); + await CommentRepository.DeleteWithRepliesAsync(comment); } private List ConvertCommentsToNestedStructure(List comments) diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/Comments/CommentRepository_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/Comments/CommentRepository_Tests.cs index 6b35bae676..80b3052798 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/Comments/CommentRepository_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/Comments/CommentRepository_Tests.cs @@ -32,7 +32,8 @@ namespace Volo.CmsKit.Comments [Fact] public async Task DeleteWithRepliesAsync() { - await _commentRepository.DeleteWithRepliesAsync(_cmsKitTestData.CommentWithChildId); + var comment = await _commentRepository.GetAsync(_cmsKitTestData.CommentWithChildId); + await _commentRepository.DeleteWithRepliesAsync(comment); var list = await _commentRepository.GetListAsync();