diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs index 07b17083c2..edb709d846 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs @@ -88,7 +88,15 @@ public class CommentAdminAppService : CmsKitAdminAppServiceBase, ICommentAdminAp public async Task UpdateApprovalStatusAsync(Guid id, CommentApprovalDto input) { var comment = await CommentRepository.GetAsync(id); - comment.IsApproved = input.IsApproved; + + if (input.IsApproved) + { + comment.Approve(); + } + else + { + comment.Reject(); + } await CommentRepository.UpdateAsync(comment); } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/Comment.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/Comment.cs index 78e43ac857..589b8d5cb2 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/Comment.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/Comment.cs @@ -27,7 +27,7 @@ public class Comment : AggregateRoot, IHasCreationTime, IMustHaveCreator, public virtual string IdempotencyToken { get; set; } - public virtual bool? IsApproved { get; set; } + public virtual bool? IsApproved { get; private set; } protected Comment() { @@ -64,4 +64,22 @@ public class Comment : AggregateRoot, IHasCreationTime, IMustHaveCreator, { Text = Check.NotNullOrWhiteSpace(text, nameof(text), CommentConsts.MaxTextLength); } + + public virtual Comment Approve() + { + IsApproved = true; + return this; + } + + public virtual Comment Reject() + { + IsApproved = false; + return this; + } + + public virtual Comment WaitForApproval() + { + IsApproved = null; + return this; + } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/CommentManager.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/CommentManager.cs index b9f4e5c1d7..0daa7fc6fa 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/CommentManager.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/CommentManager.cs @@ -18,11 +18,11 @@ public class CommentManager : DomainService } public virtual async Task CreateAsync([NotNull] CmsUser creator, - [NotNull] string entityType, - [NotNull] string entityId, - [NotNull] string text, - [CanBeNull] string url = null, - [CanBeNull] Guid? repliedCommentId = null) + [NotNull] string entityType, + [NotNull] string entityId, + [NotNull] string text, + [CanBeNull] string url = null, + [CanBeNull] Guid? repliedCommentId = null) { Check.NotNull(creator, nameof(creator)); Check.NotNullOrWhiteSpace(entityType, nameof(entityType), CommentConsts.MaxEntityTypeLength); 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 d0937eb04c..3cbb2c7df4 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 @@ -115,6 +115,10 @@ public class CommentPublicAppService : CmsKitPublicAppServiceBase, ICommentPubli comment.SetText(input.Text); comment.SetConcurrencyStampIfNotNull(input.ConcurrencyStamp); + if (bool.Parse(await SettingManager.GetOrNullGlobalAsync(CmsKitSettings.Comments.RequireApprovement))) + { + comment.WaitForApproval(); + } var updatedComment = await CommentRepository.UpdateAsync(comment); diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js index 85c8a207b6..56a5a50b9b 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js @@ -111,6 +111,10 @@ $form.submit(function (e) { e.preventDefault(); + + if (abp.setting.getBoolean("CmsKit.Comments.RequireApprovement")) { + abp.message.success(l("CommentUpdatedForApproval"), l("SavedSuccessfully")); + } abp.ui.setBusy($form.find("button[type='submit']"));