From ca7ff542404c2d2efd3b3e2124cc4dbb10c4924c Mon Sep 17 00:00:00 2001 From: Berkan Sasmaz Date: Wed, 5 Jun 2024 09:42:39 +0300 Subject: [PATCH] If RequireApprovementSettings is disable when a new comment is created, IsApprove value defaults to true --- .../Shared/Components/Comments/default.js | 14 +------ .../CmsKit/Localization/Resources/en.json | 2 - .../Volo/CmsKit/Comments/CommentManager.cs | 41 +++++++++++++------ .../Comments/CommentPublicAppService.cs | 4 -- .../Shared/Components/Commenting/default.js | 4 -- 5 files changed, 31 insertions(+), 34 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Shared/Components/Comments/default.js b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Shared/Components/Comments/default.js index 8e2817b866..042cb87a77 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Shared/Components/Comments/default.js +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Shared/Components/Comments/default.js @@ -25,18 +25,8 @@ previousValue = commentRequireApprovement; }) } - - if (isRequireApproved && !previousValue) { - abp.message.confirm(l("CommentRequireApprovementWarning"), function (ok) { - if (ok) { - UpdateSettings(isRequireApproved); - } else { - $('#RequireApprovementCheckbox').prop('checked', false); - } - }); - } else { - UpdateSettings(isRequireApproved); - } + + UpdateSettings(isRequireApproved); }); }; diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json index 55ca122797..0f49bdbccf 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json @@ -245,7 +245,5 @@ "Settings:Menu:CmsKit":"CMS", "CommentsAwaitingApproval":"Comments Awaiting Approval", "CommentSubmittedForApproval": "Your comment has been submitted for approval.", - "CommentUpdatedForApproval": "Your comment has been updated and submitted for approval.", - "CommentRequireApprovementWarning": "Once this setting is enabled, your existing comments will not appear in the UI if they are not approved. Do you want to continue the process?" } } \ No newline at end of file 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 0daa7fc6fa..20e8a81106 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 @@ -1,9 +1,9 @@ - -using JetBrains.Annotations; +using JetBrains.Annotations; using System; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Domain.Services; +using Volo.Abp.SettingManagement; using Volo.CmsKit.Users; namespace Volo.CmsKit.Comments; @@ -11,10 +11,14 @@ namespace Volo.CmsKit.Comments; public class CommentManager : DomainService { protected ICommentEntityTypeDefinitionStore DefinitionStore { get; } + protected ISettingManager SettingManager { get; } - public CommentManager(ICommentEntityTypeDefinitionStore definitionStore) + public CommentManager( + ICommentEntityTypeDefinitionStore definitionStore, + ISettingManager settingManager) { DefinitionStore = definitionStore; + SettingManager = settingManager; } public virtual async Task CreateAsync([NotNull] CmsUser creator, @@ -34,14 +38,27 @@ public class CommentManager : DomainService throw new EntityNotCommentableException(entityType); } - return new Comment( - GuidGenerator.Create(), - entityType, - entityId, - text, - repliedCommentId, - creator.Id, - url, - CurrentTenant.Id); + var comment = new Comment( + GuidGenerator.Create(), + entityType, + entityId, + text, + repliedCommentId, + creator.Id, + url, + CurrentTenant.Id); + + + var isRequireApprovementEnabled = bool.Parse(await SettingManager.GetOrNullGlobalAsync(CmsKitSettings.Comments.RequireApprovement)); + if (isRequireApprovementEnabled) + { + comment.WaitForApproval(); + } + else + { + comment.Approve(); + } + + return comment; } } 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 3cbb2c7df4..d0937eb04c 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,10 +115,6 @@ 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 56a5a50b9b..ff3bdf7703 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 @@ -112,10 +112,6 @@ $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']")); let formAsObject = $form.serializeFormToObject();