+
-
diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml.cs
index 245937b45f..36c89543c8 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/Index.cshtml.cs
@@ -1,4 +1,5 @@
using System;
+using Volo.CmsKit.Comments;
namespace Volo.CmsKit.Admin.Web.Pages.CmsKit.Comments;
@@ -11,6 +12,6 @@ public class IndexModel : CmsKitAdminPageModel
public DateTime? CreationStartDate { get; set; } = null;
public DateTime? CreationEndDate { get; set; }
- public string IsApproved { get; set; }
+ public CommentApproveStateType commentApproveStateType { get; set; }
}
diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/details.js b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/details.js
index ed85779569..44ed1f80e2 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/details.js
+++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/details.js
@@ -200,7 +200,14 @@ $(function (){
_dataTable.ajax.reloadEx();
});
-
+ commentsService.getSettings().then(function (data) {
+ if (data.requireApprovement) {
+ $('#CommentsTable').DataTable().column(4).visible(true);
+ } else {
+ $('#CommentsTable').DataTable().column(4).visible(false);
+ $('#isApprovedColumn').hide();
+ }
+ })
filterForm.submit(function (e){
e.preventDefault();
_dataTable.ajax.reloadEx();
diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/index.js b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/index.js
index f103f1c142..811f15181e 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/index.js
+++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Comments/index.js
@@ -236,11 +236,11 @@ $(function (){
e.preventDefault();
_dataTable.ajax.reloadEx();
});
+
// Get and display pending comment count
commentsService.getPendingCommentCount().then(function (count) {
- console.log(count)
if (count > 0) {
- var alertMessage = l("CommentAlertMessage") + count + "";
+ var alertMessage = l("CommentAlertMessage", count);
var alertElement = '
' + alertMessage + '';
$('#commentsAlert').html(alertElement);
$('#commentsAlert').show()
@@ -256,6 +256,7 @@ $(function (){
$('#CommentsTable').DataTable().column(6).visible(true);
} else {
$('#CommentsTable').DataTable().column(6).visible(false);
+ $('#isApprovedColumn').hide();
}
})
});
\ No newline at end of file
diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Settings/CommentSettingPageContributor.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Settings/CommentSettingPageContributor.cs
index 5ea7383087..0a88e7b35d 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Settings/CommentSettingPageContributor.cs
+++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Settings/CommentSettingPageContributor.cs
@@ -1,6 +1,7 @@
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
+using Volo.Abp.Authorization.Permissions;
using Volo.Abp.SettingManagement.Web.Pages.SettingManagement;
using Volo.CmsKit.Admin.Web.Components.MySettingGroup;
using Volo.CmsKit.Localization;
@@ -9,7 +10,6 @@ namespace Volo.CmsKit.Admin.Web.Settings;
public class CommentSettingPageContributor : ISettingPageContributor
{
-
public Task ConfigureAsync(SettingPageCreationContext context)
{
var l = context.ServiceProvider.GetRequiredService
>();
@@ -22,6 +22,7 @@ public class CommentSettingPageContributor : ISettingPageContributor
)
);
+
return Task.CompletedTask;
}
diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/wwwroot/client-proxies/cms-kit-admin-proxy.js b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/wwwroot/client-proxies/cms-kit-admin-proxy.js
index 15271077a5..f86682dc87 100644
--- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/wwwroot/client-proxies/cms-kit-admin-proxy.js
+++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/wwwroot/client-proxies/cms-kit-admin-proxy.js
@@ -176,7 +176,7 @@
volo.cmsKit.admin.comments.commentAdmin.getList = function(input, ajaxParams) {
return abp.ajax($.extend(true, {
- url: abp.appPath + 'api/cms-kit-admin/comments' + abp.utils.buildQueryString([{ name: 'entityType', value: input.entityType }, { name: 'text', value: input.text }, { name: 'repliedCommentId', value: input.repliedCommentId }, { name: 'author', value: input.author }, { name: 'creationStartDate', value: input.creationStartDate }, { name: 'creationEndDate', value: input.creationEndDate }, { name: 'isApproved', value: input.isApproved }, { name: 'sorting', value: input.sorting }, { name: 'skipCount', value: input.skipCount }, { name: 'maxResultCount', value: input.maxResultCount }]) + '',
+ url: abp.appPath + 'api/cms-kit-admin/comments' + abp.utils.buildQueryString([{ name: 'entityType', value: input.entityType }, { name: 'text', value: input.text }, { name: 'repliedCommentId', value: input.repliedCommentId }, { name: 'author', value: input.author }, { name: 'creationStartDate', value: input.creationStartDate }, { name: 'creationEndDate', value: input.creationEndDate }, { name: 'commentApproveStateType', value: input.commentApproveStateType }, { name: 'sorting', value: input.sorting }, { name: 'skipCount', value: input.skipCount }, { name: 'maxResultCount', value: input.maxResultCount }]) + '',
type: 'GET'
}, ajaxParams));
};
@@ -230,7 +230,7 @@
volo.cmsKit.admin.comments.commentAdmin.getWaitingCommentsWithReplies = function(input, ajaxParams) {
return abp.ajax($.extend(true, {
- url: abp.appPath + 'api/cms-kit-admin/comments/waiting' + abp.utils.buildQueryString([{ name: 'entityType', value: input.entityType }, { name: 'text', value: input.text }, { name: 'repliedCommentId', value: input.repliedCommentId }, { name: 'author', value: input.author }, { name: 'creationStartDate', value: input.creationStartDate }, { name: 'creationEndDate', value: input.creationEndDate }, { name: 'isApproved', value: input.isApproved }, { name: 'sorting', value: input.sorting }, { name: 'skipCount', value: input.skipCount }, { name: 'maxResultCount', value: input.maxResultCount }]) + '',
+ url: abp.appPath + 'api/cms-kit-admin/comments/waiting' + abp.utils.buildQueryString([{ name: 'entityType', value: input.entityType }, { name: 'text', value: input.text }, { name: 'repliedCommentId', value: input.repliedCommentId }, { name: 'author', value: input.author }, { name: 'creationStartDate', value: input.creationStartDate }, { name: 'creationEndDate', value: input.creationEndDate }, { name: 'commentApproveStateType', value: input.commentApproveStateType }, { name: 'sorting', value: input.sorting }, { name: 'skipCount', value: input.skipCount }, { name: 'maxResultCount', value: input.maxResultCount }]) + '',
type: 'GET'
}, ajaxParams));
};
diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Comments/CommentApproveStateType.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Comments/CommentApproveStateType.cs
new file mode 100644
index 0000000000..df7f96fbda
--- /dev/null
+++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Comments/CommentApproveStateType.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Volo.CmsKit.Comments;
+public enum CommentApproveStateType
+{
+ All,
+ True,
+ False,
+ Null
+}
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 9bb12e6c7e..2e54c74de8 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
@@ -246,7 +246,7 @@
"Approve":"Approve",
"Disapproved":"Disapproved",
- "CommentAlertMessage":"You have waiting comments: ",
+ "CommentAlertMessage":"There are {0} comments waiting for approval",
"Menu:CmsKitCommentOptions":"CmsKit Comment Options"
}
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 512cefceda..b3edc81de2 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
@@ -21,26 +21,26 @@ public interface ICommentRepository : IBasicRepository
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
- string isApproved = null,
- CancellationToken cancellationToken = default
+ CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
+ CancellationToken cancellationToken = default
);
Task GetCountAsync(
- string text = null,
+ string text = null,
string entityType = null,
Guid? repliedCommentId = null,
string authorUsername = null,
DateTime? creationStartDate = null,
DateTime? creationEndDate = null,
- string isApproved = null,
- CancellationToken cancellationToken = default
+ CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
+ CancellationToken cancellationToken = default
);
Task> GetListWithAuthorsAsync(
[NotNull] string entityType,
[NotNull] string entityId,
- bool? isApproved,
- CancellationToken cancellationToken = default
+ CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
+ CancellationToken cancellationToken = default
);
Task DeleteWithRepliesAsync(
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 d3bec8af43..df5dec45ee 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
@@ -15,179 +15,189 @@ using Volo.CmsKit.Users;
namespace Volo.CmsKit.Comments;
public class EfCoreCommentRepository : EfCoreRepository,
- ICommentRepository
+ ICommentRepository
{
- public EfCoreCommentRepository(IDbContextProvider dbContextProvider)
- : base(dbContextProvider)
- {
- }
-
- public virtual async Task GetWithAuthorAsync(Guid id,
- CancellationToken cancellationToken = default)
- {
- var query = from comment in (await GetDbSetAsync())
- join user in (await GetDbContextAsync()).Set() on comment.CreatorId equals user.Id
- where id == comment.Id
- select new CommentWithAuthorQueryResultItem
- {
- Comment = comment,
- Author = user
- };
-
- var commentWithAuthor = await query.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
-
- if (commentWithAuthor == null)
- {
- throw new EntityNotFoundException(typeof(Comment), id);
- }
-
- return commentWithAuthor;
- }
-
- public virtual async Task> GetListAsync(
- string filter = null,
- string entityType = null,
- Guid? repliedCommentId = null,
- string authorUsername = null,
- DateTime? creationStartDate = null,
- DateTime? creationEndDate = null,
- string sorting = null,
- int maxResultCount = int.MaxValue,
- int skipCount = 0,
- bool? isApproved = null,
- CancellationToken cancellationToken = default
- )
- {
- var token = GetCancellationToken(cancellationToken);
- var query = await GetListQueryAsync(
- filter,
- entityType,
- repliedCommentId,
- authorUsername,
- creationStartDate,
- creationEndDate,
- isApproved,
- token);
-
- if (!sorting.IsNullOrEmpty())
- {
- sorting = "comment." + sorting;
- }
-
- query = query.OrderBy(sorting.IsNullOrEmpty() ? "comment.creationTime desc" : sorting)
- .PageBy(skipCount, maxResultCount);
-
- return await query.ToListAsync(token);
- }
-
- public virtual async Task GetCountAsync(
- string text = null,
- string entityType = null,
- Guid? repliedCommentId = null,
- string authorUsername = null,
- DateTime? creationStartDate = null,
- DateTime? creationEndDate = null,
- bool? isApproved = null,
- CancellationToken cancellationToken = default
-
- )
- {
- var token = GetCancellationToken(cancellationToken);
- var query = await GetListQueryAsync(
- text,
- entityType,
- repliedCommentId,
- authorUsername,
- creationStartDate,
- creationEndDate,
- isApproved,
- token);
-
- return await query.LongCountAsync(token);
- }
-
- public virtual async Task> GetListWithAuthorsAsync(
- string entityType,
- string entityId,
- bool ? isApproved = null,
- CancellationToken cancellationToken = default)
- {
- Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
- Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
-
- var query = from comment in (await GetDbSetAsync())
- join user in (await GetDbContextAsync()).Set() on comment.CreatorId equals user.Id
- where entityType == comment.EntityType && entityId == comment.EntityId
+ public EfCoreCommentRepository(IDbContextProvider dbContextProvider)
+ : base(dbContextProvider)
+ {
+ }
+
+ public virtual async Task GetWithAuthorAsync(Guid id,
+ CancellationToken cancellationToken = default)
+ {
+ var query = from comment in (await GetDbSetAsync())
+ join user in (await GetDbContextAsync()).Set() on comment.CreatorId equals user.Id
+ where id == comment.Id
+ select new CommentWithAuthorQueryResultItem
+ {
+ Comment = comment,
+ Author = user
+ };
+
+ var commentWithAuthor = await query.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
+
+ if (commentWithAuthor == null)
+ {
+ throw new EntityNotFoundException(typeof(Comment), id);
+ }
+
+ return commentWithAuthor;
+ }
+
+ public virtual async Task> GetListAsync(
+ string filter = null,
+ string entityType = null,
+ Guid? repliedCommentId = null,
+ string authorUsername = null,
+ DateTime? creationStartDate = null,
+ DateTime? creationEndDate = null,
+ string sorting = null,
+ int maxResultCount = int.MaxValue,
+ int skipCount = 0,
+ CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
+ CancellationToken cancellationToken = default
+ )
+ {
+ var token = GetCancellationToken(cancellationToken);
+ var query = await GetListQueryAsync(
+ filter,
+ entityType,
+ repliedCommentId,
+ authorUsername,
+ creationStartDate,
+ creationEndDate,
+ commentApproveStateType,
+ token);
+
+ if (!sorting.IsNullOrEmpty())
+ {
+ sorting = "comment." + sorting;
+ }
+
+ query = query.OrderBy(sorting.IsNullOrEmpty() ? "comment.creationTime desc" : sorting)
+ .PageBy(skipCount, maxResultCount);
+
+ return await query.ToListAsync(token);
+ }
+
+ public virtual async Task GetCountAsync(
+ string text = null,
+ string entityType = null,
+ Guid? repliedCommentId = null,
+ string authorUsername = null,
+ DateTime? creationStartDate = null,
+ DateTime? creationEndDate = null,
+ CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
+ CancellationToken cancellationToken = default
+
+ )
+ {
+ var token = GetCancellationToken(cancellationToken);
+ var query = await GetListQueryAsync(
+ text,
+ entityType,
+ repliedCommentId,
+ authorUsername,
+ creationStartDate,
+ creationEndDate,
+ commentApproveStateType,
+ token);
+
+ return await query.LongCountAsync(token);
+ }
+
+ public virtual async Task> GetListWithAuthorsAsync(
+ string entityType,
+ string entityId,
+ CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
+ CancellationToken cancellationToken = default)
+ {
+ Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
+ Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
+
+ var query = from comment in (await GetDbSetAsync())
+ join user in (await GetDbContextAsync()).Set() on comment.CreatorId equals user.Id
+ where entityType == comment.EntityType && entityId == comment.EntityId
orderby comment.CreationTime
- select new CommentWithAuthorQueryResultItem
- {
- Comment = comment,
- Author = user
- };
+ select new CommentWithAuthorQueryResultItem
+ {
+ Comment = comment,
+ Author = user
+ };
- if (isApproved.HasValue)
+ if (CommentApproveStateType.True == commentApproveStateType)
+ {
+ query = query.Where(c => c.Comment.IsApproved == true);
+ }
+ else if (CommentApproveStateType.False == commentApproveStateType)
{
- query = query.Where(c => c.Comment.IsApproved == isApproved.Value);
+ query = query.Where(c => c.Comment.IsApproved == false);
+ }
+ else if (CommentApproveStateType.Null == commentApproveStateType)
+ {
+ query = query.Where(c => c.Comment.IsApproved == null);
}
return await query.ToListAsync(GetCancellationToken(cancellationToken));
- }
-
- public virtual async Task DeleteWithRepliesAsync(
- Comment comment,
- CancellationToken cancellationToken = default)
- {
- var replies = await (await GetDbSetAsync())
- .Where(x => x.RepliedCommentId == comment.Id)
- .ToListAsync(GetCancellationToken(cancellationToken));
-
- foreach (var reply in replies)
- {
- await DeleteAsync(
- reply,
- cancellationToken: GetCancellationToken(cancellationToken)
- );
- }
-
- await DeleteAsync(comment, cancellationToken: GetCancellationToken(cancellationToken));
- }
-
- public virtual async Task ExistsAsync(string idempotencyToken, CancellationToken cancellationToken = default)
- {
- return await (await GetDbSetAsync()).AnyAsync(x => x.IdempotencyToken == idempotencyToken, GetCancellationToken(cancellationToken));
- }
-
- protected virtual async Task> GetListQueryAsync(
- string filter = null,
- string entityType = null,
- Guid? repliedCommentId = null,
- string authorUsername = null,
- DateTime? creationStartDate = null,
- DateTime? creationEndDate = null,
- bool? isApproved = null,
-
- CancellationToken cancellationToken = default
-
- )
- {
- var commentDbSet = await GetDbSetAsync();
- var cmsUserSet = (await GetDbContextAsync()).Set();
-
- var query = from comment in commentDbSet
- join user in cmsUserSet
- on comment.CreatorId equals user.Id
- select new CommentWithAuthorQueryResultItem
- {
- Comment = comment,
- Author = user
- };
-
- return query.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Comment.Text.Contains(filter))
- .WhereIf(!entityType.IsNullOrWhiteSpace(), c => c.Comment.EntityType.Contains(entityType))
- .WhereIf(repliedCommentId.HasValue, c => c.Comment.RepliedCommentId == repliedCommentId)
- .WhereIf(!authorUsername.IsNullOrWhiteSpace(), c => c.Author.UserName.Contains(authorUsername))
- .WhereIf(creationStartDate.HasValue, c => c.Comment.CreationTime >= creationStartDate)
- .WhereIf(creationEndDate.HasValue, c => c.Comment.CreationTime <= creationEndDate)
- .WhereIf(isApproved.HasValue, c => c.Comment.IsApproved == isApproved);
- }
+ }
+
+ public virtual async Task DeleteWithRepliesAsync(
+ Comment comment,
+ CancellationToken cancellationToken = default)
+ {
+ var replies = await (await GetDbSetAsync())
+ .Where(x => x.RepliedCommentId == comment.Id)
+ .ToListAsync(GetCancellationToken(cancellationToken));
+
+ foreach (var reply in replies)
+ {
+ await DeleteAsync(
+ reply,
+ cancellationToken: GetCancellationToken(cancellationToken)
+ );
+ }
+
+ await DeleteAsync(comment, cancellationToken: GetCancellationToken(cancellationToken));
+ }
+
+ public virtual async Task ExistsAsync(string idempotencyToken, CancellationToken cancellationToken = default)
+ {
+ return await (await GetDbSetAsync()).AnyAsync(x => x.IdempotencyToken == idempotencyToken, GetCancellationToken(cancellationToken));
+ }
+
+ protected virtual async Task> GetListQueryAsync(
+ string filter = null,
+ string entityType = null,
+ Guid? repliedCommentId = null,
+ string authorUsername = null,
+ DateTime? creationStartDate = null,
+ DateTime? creationEndDate = null,
+ CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
+ CancellationToken cancellationToken = default
+
+ )
+ {
+ var commentDbSet = await GetDbSetAsync();
+ var cmsUserSet = (await GetDbContextAsync()).Set();
+
+ var query = from comment in commentDbSet
+ join user in cmsUserSet
+ on comment.CreatorId equals user.Id
+ select new CommentWithAuthorQueryResultItem
+ {
+ Comment = comment,
+ Author = user
+ };
+
+ return query.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Comment.Text.Contains(filter))
+ .WhereIf(!entityType.IsNullOrWhiteSpace(), c => c.Comment.EntityType.Contains(entityType))
+ .WhereIf(repliedCommentId.HasValue, c => c.Comment.RepliedCommentId == repliedCommentId)
+ .WhereIf(!authorUsername.IsNullOrWhiteSpace(), c => c.Author.UserName.Contains(authorUsername))
+ .WhereIf(creationStartDate.HasValue, c => c.Comment.CreationTime >= creationStartDate)
+ .WhereIf(creationEndDate.HasValue, c => c.Comment.CreationTime <= creationEndDate)
+ .WhereIf(CommentApproveStateType.True == commentApproveStateType, c => c.Comment.IsApproved == true)
+ .WhereIf(CommentApproveStateType.False == commentApproveStateType, c => c.Comment.IsApproved == false)
+ .WhereIf(CommentApproveStateType.Null == commentApproveStateType, c => c.Comment.IsApproved == null);
+ //.WhereIf(isApproved.HasValue, c => c.Comment.IsApproved == isApproved);
+ }
}
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 b26a9b1d26..cf11c36db0 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
@@ -16,231 +16,231 @@ namespace Volo.CmsKit.MongoDB.Comments;
public class MongoCommentRepository : MongoDbRepository, ICommentRepository
{
- public MongoCommentRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider)
- {
- }
-
- public virtual async Task GetWithAuthorAsync(Guid id, CancellationToken cancellationToken = default)
- {
- var comment = await GetAsync(id);
- var author = await (await GetDbContextAsync())
- .CmsUsers
- .AsQueryable()
- .FirstOrDefaultAsync(x => x.Id == comment.CreatorId, GetCancellationToken(cancellationToken));
-
- return new CommentWithAuthorQueryResultItem()
- {
- Comment = comment,
- Author = author
- };
- }
-
- public virtual async Task> GetListAsync(
- string filter = null,
- string entityType = null,
- Guid? repliedCommentId = null,
- string authorUsername = null,
- DateTime? creationStartDate = null,
- DateTime? creationEndDate = null,
- string sorting = null,
- int maxResultCount = int.MaxValue,
- int skipCount = 0,
- string isApproved = null,
- CancellationToken cancellationToken = default
- )
-
- {
- //bool? isApprovedValue = ParseIsApproved(isApproved);
-
- var token = GetCancellationToken(cancellationToken);
- var query = await GetListQueryAsync(
- filter,
- entityType,
- repliedCommentId,
- authorUsername,
- creationStartDate,
- creationEndDate,
- isApproved,
- token);
-
- var comments = await query.OrderBy(sorting.IsNullOrEmpty() ? "creationTime desc" : sorting)
- .As>()
- .PageBy>(skipCount, maxResultCount)
- .ToListAsync(token);
-
- var commentIds = comments.Select(x => x.Id).ToList();
-
- var authorsQuery = from comment in (await GetMongoQueryableAsync(token))
- join user in (await GetDbContextAsync(token)).CmsUsers on comment.CreatorId equals user.Id
- where commentIds.Contains(comment.Id)
- orderby comment.CreationTime
- select user;
-
- var authors = await ApplyDataFilters, CmsUser>(authorsQuery).ToListAsync(token);
-
- return comments
- .Select(
- comment =>
- new CommentWithAuthorQueryResultItem
- {
- Comment = comment,
- Author = authors.FirstOrDefault(a => a.Id == comment.CreatorId)
- }).ToList();
- }
-
- public virtual async Task GetCountAsync(
- string text = null,
- string entityType = null,
- Guid? repliedCommentId = null,
- string authorUsername = null,
- DateTime? creationStartDate = null,
- DateTime? creationEndDate = null,
- string isApproved = null,
- CancellationToken cancellationToken = default
- )
- {
- //bool? isApprovedValue = ParseIsApproved(isApproved);
- var query = await GetListQueryAsync(
- text,
- entityType,
- repliedCommentId,
- authorUsername,
- creationStartDate,
- creationEndDate,
- isApproved,
- cancellationToken);
-
- return await query.As>()
- .LongCountAsync(GetCancellationToken(cancellationToken));
- }
-
- public virtual async Task> GetListWithAuthorsAsync(
- string entityType,
- string entityId,
- bool? isApproved,
- CancellationToken cancellationToken = default)
- {
- Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
- Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
-
- var authorsQuery = from comment in (await GetMongoQueryableAsync(cancellationToken))
- join user in (await GetDbContextAsync(cancellationToken)).CmsUsers on comment.CreatorId equals user.Id
- where entityType == comment.EntityType && entityId == comment.EntityId
- orderby comment.CreationTime
- select user;
-
- var authors = await ApplyDataFilters, CmsUser>(authorsQuery).ToListAsync(GetCancellationToken(cancellationToken));
-
- var commentsQuery = (await GetMongoQueryableAsync(cancellationToken))
- .Where(c => c.EntityId == entityId && c.EntityType == entityType);
-
-
- commentsQuery = isApproved.Value ?
- commentsQuery.Where(c => c.IsApproved == true) :
- commentsQuery.Where(c => c.IsApproved == true || c.IsApproved == null);
-
-
- var comments = await commentsQuery
- .OrderBy(c => c.CreationTime)
- .ToListAsync(GetCancellationToken(cancellationToken));
-
- return comments
- .Select(
- comment =>
- new CommentWithAuthorQueryResultItem
- {
- Comment = comment,
- Author = authors.FirstOrDefault(a => a.Id == comment.CreatorId)
- }).ToList();
- }
-
- public virtual async Task DeleteWithRepliesAsync(
- Comment comment,
- CancellationToken cancellationToken = default)
- {
- var replies = await (await GetMongoQueryableAsync(cancellationToken))
- .Where(x => x.RepliedCommentId == comment.Id)
- .ToListAsync(GetCancellationToken(cancellationToken));
-
- await base.DeleteAsync(
- comment,
- cancellationToken: GetCancellationToken(cancellationToken)
- );
-
- foreach (var reply in replies)
- {
- await base.DeleteAsync(
- reply,
- cancellationToken: GetCancellationToken(cancellationToken)
- );
- }
- }
-
- public virtual async Task ExistsAsync(string idempotencyToken, CancellationToken cancellationToken = default)
- {
- return await (await GetMongoQueryableAsync(cancellationToken))
- .AnyAsync(x => x.IdempotencyToken == idempotencyToken, GetCancellationToken(cancellationToken));
- }
-
- protected virtual async Task> GetListQueryAsync(
- string filter = null,
- string entityType = null,
- Guid? repliedCommentId = null,
- string authorUsername = null,
- DateTime? creationStartDate = null,
- DateTime? creationEndDate = null,
- string isApproved = null,
- CancellationToken cancellationToken = default
- )
- {
- var queryable = await GetMongoQueryableAsync(cancellationToken);
-
- if (!string.IsNullOrEmpty(authorUsername))
- {
- var author = await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.UserName == authorUsername, cancellationToken: cancellationToken);
-
- var authorId = author?.Id ?? Guid.Empty;
-
- queryable = queryable.Where(x => x.CreatorId == authorId);
- }
-
- queryable.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Text.Contains(filter))
- .WhereIf(!entityType.IsNullOrWhiteSpace(), c => c.EntityType == entityType)
- .WhereIf(repliedCommentId.HasValue, c => c.RepliedCommentId == repliedCommentId)
- .WhereIf(creationStartDate.HasValue, c => c.CreationTime >= creationStartDate)
- .WhereIf(creationEndDate.HasValue, c => c.CreationTime <= creationEndDate);
-
- if (!string.IsNullOrWhiteSpace(isApproved))
- {
- bool? isApprovedValue = ParseIsApproved(isApproved);
- if (isApprovedValue.HasValue)
- {
- queryable = queryable.Where(c => c.IsApproved == isApprovedValue);
- }
- else if (isApprovedValue == null)
- {
- queryable = queryable.Where(c => c.IsApproved == null);
- }
-
- }
-
- return queryable;
-
- }
- public static bool? ParseIsApproved(string isApproved)
- {
- if (string.IsNullOrWhiteSpace(isApproved))
- {
- return null;
- }
-
- return isApproved.ToLower() switch
- {
- "true" => true,
- "false" => false,
- "null" => (bool?)null,
- _ => null
-
- };
- }
+ public MongoCommentRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider)
+ {
+ }
+
+ public virtual async Task GetWithAuthorAsync(Guid id, CancellationToken cancellationToken = default)
+ {
+ var comment = await GetAsync(id);
+ var author = await (await GetDbContextAsync())
+ .CmsUsers
+ .AsQueryable()
+ .FirstOrDefaultAsync(x => x.Id == comment.CreatorId, GetCancellationToken(cancellationToken));
+
+ return new CommentWithAuthorQueryResultItem()
+ {
+ Comment = comment,
+ Author = author
+ };
+ }
+
+ public virtual async Task> GetListAsync(
+ string filter = null,
+ string entityType = null,
+ Guid? repliedCommentId = null,
+ string authorUsername = null,
+ DateTime? creationStartDate = null,
+ DateTime? creationEndDate = null,
+ string sorting = null,
+ int maxResultCount = int.MaxValue,
+ int skipCount = 0,
+ CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
+ CancellationToken cancellationToken = default
+ )
+
+ {
+ //bool? isApprovedValue = ParseIsApproved(isApproved);
+
+ var token = GetCancellationToken(cancellationToken);
+ var query = await GetListQueryAsync(
+ filter,
+ entityType,
+ repliedCommentId,
+ authorUsername,
+ creationStartDate,
+ creationEndDate,
+ commentApproveStateType,
+ token);
+
+ var comments = await query.OrderBy(sorting.IsNullOrEmpty() ? "creationTime desc" : sorting)
+ .As>()
+ .PageBy>(skipCount, maxResultCount)
+ .ToListAsync(token);
+
+ var commentIds = comments.Select(x => x.Id).ToList();
+
+ var authorsQuery = from comment in (await GetMongoQueryableAsync(token))
+ join user in (await GetDbContextAsync(token)).CmsUsers on comment.CreatorId equals user.Id
+ where commentIds.Contains(comment.Id)
+ orderby comment.CreationTime
+ select user;
+
+ var authors = await ApplyDataFilters, CmsUser>(authorsQuery).ToListAsync(token);
+
+ return comments
+ .Select(
+ comment =>
+ new CommentWithAuthorQueryResultItem
+ {
+ Comment = comment,
+ Author = authors.FirstOrDefault(a => a.Id == comment.CreatorId)
+ }).ToList();
+ }
+
+ public virtual async Task GetCountAsync(
+ string text = null,
+ string entityType = null,
+ Guid? repliedCommentId = null,
+ string authorUsername = null,
+ DateTime? creationStartDate = null,
+ DateTime? creationEndDate = null,
+ CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
+ CancellationToken cancellationToken = default
+ )
+ {
+ //bool? isApprovedValue = ParseIsApproved(isApproved);
+ var query = await GetListQueryAsync(
+ text,
+ entityType,
+ repliedCommentId,
+ authorUsername,
+ creationStartDate,
+ creationEndDate,
+ commentApproveStateType,
+ cancellationToken);
+
+ return await query.As>()
+ .LongCountAsync(GetCancellationToken(cancellationToken));
+ }
+
+ public virtual async Task> GetListWithAuthorsAsync(
+ string entityType,
+ string entityId,
+ CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
+ CancellationToken cancellationToken = default)
+ {
+ Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
+ Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
+
+ var authorsQuery = from comment in (await GetMongoQueryableAsync(cancellationToken))
+ join user in (await GetDbContextAsync(cancellationToken)).CmsUsers on comment.CreatorId equals user.Id
+ where entityType == comment.EntityType && entityId == comment.EntityId
+ orderby comment.CreationTime
+ select user;
+
+ var authors = await ApplyDataFilters, CmsUser>(authorsQuery).ToListAsync(GetCancellationToken(cancellationToken));
+
+ var commentsQuery = (await GetMongoQueryableAsync(cancellationToken))
+ .Where(c => c.EntityId == entityId && c.EntityType == entityType);
+
+
+ commentsQuery = (IMongoQueryable)FilterCommentsByApprovalState(commentsQuery, commentApproveStateType);
+
+ var comments = await commentsQuery
+ .OrderBy(c => c.CreationTime)
+ .ToListAsync(GetCancellationToken(cancellationToken));
+
+ return comments
+ .Select(
+ comment =>
+ new CommentWithAuthorQueryResultItem
+ {
+ Comment = comment,
+ Author = authors.FirstOrDefault(a => a.Id == comment.CreatorId)
+ }).ToList();
+ }
+
+ public virtual async Task DeleteWithRepliesAsync(
+ Comment comment,
+ CancellationToken cancellationToken = default)
+ {
+ var replies = await (await GetMongoQueryableAsync(cancellationToken))
+ .Where(x => x.RepliedCommentId == comment.Id)
+ .ToListAsync(GetCancellationToken(cancellationToken));
+
+ await base.DeleteAsync(
+ comment,
+ cancellationToken: GetCancellationToken(cancellationToken)
+ );
+
+ foreach (var reply in replies)
+ {
+ await base.DeleteAsync(
+ reply,
+ cancellationToken: GetCancellationToken(cancellationToken)
+ );
+ }
+ }
+
+ public virtual async Task ExistsAsync(string idempotencyToken, CancellationToken cancellationToken = default)
+ {
+ return await (await GetMongoQueryableAsync(cancellationToken))
+ .AnyAsync(x => x.IdempotencyToken == idempotencyToken, GetCancellationToken(cancellationToken));
+ }
+
+ protected virtual async Task> GetListQueryAsync(
+ string filter = null,
+ string entityType = null,
+ Guid? repliedCommentId = null,
+ string authorUsername = null,
+ DateTime? creationStartDate = null,
+ DateTime? creationEndDate = null,
+ CommentApproveStateType commentApproveStateType = CommentApproveStateType.All,
+ CancellationToken cancellationToken = default
+ )
+ {
+ var queryable = await GetMongoQueryableAsync(cancellationToken);
+
+ if (!string.IsNullOrEmpty(authorUsername))
+ {
+ var author = await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.UserName == authorUsername, cancellationToken: cancellationToken);
+
+ var authorId = author?.Id ?? Guid.Empty;
+
+ queryable = queryable.Where(x => x.CreatorId == authorId);
+ }
+
+ queryable.WhereIf(!filter.IsNullOrWhiteSpace(), c => c.Text.Contains(filter))
+ .WhereIf(!entityType.IsNullOrWhiteSpace(), c => c.EntityType == entityType)
+ .WhereIf(repliedCommentId.HasValue, c => c.RepliedCommentId == repliedCommentId)
+ .WhereIf(creationStartDate.HasValue, c => c.CreationTime >= creationStartDate)
+ .WhereIf(creationEndDate.HasValue, c => c.CreationTime <= creationEndDate);
+ //.WhereIf(CommentApproveStateType.True == commentApproveStateType, c => c.IsApproved == true)
+ //.WhereIf(CommentApproveStateType.False == commentApproveStateType, c => c.IsApproved == false)
+ //.WhereIf(CommentApproveStateType.Null == commentApproveStateType, c => c.IsApproved == null);
+
+ if (CommentApproveStateType.True == commentApproveStateType)
+ {
+ queryable = queryable.Where(c => c.IsApproved == true);
+ }
+ else if (CommentApproveStateType.False == commentApproveStateType)
+ {
+ queryable = queryable.Where(c => c.IsApproved == false);
+
+ }
+ else if (CommentApproveStateType.Null == commentApproveStateType)
+ {
+ queryable = queryable.Where(c => c.IsApproved == null);
+ }
+
+
+ return queryable;
+
+ }
+
+ public IQueryable FilterCommentsByApprovalState(IQueryable commentsQuery, CommentApproveStateType approveState)
+ {
+ switch (approveState)
+ {
+ case CommentApproveStateType.True:
+ commentsQuery = commentsQuery.Where(c => c.IsApproved == true);
+ break;
+ case CommentApproveStateType.False:
+ commentsQuery = commentsQuery.Where(c => c.IsApproved == true || c.IsApproved == null);
+ break;
+ }
+
+ return commentsQuery;
+ }
}
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 bee75d40eb..0edec591e7 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
@@ -58,8 +58,10 @@ public class CommentPublicAppService : CmsKitPublicAppServiceBase, ICommentPubli
public virtual async Task> GetListAsync(string entityType, string entityId)
{
string state = await SettingManager.GetOrNullGlobalAsync(AppSettings.RequireApprovement);
+ var commentsWithAuthor = bool.Parse(state) ?
+ await CommentRepository.GetListWithAuthorsAsync(entityType, entityId, CommentApproveStateType.True) :
+ await CommentRepository.GetListWithAuthorsAsync(entityType, entityId, CommentApproveStateType.False);
- var commentsWithAuthor = await CommentRepository.GetListWithAuthorsAsync(entityType, entityId, bool.Parse(state));
return new ListResultDto(
ConvertCommentsToNestedStructure(commentsWithAuthor)