Browse Source

Comment needs to be approved again when updated

pull/19919/head
Berkan Sasmaz 2 years ago
parent
commit
a5271d124d
  1. 10
      modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Comments/CommentAdminAppService.cs
  2. 20
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/Comment.cs
  3. 10
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/CommentManager.cs
  4. 4
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs
  5. 4
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Commenting/default.js

10
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);
}

20
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/Comment.cs

@ -27,7 +27,7 @@ public class Comment : AggregateRoot<Guid>, 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<Guid>, 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;
}
}

10
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/CommentManager.cs

@ -18,11 +18,11 @@ public class CommentManager : DomainService
}
public virtual async Task<Comment> 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);

4
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);

4
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']"));

Loading…
Cancel
Save