From acb19ffa22a1d54d6cf59dd723d62309c2811f35 Mon Sep 17 00:00:00 2001 From: enisn Date: Thu, 31 Dec 2020 14:29:49 +0300 Subject: [PATCH 01/32] CmsKit - Add Content Admin Permissions --- .../Volo/CmsKit/Permissions/CmsKitAdminPermissions.cs | 8 ++++++++ .../Volo/CmsKit/Localization/Resources/en.json | 4 ++++ .../Volo/CmsKit/Localization/Resources/tr.json | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Permissions/CmsKitAdminPermissions.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Permissions/CmsKitAdminPermissions.cs index 26daeb0b01..55bffff67f 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Permissions/CmsKitAdminPermissions.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Permissions/CmsKitAdminPermissions.cs @@ -12,5 +12,13 @@ namespace Volo.CmsKit.Permissions public const string Update = Default + ".Update"; public const string Delete = Default + ".Delete"; } + + public static class Contents + { + public const string Default = GroupName + ".Contents"; + public const string Create = Default + ".Create"; + public const string Update = Default + ".Update"; + public const string Delete = Default + ".Delete"; + } } } 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 42d56b8d16..a2aee70c49 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 @@ -14,6 +14,10 @@ "Permission:TagManagement.Create": "Create Tag", "Permission:TagManagement.Delete": "Delete Tag", "Permission:TagManagement.Update": "Update Tag", + "Permission:Contents": "Content Management", + "Permission:Contents.Create": "Create Content", + "Permission:Contents.Delete": "Delete Content", + "Permission:Contents.Update": "Update Content", "PickYourReaction": "Pick your reaction", "RatingUndoMessage": "Your rating will be undo.", "Reply": "Reply", diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/tr.json b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/tr.json index ac8bd98a9f..693be35377 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/tr.json +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/tr.json @@ -14,6 +14,10 @@ "Permission:TagManagement.Create": "Etiket Oluşturma", "Permission:TagManagement.Delete": "Etiket Silme", "Permission:TagManagement.Update": "Etiket Güncelleme", + "Permission:Contents": "İçerik Yönetimi", + "Permission:Contents.Create": "İçerik Oluşturma", + "Permission:Contents.Delete": "İçerik Silme", + "Permission:Contents.Update": "İçerik Güncelleme", "PickYourReaction": "Tepkinizi seçin", "RatingUndoMessage": "Oylamanız geri alınacak.", "Reply": "Cevapla", From c6ca4b3c98ed9e5af45c6aba1bccd713b6df28d5 Mon Sep 17 00:00:00 2001 From: enisn Date: Thu, 31 Dec 2020 14:30:17 +0300 Subject: [PATCH 02/32] CmsKit - Add application layer of Content --- .../CmsKit/Admin/Contents/ContentCreateDto.cs | 21 +++++++++++ .../Volo/CmsKit/Admin/Contents/ContentDto.cs | 1 + .../Admin/Contents/ContentGetListInput.cs | 9 +++++ .../CmsKit/Admin/Contents/ContentUpdateDto.cs | 13 +++++++ .../Admin/Contents/IContentAdminAppService.cs | 16 +++++++++ .../Admin/Contents/ContentAdminAppService.cs | 36 +++++++++++++++++++ .../Volo/CmsKit/Contents/ContentConsts.cs | 2 +- 7 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentCreateDto.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentGetListInput.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentUpdateDto.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/IContentAdminAppService.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentCreateDto.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentCreateDto.cs new file mode 100644 index 0000000000..6729203c8e --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentCreateDto.cs @@ -0,0 +1,21 @@ +using System.ComponentModel.DataAnnotations; +using Volo.Abp.Validation; +using Volo.CmsKit.Contents; + +namespace Volo.CmsKit.Admin.Contents +{ + public class ContentCreateDto + { + [Required] + [DynamicMaxLength(typeof(ContentConsts), nameof(ContentConsts.MaxEntityTypeLength))] + public string EntityType { get; set; } + + [Required] + [DynamicMaxLength(typeof(ContentConsts), nameof(ContentConsts.MaxEntityIdLength))] + public string EntityId { get; set; } + + [Required] + [DynamicMaxLength(typeof(ContentConsts), nameof(ContentConsts.MaxValueLength))] + public string Value { get; set; } + } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentDto.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentDto.cs index aa7a4650b1..d58ba1c9a3 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentDto.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentDto.cs @@ -5,6 +5,7 @@ namespace Volo.CmsKit.Admin.Contents { public class ContentDto : EntityDto { + public string EntityType { get; set; } public string Value { get; set; } } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentGetListInput.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentGetListInput.cs new file mode 100644 index 0000000000..3523b40496 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentGetListInput.cs @@ -0,0 +1,9 @@ +using Volo.Abp.Application.Dtos; + +namespace Volo.CmsKit.Admin.Contents +{ + public class ContentGetListInput : PagedAndSortedResultRequestDto + { + public string Filter { get; set; } + } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentUpdateDto.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentUpdateDto.cs new file mode 100644 index 0000000000..1164b4eecc --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentUpdateDto.cs @@ -0,0 +1,13 @@ +using System.ComponentModel.DataAnnotations; +using Volo.Abp.Validation; +using Volo.CmsKit.Contents; + +namespace Volo.CmsKit.Admin.Contents +{ + public class ContentUpdateDto + { + [Required] + [DynamicMaxLength(typeof(ContentConsts), nameof(ContentConsts.MaxValueLength))] + public string Value { get; set; } + } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/IContentAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/IContentAdminAppService.cs new file mode 100644 index 0000000000..02b25aa16d --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/IContentAdminAppService.cs @@ -0,0 +1,16 @@ +using System; +using Volo.Abp.Application.Services; +using Volo.CmsKit.Admin.Contents; + +namespace Volo.CmsKit.Admin.Contents +{ + public interface IContentAdminAppService + : ICrudAppService< + ContentDto, + Guid, + ContentGetListInput, + ContentCreateDto, + ContentUpdateDto> + { + } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs new file mode 100644 index 0000000000..9c6496770c --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs @@ -0,0 +1,36 @@ +using Microsoft.AspNetCore.Authorization; +using System; +using Volo.Abp.Application.Services; +using Volo.Abp.Domain.Repositories; +using Volo.CmsKit.Contents; +using Volo.CmsKit.Permissions; + +namespace Volo.CmsKit.Admin.Contents +{ + [Authorize(CmsKitAdminPermissions.Contents.Default)] + public class ContentAdminAppService : + CrudAppService< + Content, + ContentDto, + Guid, + ContentGetListInput, + ContentCreateDto, + ContentUpdateDto + >, IContentAdminAppService + { + public ContentAdminAppService( + IRepository repository, + IContentRepository contentRepository) : base(repository) + { + ContentRepository = contentRepository; + + GetListPolicyName = CmsKitAdminPermissions.Contents.Default; + GetPolicyName = CmsKitAdminPermissions.Contents.Default; + CreatePolicyName = CmsKitAdminPermissions.Contents.Create; + UpdatePolicyName = CmsKitAdminPermissions.Contents.Update; + DeletePolicyName = CmsKitAdminPermissions.Contents.Delete; + } + + protected IContentRepository ContentRepository { get; } + } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Contents/ContentConsts.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Contents/ContentConsts.cs index 758a29e81f..d6d69a6a39 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Contents/ContentConsts.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Contents/ContentConsts.cs @@ -10,6 +10,6 @@ namespace Volo.CmsKit.Contents public static int MaxEntityIdLength { get; set; } = CmsEntityConsts.MaxEntityIdLength; // TODO: consider - public static int MaxValueLength = int.MaxValue; + public static int MaxValueLength { get; set; } = int.MaxValue; } } \ No newline at end of file From af22522028048b4f027d61a7ce40b68ce1f31a1a Mon Sep 17 00:00:00 2001 From: enisn Date: Thu, 31 Dec 2020 14:30:36 +0300 Subject: [PATCH 03/32] CmsKit - Add ContentController --- .../Admin/Contents/ContentController.cs | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs new file mode 100644 index 0000000000..7fc2f4596e --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs @@ -0,0 +1,50 @@ +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.CmsKit.Admin.Contents; + +namespace Volo.CmsKit.Admin.HttpApi.Volo.CmsKit.Admin.Contents +{ + [RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] + [Area("cms-kit")] + [Route("api/cms-kit-admin/contents")] + public class ContentController : CmsKitAdminController, IContentAdminAppService + { + public ContentController(IContentAdminAppService contentAdminAppService) + { + ContentAdminAppService = contentAdminAppService; + } + + protected IContentAdminAppService ContentAdminAppService { get; } + + public Task CreateAsync(ContentCreateDto input) + { + return ContentAdminAppService.CreateAsync(input); + } + + public Task DeleteAsync(Guid id) + { + return ContentAdminAppService.DeleteAsync(id); + } + + public Task GetAsync(Guid id) + { + return ContentAdminAppService.GetAsync(id); + } + + public Task> GetListAsync(ContentGetListInput input) + { + return ContentAdminAppService.GetListAsync(input); + } + + public Task UpdateAsync(Guid id, ContentUpdateDto input) + { + return ContentAdminAppService.UpdateAsync(id, input); + } + } +} From 9616ada96074d210f89042351a2ede05b00ad218 Mon Sep 17 00:00:00 2001 From: enisn Date: Thu, 31 Dec 2020 15:36:46 +0300 Subject: [PATCH 04/32] CmsKit - Add missing Content Permissions --- .../CmsKitAdminPermissionDefinitionProvider.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Permissions/CmsKitAdminPermissionDefinitionProvider.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Permissions/CmsKitAdminPermissionDefinitionProvider.cs index 2cb6a53b58..e15daca848 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Permissions/CmsKitAdminPermissionDefinitionProvider.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Permissions/CmsKitAdminPermissionDefinitionProvider.cs @@ -1,5 +1,7 @@ using Volo.Abp.Authorization.Permissions; +using Volo.Abp.GlobalFeatures; using Volo.Abp.Localization; +using Volo.CmsKit.GlobalFeatures; using Volo.CmsKit.Localization; namespace Volo.CmsKit.Permissions @@ -15,6 +17,14 @@ namespace Volo.CmsKit.Permissions .AddChild(CmsKitAdminPermissions.Tags.Create, L("Permission:TagManagement.Create")) .AddChild(CmsKitAdminPermissions.Tags.Update, L("Permission:TagManagement.Update")) .AddChild(CmsKitAdminPermissions.Tags.Delete, L("Permission:TagManagement.Delete")); + + if (GlobalFeatureManager.Instance.IsEnabled()) + { + var contentGroup = cmsGroup.AddPermission(CmsKitAdminPermissions.Contents.Default, L("Permission:Contents")); + contentGroup.AddChild(CmsKitAdminPermissions.Contents.Create, L("Permission:Contents.Create")); + contentGroup.AddChild(CmsKitAdminPermissions.Contents.Update, L("Permission:Contents.Update")); + contentGroup.AddChild(CmsKitAdminPermissions.Contents.Delete, L("Permission:Contents.Delete")); + } } private static LocalizableString L(string name) From 538c368a082cbd6fc58fd3921ca9754c085020eb Mon Sep 17 00:00:00 2001 From: enisn Date: Thu, 31 Dec 2020 15:37:16 +0300 Subject: [PATCH 05/32] CmsKit - Refactor ContentController --- .../Volo/CmsKit/Admin/Contents/ContentController.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs index 7fc2f4596e..79cf2e0a8f 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs @@ -1,8 +1,5 @@ using Microsoft.AspNetCore.Mvc; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Application.Dtos; From 01d22dacaf10a669e7ec6abf30450304c0eb5dde Mon Sep 17 00:00:00 2001 From: enisn Date: Thu, 31 Dec 2020 15:42:52 +0300 Subject: [PATCH 06/32] CmsKit - Add missing Authorize attributes to ContentController --- .../Volo/CmsKit/Admin/Contents/ContentController.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs index 79cf2e0a8f..e3733d6fdb 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs @@ -1,12 +1,15 @@ -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; using System; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Application.Dtos; using Volo.CmsKit.Admin.Contents; +using Volo.CmsKit.Permissions; namespace Volo.CmsKit.Admin.HttpApi.Volo.CmsKit.Admin.Contents { + [Authorize(CmsKitAdminPermissions.Contents.Delete)] [RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] [Area("cms-kit")] [Route("api/cms-kit-admin/contents")] @@ -19,26 +22,31 @@ namespace Volo.CmsKit.Admin.HttpApi.Volo.CmsKit.Admin.Contents protected IContentAdminAppService ContentAdminAppService { get; } + [Authorize(CmsKitAdminPermissions.Contents.Create)] public Task CreateAsync(ContentCreateDto input) { return ContentAdminAppService.CreateAsync(input); } + [Authorize(CmsKitAdminPermissions.Contents.Delete)] public Task DeleteAsync(Guid id) { return ContentAdminAppService.DeleteAsync(id); } + [Authorize(CmsKitAdminPermissions.Contents.Default)] public Task GetAsync(Guid id) { return ContentAdminAppService.GetAsync(id); } + [Authorize(CmsKitAdminPermissions.Contents.Default)] public Task> GetListAsync(ContentGetListInput input) { return ContentAdminAppService.GetListAsync(input); } + [Authorize(CmsKitAdminPermissions.Contents.Update)] public Task UpdateAsync(Guid id, ContentUpdateDto input) { return ContentAdminAppService.UpdateAsync(id, input); From e7b11789788c07101b0dce5905a25da3b263af39 Mon Sep 17 00:00:00 2001 From: enisn Date: Thu, 31 Dec 2020 16:12:49 +0300 Subject: [PATCH 07/32] CmsKit - Fix wrong permission for ContentController --- .../Volo/CmsKit/Admin/Contents/ContentController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs index e3733d6fdb..38b702a6a0 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs @@ -9,7 +9,7 @@ using Volo.CmsKit.Permissions; namespace Volo.CmsKit.Admin.HttpApi.Volo.CmsKit.Admin.Contents { - [Authorize(CmsKitAdminPermissions.Contents.Delete)] + [Authorize(CmsKitAdminPermissions.Contents.Default)] [RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] [Area("cms-kit")] [Route("api/cms-kit-admin/contents")] From c9d7d9f3407493fb15e66c694ad55126b8ceb5db Mon Sep 17 00:00:00 2001 From: enisn Date: Thu, 31 Dec 2020 16:17:31 +0300 Subject: [PATCH 08/32] CmsKit - Fix namespace for ContentController --- .../Volo/CmsKit/Admin/Contents/ContentController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs index 38b702a6a0..a95646cb9d 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs @@ -7,7 +7,7 @@ using Volo.Abp.Application.Dtos; using Volo.CmsKit.Admin.Contents; using Volo.CmsKit.Permissions; -namespace Volo.CmsKit.Admin.HttpApi.Volo.CmsKit.Admin.Contents +namespace Volo.CmsKit.Admin.Contents { [Authorize(CmsKitAdminPermissions.Contents.Default)] [RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] From 8a3b8c01bdb76124728851ae6c5b40471bd16a04 Mon Sep 17 00:00:00 2001 From: enisn Date: Thu, 31 Dec 2020 16:31:42 +0300 Subject: [PATCH 09/32] CmsKit - Add HttpMethods to ContentController --- .../Volo/CmsKit/Admin/Contents/ContentController.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs index a95646cb9d..5842f73007 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs @@ -22,30 +22,35 @@ namespace Volo.CmsKit.Admin.Contents protected IContentAdminAppService ContentAdminAppService { get; } + [HttpPost] [Authorize(CmsKitAdminPermissions.Contents.Create)] public Task CreateAsync(ContentCreateDto input) { return ContentAdminAppService.CreateAsync(input); } + [HttpDelete("{id}"] [Authorize(CmsKitAdminPermissions.Contents.Delete)] public Task DeleteAsync(Guid id) { return ContentAdminAppService.DeleteAsync(id); } + [HttpGet("{id}"] [Authorize(CmsKitAdminPermissions.Contents.Default)] public Task GetAsync(Guid id) { return ContentAdminAppService.GetAsync(id); } + [HttpGet] [Authorize(CmsKitAdminPermissions.Contents.Default)] public Task> GetListAsync(ContentGetListInput input) { return ContentAdminAppService.GetListAsync(input); } + [HttpPut] [Authorize(CmsKitAdminPermissions.Contents.Update)] public Task UpdateAsync(Guid id, ContentUpdateDto input) { From 83525591677bd9edf066f2fee9ec4a1308909842 Mon Sep 17 00:00:00 2001 From: enisn Date: Thu, 31 Dec 2020 16:32:05 +0300 Subject: [PATCH 10/32] CmsKit - Add HttpMethods to ContentController --- .../Volo/CmsKit/Admin/Contents/ContentController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs index 5842f73007..f64068222a 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs @@ -29,14 +29,14 @@ namespace Volo.CmsKit.Admin.Contents return ContentAdminAppService.CreateAsync(input); } - [HttpDelete("{id}"] + [HttpDelete("{id}")] [Authorize(CmsKitAdminPermissions.Contents.Delete)] public Task DeleteAsync(Guid id) { return ContentAdminAppService.DeleteAsync(id); } - [HttpGet("{id}"] + [HttpGet("{id}")] [Authorize(CmsKitAdminPermissions.Contents.Default)] public Task GetAsync(Guid id) { From 187d89a64fa587979b03cedd0cf89dfa276bf03f Mon Sep 17 00:00:00 2001 From: enisn Date: Thu, 31 Dec 2020 16:44:43 +0300 Subject: [PATCH 11/32] CmsKit - Remove Filter from ContentGetListInput --- .../Volo/CmsKit/Admin/Contents/ContentGetListInput.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentGetListInput.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentGetListInput.cs index 3523b40496..73df63558b 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentGetListInput.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentGetListInput.cs @@ -4,6 +4,5 @@ namespace Volo.CmsKit.Admin.Contents { public class ContentGetListInput : PagedAndSortedResultRequestDto { - public string Filter { get; set; } } } From b494f1ea322314866ccc42ba40f8c07a9eea40f0 Mon Sep 17 00:00:00 2001 From: enisn Date: Thu, 31 Dec 2020 16:56:57 +0300 Subject: [PATCH 12/32] CmsKit - Add missiong Content mappings --- .../CmsKit/Admin/CmsKitAdminApplicationAutoMapperProfile.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/CmsKitAdminApplicationAutoMapperProfile.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/CmsKitAdminApplicationAutoMapperProfile.cs index e1062daa92..4b7a6eb58f 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/CmsKitAdminApplicationAutoMapperProfile.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/CmsKitAdminApplicationAutoMapperProfile.cs @@ -1,5 +1,7 @@ using AutoMapper; +using Volo.CmsKit.Admin.Contents; using Volo.CmsKit.Admin.Pages; +using Volo.CmsKit.Contents; using Volo.CmsKit.Pages; namespace Volo.CmsKit.Admin @@ -9,6 +11,10 @@ namespace Volo.CmsKit.Admin public CmsKitAdminApplicationAutoMapperProfile() { CreateMap(); + + CreateMap(MemberList.Destination); + CreateMap(MemberList.Source); + CreateMap(MemberList.Source); } } } From 9d1d86a3b305e46a8ea2709e038b25db3be8abab Mon Sep 17 00:00:00 2001 From: enisn Date: Thu, 31 Dec 2020 18:05:08 +0300 Subject: [PATCH 13/32] CmsKit - Update tests for Content --- .../Contents/ContentAdminAppService_Tests.cs | 88 +++++++++++++++++++ .../CmsKitDataSeedContributor.cs | 15 ++-- .../Volo.CmsKit.TestBase/CmsKitTestData.cs | 34 +++---- .../Contents/ContentRepository_Tests.cs | 2 +- 4 files changed, 116 insertions(+), 23 deletions(-) create mode 100644 modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs new file mode 100644 index 0000000000..b7d2d4d80d --- /dev/null +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs @@ -0,0 +1,88 @@ +using Microsoft.Extensions.DependencyInjection; +using NSubstitute; +using Shouldly; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Domain.Entities; +using Volo.Abp.Users; +using Volo.CmsKit.Admin.Contents; +using Xunit; + +namespace Volo.CmsKit.Contents +{ + public class ContentAdminAppService_Tests : CmsKitApplicationTestBase + { + private ICurrentUser _currentUser; + private readonly CmsKitTestData _data; + private readonly IContentAdminAppService _service; + public ContentAdminAppService_Tests() + { + _data = GetRequiredService(); + _service = GetRequiredService(); + } + + protected override void AfterAddApplication(IServiceCollection services) + { + _currentUser = Substitute.For(); + services.AddSingleton(_currentUser); + } + + [Fact] + public async Task ShouldGetListAsync() + { + var result = await _service.GetListAsync(new ContentGetListInput()); + + result.ShouldNotBeNull(); + result.Items.ShouldNotBeEmpty(); + result.Items.Count.ShouldBe(4); + } + + [Fact] + public async Task ShouldGetAsync() + { + var result = await _service.GetAsync(_data.Content_1_Id); + + result.ShouldNotBeNull(); + } + + [Fact] + public async Task ShouldCreateAsync() + { + var created = await _service.CreateAsync(new ContentCreateDto + { + EntityId = "test_case_id", + EntityType = "test_case_type", + Value = "Some long content" + }); + + created.ShouldNotBeNull(); + } + + [Fact] + public async Task ShouldUpdateAsync() + { + string newValue = "Newly created fresh value"; + var updateDto = new ContentUpdateDto + { + Value = newValue + }; + + await _service.UpdateAsync(_data.Content_1_Id, updateDto); + + var content = await _service.GetAsync(_data.Content_1_Id); + content.ShouldNotBeNull(); + content.Value.ShouldBe(newValue); + } + + [Fact] + public async Task ShouldDeleteAsync() + { + await _service.DeleteAsync(_data.Content_2_Id); + + await Should.ThrowAsync(async () => await _service.GetAsync(_data.Content_2_Id)); + } + } +} diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs index b0f820a4f2..442a86c0b9 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using System.Threading.Tasks; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; @@ -202,16 +203,16 @@ namespace Volo.CmsKit private async Task SeedContentsAsync() { var content1 = new Content( - _guidGenerator.Create(), - _cmsKitTestData.Content_1_EntityType, _cmsKitTestData.Content_1_Id, + _cmsKitTestData.Content_1_EntityType, + _cmsKitTestData.Content_1_EntityId, _cmsKitTestData.Content_1 ); var content2 = new Content( - _guidGenerator.Create(), - _cmsKitTestData.Content_2_EntityType, _cmsKitTestData.Content_2_Id, + _cmsKitTestData.Content_2_EntityType, + _cmsKitTestData.Content_2_EntityId, _cmsKitTestData.Content_2 ); @@ -225,14 +226,14 @@ namespace Volo.CmsKit { var tagEntity = await _tagManager.InsertAsync(_guidGenerator.Create(), _cmsKitTestData.Content_1_EntityType, tag); - await _entityTagRepository.InsertAsync(new EntityTag(tagEntity.Id, _cmsKitTestData.Content_1_Id)); + await _entityTagRepository.InsertAsync(new EntityTag(tagEntity.Id, _cmsKitTestData.Content_1_EntityId)); } foreach (var tag in _cmsKitTestData.Content_2_Tags) { var tagEntity = await _tagManager.InsertAsync(_guidGenerator.Create(), _cmsKitTestData.Content_2_EntityType, tag); - await _entityTagRepository.InsertAsync(new EntityTag(tagEntity.Id, _cmsKitTestData.Content_2_Id)); + await _entityTagRepository.InsertAsync(new EntityTag(tagEntity.Id, _cmsKitTestData.Content_2_EntityId)); } } diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs index 11aa185ddd..7433759f40 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs @@ -21,39 +21,43 @@ namespace Volo.CmsKit public string EntityId2 { get; } = "2"; public string Content_1_EntityType { get; } = "Lyrics"; - + public string Content_1 { get; } = "First things first\nI'ma say all the words inside my head\nI'm fired up and tired of the way that things have been, oh-ooh\nThe way that things have been, oh-ooh"; - public string Content_1_Id { get; } = "1"; + public Guid Content_1_Id { get; } = Guid.NewGuid(); + + public string Content_1_EntityId { get; } = "1"; + + public string[] Content_1_Tags => new string[] { "Imagine Dragons", "Music" }; - public string[] Content_1_Tags => new string[] {"Imagine Dragons", "Music"}; - public string Content_2_EntityType { get; } = "LyricsAlso"; - + public string Content_2 { get; } = "Second thing second\nDon't you tell me what you think that I could be\nI'm the one at the sail, I'm the master of my sea, oh-ooh\nThe master of my sea, oh-ooh"; - - public string Content_2_Id { get; } = "2"; - - public string[] Content_2_Tags => new string[] {"Imagine Dragons", "Music", "Most Loved Part"}; + + public Guid Content_2_Id { get; } = Guid.NewGuid(); + + public string Content_2_EntityId { get; } = "2"; + + public string[] Content_2_Tags => new string[] { "Imagine Dragons", "Music", "Most Loved Part" }; public string Page_1_Title { get; } = "Imagine Dragons - Believer Lyrics"; public string Page_1_Url { get; } = "imagine-dragons-believer-lyrics"; - + public string Page_1_Description { get; } = "You can get the lyrics of the music."; - + public Guid Page_1_Id { get; } = Guid.NewGuid(); public string Page_1_Content => Content_1; - + public string Page_2_Title { get; } = "Imagine Dragons - Believer Lyrics (Page 2)"; public string Page_2_Url { get; } = "imagine-dragons-believer-lyrics-2"; - + public string Page_2_Description { get; } = "You can get the lyrics of the music."; - + public Guid Page_2_Id { get; } = Guid.NewGuid(); - + public string Page_2_Content => Content_2; } } diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/Contents/ContentRepository_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/Contents/ContentRepository_Tests.cs index c92383694e..c5b166551e 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/Contents/ContentRepository_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/Contents/ContentRepository_Tests.cs @@ -47,7 +47,7 @@ namespace Volo.CmsKit.Contents public async Task ShouldFindAsync() { var content = - await _contentRepository.FindAsync(_cmsKitTestData.Content_1_EntityType, _cmsKitTestData.Content_1_Id); + await _contentRepository.FindAsync(_cmsKitTestData.Content_1_EntityType, _cmsKitTestData.Content_1_EntityId); content.ShouldNotBeNull(); } From 6079da52900e4dbe5abbbc614ed575a9fc4bfcba Mon Sep 17 00:00:00 2001 From: enisn Date: Mon, 4 Jan 2021 12:47:42 +0300 Subject: [PATCH 14/32] CmsKit - Temporary solution for Content deletion --- .../CmsKitDbContextModelCreatingExtensions.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs index 8d32de7958..ebcb5dc22e 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs @@ -100,9 +100,11 @@ namespace Volo.CmsKit.EntityFrameworkCore builder.Entity(b => { b.ToTable(options.TablePrefix + "Contents", options.Schema); - + b.ConfigureByConvention(); - + + b.HasQueryFilter(x => !x.IsDeleted); // TODO: Find out why default filter doesn't work. + b.Property(x => x.EntityType).IsRequired().HasMaxLength(ContentConsts.MaxEntityTypeLength); b.Property(x => x.EntityId).IsRequired().HasMaxLength(ContentConsts.MaxEntityIdLength); b.Property(x => x.Value).IsRequired().HasMaxLength(ContentConsts.MaxValueLength); From ce852b4f24bce250a56e61e6b3c8fdc735662090 Mon Sep 17 00:00:00 2001 From: enisn Date: Tue, 5 Jan 2021 09:54:15 +0300 Subject: [PATCH 15/32] CmsKit - Refactoring on Content Services --- .../Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs | 4 ++-- .../Volo/CmsKit/Admin/Contents/ContentController.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs index 9c6496770c..9cd6df6bc7 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs @@ -18,6 +18,8 @@ namespace Volo.CmsKit.Admin.Contents ContentUpdateDto >, IContentAdminAppService { + protected IContentRepository ContentRepository { get; } + public ContentAdminAppService( IRepository repository, IContentRepository contentRepository) : base(repository) @@ -30,7 +32,5 @@ namespace Volo.CmsKit.Admin.Contents UpdatePolicyName = CmsKitAdminPermissions.Contents.Update; DeletePolicyName = CmsKitAdminPermissions.Contents.Delete; } - - protected IContentRepository ContentRepository { get; } } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs index f64068222a..2dec4b60d5 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs @@ -15,13 +15,13 @@ namespace Volo.CmsKit.Admin.Contents [Route("api/cms-kit-admin/contents")] public class ContentController : CmsKitAdminController, IContentAdminAppService { + protected IContentAdminAppService ContentAdminAppService { get; } + public ContentController(IContentAdminAppService contentAdminAppService) { ContentAdminAppService = contentAdminAppService; } - protected IContentAdminAppService ContentAdminAppService { get; } - [HttpPost] [Authorize(CmsKitAdminPermissions.Contents.Create)] public Task CreateAsync(ContentCreateDto input) From 42eb25c3e8bcb20860799f94861bda6f0aadde7b Mon Sep 17 00:00:00 2001 From: enisn Date: Tue, 5 Jan 2021 09:54:35 +0300 Subject: [PATCH 16/32] CmsKit - Add new tests to Content --- .../Contents/ContentAdminAppService_Tests.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs index b7d2d4d80d..a33f61cedc 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs @@ -61,6 +61,29 @@ namespace Volo.CmsKit.Contents created.ShouldNotBeNull(); } + [Fact] + public async Task ShouldNotCreateWithSameParametersAsync() + { + var entityTtype = "My.Awesome.Book"; + var entityId = "1"; + + await _service.CreateAsync(new ContentCreateDto + { + EntityId = entityId, + EntityType = entityTtype, + Value = "Some long content" + }); + + await Should.ThrowAsync(async () => + await _service.CreateAsync(new ContentCreateDto + { + EntityId = entityId, + EntityType = entityTtype, + Value = "Yet another long content" + }) + ); + } + [Fact] public async Task ShouldUpdateAsync() { @@ -84,5 +107,21 @@ namespace Volo.CmsKit.Contents await Should.ThrowAsync(async () => await _service.GetAsync(_data.Content_2_Id)); } + + [Fact] + public async Task ShouldThrowEntityNotFoundExceptionWhileDeletingNonExistingAsync() + { + await Should.ThrowAsync(async () => + await _service.DeleteAsync(Guid.NewGuid())); // Freshly generated non-existing id. + } + + [Fact] + public async Task ShouldThrowEntityNotFoundExceptionWhileDeletingAlreadyDeletedAsync() + { + await _service.DeleteAsync(_data.Content_2_Id); + + Should.ThrowAsync(async () => + await _service.DeleteAsync(_data.Content_2_Id)); + } } } From 3a58a459e2604f06ca8ca7a851f472df6a7a30d9 Mon Sep 17 00:00:00 2001 From: enisn Date: Tue, 5 Jan 2021 10:00:17 +0300 Subject: [PATCH 17/32] CmsKit - Update Content Tests --- .../Contents/ContentAdminAppService_Tests.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs index a33f61cedc..887d50d555 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs @@ -51,14 +51,23 @@ namespace Volo.CmsKit.Contents [Fact] public async Task ShouldCreateAsync() { + var entityId = "1-2-3"; + var entityType = "My.Awesome.Blog"; + var value = "Some long content"; + var created = await _service.CreateAsync(new ContentCreateDto { - EntityId = "test_case_id", - EntityType = "test_case_type", - Value = "Some long content" + EntityId = entityId, + EntityType = entityType, + Value = value }); - created.ShouldNotBeNull(); + created.Id.ShouldNotBe(Guid.Empty); + + var content = await _service.GetAsync(created.Id); + + content.ShouldNotBeNull(); + content.EntityType.ShouldBe(entityType); } [Fact] From 03736463c787734a2412bd7d19d02c50d01b10f4 Mon Sep 17 00:00:00 2001 From: enisn Date: Tue, 5 Jan 2021 10:24:29 +0300 Subject: [PATCH 18/32] CmsKit - Remove unnecessary test from Content --- .../Contents/ContentAdminAppService_Tests.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs index 887d50d555..39f6251de7 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs @@ -117,13 +117,6 @@ namespace Volo.CmsKit.Contents await Should.ThrowAsync(async () => await _service.GetAsync(_data.Content_2_Id)); } - [Fact] - public async Task ShouldThrowEntityNotFoundExceptionWhileDeletingNonExistingAsync() - { - await Should.ThrowAsync(async () => - await _service.DeleteAsync(Guid.NewGuid())); // Freshly generated non-existing id. - } - [Fact] public async Task ShouldThrowEntityNotFoundExceptionWhileDeletingAlreadyDeletedAsync() { From 4c18d77f80730193ea172d63c3e066b03513a0af Mon Sep 17 00:00:00 2001 From: enisn Date: Tue, 5 Jan 2021 10:26:33 +0300 Subject: [PATCH 19/32] CmsKit - Update Content tests --- .../Contents/ContentAdminAppService_Tests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs index 39f6251de7..7d3e7b5fd3 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs @@ -118,11 +118,11 @@ namespace Volo.CmsKit.Contents } [Fact] - public async Task ShouldThrowEntityNotFoundExceptionWhileDeletingAlreadyDeletedAsync() + public async Task ShouldNotThrowEntityNotFoundExceptionWhileDeletingAlreadyDeletedAsync() { await _service.DeleteAsync(_data.Content_2_Id); - Should.ThrowAsync(async () => + await Should.NotThrowAsync(async () => await _service.DeleteAsync(_data.Content_2_Id)); } } From 15a5273f5e7ccdc1ecb0cef4632d6b1dd9ddb19c Mon Sep 17 00:00:00 2001 From: enisn Date: Tue, 5 Jan 2021 11:30:42 +0300 Subject: [PATCH 20/32] CmsKit - Add Business Logic to Content --- .../Admin/Contents/ContentAdminAppService.cs | 24 ++++++++++++-- .../Volo/CmsKit/CmsKitErrorCodes.cs | 1 + .../Volo/CmsKit/Contents/Content.cs | 4 +-- .../Volo/CmsKit/Contents/ContentManager.cs | 31 +++++++++++++++++++ .../Volo/CmsKit/Contents/IContentManager.cs | 11 +++++++ .../CmsKit/Contents/IContentRepository.cs | 12 ++++++- .../Contents/TagAlreadyExistException.cs | 17 ++++++++++ .../Contents/EfCoreContentRepository.cs | 14 ++++++++- .../Contents/MongoContentRepository.cs | 14 ++++++++- .../Contents/ContentAdminAppService_Tests.cs | 2 +- 10 files changed, 122 insertions(+), 8 deletions(-) create mode 100644 modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/ContentManager.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/IContentManager.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/TagAlreadyExistException.cs diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs index 9cd6df6bc7..f83d77af52 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs @@ -1,14 +1,16 @@ using Microsoft.AspNetCore.Authorization; using System; +using System.Threading.Tasks; using Volo.Abp.Application.Services; using Volo.Abp.Domain.Repositories; using Volo.CmsKit.Contents; +using Volo.CmsKit.Domain.Volo.CmsKit.Contents; using Volo.CmsKit.Permissions; namespace Volo.CmsKit.Admin.Contents { [Authorize(CmsKitAdminPermissions.Contents.Default)] - public class ContentAdminAppService : + public class ContentAdminAppService : CrudAppService< Content, ContentDto, @@ -18,19 +20,37 @@ namespace Volo.CmsKit.Admin.Contents ContentUpdateDto >, IContentAdminAppService { + protected IContentManager ContentManager { get; } protected IContentRepository ContentRepository { get; } public ContentAdminAppService( IRepository repository, + IContentManager contentManager, IContentRepository contentRepository) : base(repository) { - ContentRepository = contentRepository; + ContentManager = contentManager; GetListPolicyName = CmsKitAdminPermissions.Contents.Default; GetPolicyName = CmsKitAdminPermissions.Contents.Default; CreatePolicyName = CmsKitAdminPermissions.Contents.Create; UpdatePolicyName = CmsKitAdminPermissions.Contents.Update; DeletePolicyName = CmsKitAdminPermissions.Contents.Delete; + ContentRepository = contentRepository; + } + + [Authorize(CmsKitAdminPermissions.Contents.Create)] + public override async Task CreateAsync(ContentCreateDto input) + { + var entity = new Content( + GuidGenerator.Create(), + input.EntityType, + input.EntityId, + input.Value, + CurrentTenant?.Id); + + await ContentManager.InsertAsync(entity); + + return MapToGetListOutputDto(entity); } } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/CmsKitErrorCodes.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/CmsKitErrorCodes.cs index 76ba39c3f2..4b57a5a52e 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/CmsKitErrorCodes.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/CmsKitErrorCodes.cs @@ -3,5 +3,6 @@ public static class CmsKitErrorCodes { public const string TagAlreadyExist = "CmsKit:0001"; + public const string ContentAlreadyExist = "CmsKit:0002"; } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/Content.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/Content.cs index 6f4175daad..e2d4a2a4ac 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/Content.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/Content.cs @@ -8,9 +8,9 @@ namespace Volo.CmsKit.Contents { public class Content : FullAuditedAggregateRoot, IMultiTenant { - public virtual Guid? TenantId { get; set; } + public virtual Guid? TenantId { get; protected set; } - public virtual string EntityType { get; set; } + public virtual string EntityType { get; protected set; } public virtual string EntityId { get; set; } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/ContentManager.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/ContentManager.cs new file mode 100644 index 0000000000..33c4889245 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/ContentManager.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Volo.Abp.Domain.Services; +using Volo.CmsKit.Contents; + +namespace Volo.CmsKit.Domain.Volo.CmsKit.Contents +{ + public class ContentManager : DomainService, IContentManager + { + protected IContentRepository ContentRepository { get; } + public ContentManager(IContentRepository contentRepository) + { + ContentRepository = contentRepository; + } + + + public async Task InsertAsync(Content content, CancellationToken cancellationToken = default) + { + if (await ContentRepository.ExistAsync(content.EntityType, content.EntityId, content.TenantId, cancellationToken)) + { + throw new ContentAlreadyExistException(content.EntityType, content.EntityId); + } + + return await ContentRepository.InsertAsync(content); + } + } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/IContentManager.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/IContentManager.cs new file mode 100644 index 0000000000..e795e7895c --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/IContentManager.cs @@ -0,0 +1,11 @@ +using System.Threading; +using System.Threading.Tasks; +using Volo.CmsKit.Contents; + +namespace Volo.CmsKit.Domain.Volo.CmsKit.Contents +{ + public interface IContentManager + { + Task InsertAsync(Content content, CancellationToken cancellationToken = default); + } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/IContentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/IContentRepository.cs index acd5ed2a84..70fcf748d2 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/IContentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/IContentRepository.cs @@ -20,6 +20,16 @@ namespace Volo.CmsKit.Contents Guid? tenantId = null, CancellationToken cancellationToken = default); - Task DeleteAsync([NotNull] string entityType, [NotNull] string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default); + Task DeleteAsync( + [NotNull] string entityType, + [NotNull] string entityId, + Guid? tenantId = null, + CancellationToken cancellationToken = default); + + Task ExistAsync( + [NotNull] string entityType, + [NotNull] string entityId, + Guid? tenantId = null, + CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/TagAlreadyExistException.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/TagAlreadyExistException.cs new file mode 100644 index 0000000000..8ea4d4c54a --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/TagAlreadyExistException.cs @@ -0,0 +1,17 @@ +using JetBrains.Annotations; +using System; +using Volo.Abp; + +namespace Volo.CmsKit.Contents +{ + [Serializable] + public class ContentAlreadyExistException : BusinessException + { + public ContentAlreadyExistException([NotNull] string entityType, [NotNull] string entityId) + { + Code = CmsKitErrorCodes.ContentAlreadyExist; + WithData(nameof(Content.EntityType), entityType); + WithData(nameof(Content.EntityId), entityId); + } + } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs index 9293d637f7..66704ffb6d 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs @@ -1,4 +1,6 @@ -using System; +using JetBrains.Annotations; +using Microsoft.EntityFrameworkCore; +using System; using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; @@ -51,5 +53,15 @@ namespace Volo.CmsKit.Contents x.TenantId == tenantId, cancellationToken: GetCancellationToken(cancellationToken)); } + + public async Task ExistAsync([NotNull] string entityType, [NotNull] string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default) + { + var dbSet = await GetDbSetAsync(); + return await dbSet.AnyAsync(x => + x.EntityType == entityType && + x.EntityId == entityId && + x.TenantId == tenantId, + cancellationToken: GetCancellationToken(cancellationToken)); + } } } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs index ccdee8b431..b323d9d686 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs @@ -1,4 +1,6 @@ -using System; +using JetBrains.Annotations; +using MongoDB.Driver.Linq; +using System; using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories.MongoDB; @@ -51,5 +53,15 @@ namespace Volo.CmsKit.MongoDB.Contents x.TenantId == tenantId, cancellationToken: GetCancellationToken(cancellationToken)); } + + public async Task ExistAsync([NotNull] string entityType, [NotNull] string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default) + { + return await (await GetMongoQueryableAsync()).AnyAsync(x => + !x.IsDeleted && + x.EntityType == entityType && + x.EntityId == entityId && + x.TenantId == tenantId, + cancellationToken: GetCancellationToken(cancellationToken)); + } } } \ No newline at end of file diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs index 7d3e7b5fd3..d8c5d62a61 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs @@ -83,7 +83,7 @@ namespace Volo.CmsKit.Contents Value = "Some long content" }); - await Should.ThrowAsync(async () => + await Should.ThrowAsync(async () => await _service.CreateAsync(new ContentCreateDto { EntityId = entityId, From eff17e3cfd50893d090ac522c9248e27ace2e529 Mon Sep 17 00:00:00 2001 From: enisn Date: Tue, 5 Jan 2021 11:35:06 +0300 Subject: [PATCH 21/32] CmsKit - Add missing resources for Content Business Exceptions --- .../Volo/CmsKit/Localization/Resources/en.json | 9 +++++---- .../Volo/CmsKit/Localization/Resources/tr.json | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) 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 a2aee70c49..b1dd404123 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 @@ -1,6 +1,7 @@ { "culture": "en", "texts": { + "CmsKit:0002": "Content already exist!", "CommentAuthorizationExceptionMessage": "Those comments are not allowed for public display.", "Comments": "Comments", "Delete": "Delete", @@ -10,14 +11,14 @@ "LoginToReply": "Login to reply", "MessageDeletionConfirmationMessage": "This comment will be deleted completely.", "Permission:CmsKit": "CmsKit", - "Permission:TagManagement": "Tag Management", - "Permission:TagManagement.Create": "Create Tag", - "Permission:TagManagement.Delete": "Delete Tag", - "Permission:TagManagement.Update": "Update Tag", "Permission:Contents": "Content Management", "Permission:Contents.Create": "Create Content", "Permission:Contents.Delete": "Delete Content", "Permission:Contents.Update": "Update Content", + "Permission:TagManagement": "Tag Management", + "Permission:TagManagement.Create": "Create Tag", + "Permission:TagManagement.Delete": "Delete Tag", + "Permission:TagManagement.Update": "Update Tag", "PickYourReaction": "Pick your reaction", "RatingUndoMessage": "Your rating will be undo.", "Reply": "Reply", diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/tr.json b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/tr.json index 693be35377..4813ae126f 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/tr.json +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/tr.json @@ -1,6 +1,7 @@ { "culture": "tr", "texts": { + "CmsKit:0002": "İçerik zaten mevcut!", "CommentAuthorizationExceptionMessage": "Bu yorumları görebilmek için yetki gerekir.", "Comments": "Yorumlar", "Delete": "Sil", @@ -10,14 +11,14 @@ "LoginToReply": "Cevap vermek için giriş yap", "MessageDeletionConfirmationMessage": "Bu yorum tamamen silinecektir", "Permission:CmsKit": "CmsKit", - "Permission:TagManagement": "Etiket Yönetimi", - "Permission:TagManagement.Create": "Etiket Oluşturma", - "Permission:TagManagement.Delete": "Etiket Silme", - "Permission:TagManagement.Update": "Etiket Güncelleme", "Permission:Contents": "İçerik Yönetimi", "Permission:Contents.Create": "İçerik Oluşturma", "Permission:Contents.Delete": "İçerik Silme", "Permission:Contents.Update": "İçerik Güncelleme", + "Permission:TagManagement": "Etiket Yönetimi", + "Permission:TagManagement.Create": "Etiket Oluşturma", + "Permission:TagManagement.Delete": "Etiket Silme", + "Permission:TagManagement.Update": "Etiket Güncelleme", "PickYourReaction": "Tepkinizi seçin", "RatingUndoMessage": "Oylamanız geri alınacak.", "Reply": "Cevapla", From dcc22cb1ef565c3adede5388c9593dee28021536 Mon Sep 17 00:00:00 2001 From: enisn Date: Tue, 5 Jan 2021 11:37:43 +0300 Subject: [PATCH 22/32] CmsKit - Code-formatting --- .../Volo/CmsKit/Contents/ContentManager.cs | 2 +- .../Volo/CmsKit/Contents/EfCoreContentRepository.cs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/ContentManager.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/ContentManager.cs index 33c4889245..86808df171 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/ContentManager.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/ContentManager.cs @@ -12,12 +12,12 @@ namespace Volo.CmsKit.Domain.Volo.CmsKit.Contents public class ContentManager : DomainService, IContentManager { protected IContentRepository ContentRepository { get; } + public ContentManager(IContentRepository contentRepository) { ContentRepository = contentRepository; } - public async Task InsertAsync(Content content, CancellationToken cancellationToken = default) { if (await ContentRepository.ExistAsync(content.EntityType, content.EntityId, content.TenantId, cancellationToken)) diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs index 66704ffb6d..192bfc1e5d 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs @@ -45,7 +45,11 @@ namespace Volo.CmsKit.Contents ); } - public Task DeleteAsync(string entityType, string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default) + public Task DeleteAsync( + string entityType, + string entityId, + Guid? tenantId = null, + CancellationToken cancellationToken = default) { return DeleteAsync(x => x.EntityType == entityType && @@ -54,7 +58,11 @@ namespace Volo.CmsKit.Contents cancellationToken: GetCancellationToken(cancellationToken)); } - public async Task ExistAsync([NotNull] string entityType, [NotNull] string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default) + public async Task ExistAsync( + [NotNull] string entityType, + [NotNull] string entityId, + Guid? tenantId = null, + CancellationToken cancellationToken = default) { var dbSet = await GetDbSetAsync(); return await dbSet.AnyAsync(x => From 7497587d6ee922a0083fedd7b5dde5d23900a0a7 Mon Sep 17 00:00:00 2001 From: enisn Date: Tue, 5 Jan 2021 11:40:19 +0300 Subject: [PATCH 23/32] CmsKit - Refactor Exists convension in Content --- .../Volo.CmsKit.Domain/Volo/CmsKit/Contents/ContentManager.cs | 2 +- .../Volo/CmsKit/Contents/IContentRepository.cs | 2 +- .../Volo/CmsKit/Contents/EfCoreContentRepository.cs | 2 +- .../Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/ContentManager.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/ContentManager.cs index 86808df171..6eb2521ba2 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/ContentManager.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/ContentManager.cs @@ -20,7 +20,7 @@ namespace Volo.CmsKit.Domain.Volo.CmsKit.Contents public async Task InsertAsync(Content content, CancellationToken cancellationToken = default) { - if (await ContentRepository.ExistAsync(content.EntityType, content.EntityId, content.TenantId, cancellationToken)) + if (await ContentRepository.ExistsAsync(content.EntityType, content.EntityId, content.TenantId, cancellationToken)) { throw new ContentAlreadyExistException(content.EntityType, content.EntityId); } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/IContentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/IContentRepository.cs index 70fcf748d2..3b767b4722 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/IContentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/IContentRepository.cs @@ -26,7 +26,7 @@ namespace Volo.CmsKit.Contents Guid? tenantId = null, CancellationToken cancellationToken = default); - Task ExistAsync( + Task ExistsAsync( [NotNull] string entityType, [NotNull] string entityId, Guid? tenantId = null, diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs index 192bfc1e5d..adbbd73dc8 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs @@ -58,7 +58,7 @@ namespace Volo.CmsKit.Contents cancellationToken: GetCancellationToken(cancellationToken)); } - public async Task ExistAsync( + public async Task ExistsAsync( [NotNull] string entityType, [NotNull] string entityId, Guid? tenantId = null, diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs index b323d9d686..234757384f 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs @@ -54,7 +54,7 @@ namespace Volo.CmsKit.MongoDB.Contents cancellationToken: GetCancellationToken(cancellationToken)); } - public async Task ExistAsync([NotNull] string entityType, [NotNull] string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default) + public async Task ExistsAsync([NotNull] string entityType, [NotNull] string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default) { return await (await GetMongoQueryableAsync()).AnyAsync(x => !x.IsDeleted && From d933603a328278f5454a39ddc1bd73551d68f1ea Mon Sep 17 00:00:00 2001 From: enisn Date: Tue, 5 Jan 2021 11:49:46 +0300 Subject: [PATCH 24/32] CmsKit - Fix typo in Resources --- .../Volo/CmsKit/Localization/Resources/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b1dd404123..beda437f6a 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 @@ -1,7 +1,7 @@ { "culture": "en", "texts": { - "CmsKit:0002": "Content already exist!", + "CmsKit:0002": "Content already exists!", "CommentAuthorizationExceptionMessage": "Those comments are not allowed for public display.", "Comments": "Comments", "Delete": "Delete", From 7dcf5c88e431e917d4902430ddec2b8aa169c1db Mon Sep 17 00:00:00 2001 From: enisn Date: Tue, 5 Jan 2021 14:17:48 +0300 Subject: [PATCH 25/32] CmsKit - Remove custom SoftDelete checks --- .../Admin/Contents/ContentAdminAppService.cs | 1 + .../Contents/EfCoreContentRepository.cs | 2 - .../CmsKitDbContextModelCreatingExtensions.cs | 51 ++++++++++--------- .../Contents/MongoContentRepository.cs | 3 -- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs index f83d77af52..4695339fd7 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs @@ -21,6 +21,7 @@ namespace Volo.CmsKit.Admin.Contents >, IContentAdminAppService { protected IContentManager ContentManager { get; } + protected IContentRepository ContentRepository { get; } public ContentAdminAppService( diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs index adbbd73dc8..884c5e9b01 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs @@ -22,7 +22,6 @@ namespace Volo.CmsKit.Contents CancellationToken cancellationToken = default) { return GetAsync(x => - !x.IsDeleted && x.EntityType == entityType && x.EntityId == entityId && x.TenantId == tenantId, @@ -37,7 +36,6 @@ namespace Volo.CmsKit.Contents CancellationToken cancellationToken = default) { return FindAsync(x => - !x.IsDeleted && x.EntityType == entityType && x.EntityId == entityId && x.TenantId == tenantId, diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs index ebcb5dc22e..3c937a3432 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs @@ -41,8 +41,8 @@ namespace Volo.CmsKit.EntityFrameworkCore b.ConfigureByConvention(); b.ConfigureAbpUser(); - b.HasIndex(x => new {x.TenantId, x.UserName}); - b.HasIndex(x => new {x.TenantId, x.Email}); + b.HasIndex(x => new { x.TenantId, x.UserName }); + b.HasIndex(x => new { x.TenantId, x.Email }); }); } @@ -93,61 +93,62 @@ namespace Volo.CmsKit.EntityFrameworkCore r.Property(x => x.EntityType).IsRequired().HasMaxLength(RatingConsts.MaxEntityTypeLength); r.Property(x => x.EntityId).IsRequired().HasMaxLength(RatingConsts.MaxEntityIdLength); - r.HasIndex(x => new {x.TenantId, x.EntityType, x.EntityId, x.CreatorId}); + r.HasIndex(x => new { x.TenantId, x.EntityType, x.EntityId, x.CreatorId }); }); } - builder.Entity(b => + if (GlobalFeatureManager.Instance.IsEnabled()) { - b.ToTable(options.TablePrefix + "Contents", options.Schema); + builder.Entity(b => + { + b.ToTable(options.TablePrefix + "Contents", options.Schema); - b.ConfigureByConvention(); + b.ConfigureByConvention(); - b.HasQueryFilter(x => !x.IsDeleted); // TODO: Find out why default filter doesn't work. + b.Property(x => x.EntityType).IsRequired().HasMaxLength(ContentConsts.MaxEntityTypeLength); + b.Property(x => x.EntityId).IsRequired().HasMaxLength(ContentConsts.MaxEntityIdLength); + b.Property(x => x.Value).IsRequired().HasMaxLength(ContentConsts.MaxValueLength); + + b.HasIndex(x => new { x.TenantId, x.EntityType, x.EntityId }); + }); + } - b.Property(x => x.EntityType).IsRequired().HasMaxLength(ContentConsts.MaxEntityTypeLength); - b.Property(x => x.EntityId).IsRequired().HasMaxLength(ContentConsts.MaxEntityIdLength); - b.Property(x => x.Value).IsRequired().HasMaxLength(ContentConsts.MaxValueLength); - - b.HasIndex(x => new { x.TenantId, x.EntityType, x.EntityId }); - }); - builder.Entity(b => { b.ToTable(options.TablePrefix + "Tags", options.Schema); - + b.ConfigureByConvention(); - + b.Property(x => x.EntityType).IsRequired().HasMaxLength(TagConsts.MaxEntityTypeLength); b.Property(x => x.Name).IsRequired().HasMaxLength(TagConsts.MaxNameLength); - + b.HasIndex(x => new { x.TenantId, x.Name }); }); - + builder.Entity(b => { b.ToTable(options.TablePrefix + "EntityTags", options.Schema); - + b.ConfigureByConvention(); b.HasKey(x => new { x.EntityId, x.TagId }); - + b.Property(x => x.EntityId).IsRequired(); b.Property(x => x.TagId).IsRequired(); - + b.HasIndex(x => new { x.TenantId, x.EntityId, x.TagId }); }); - + builder.Entity(b => { b.ToTable(options.TablePrefix + "Pages", options.Schema); - + b.ConfigureByConvention(); - + b.Property(x => x.Title).IsRequired().HasMaxLength(PageConsts.MaxTitleLength); b.Property(x => x.Url).IsRequired().HasMaxLength(PageConsts.MaxUrlLength); b.Property(x => x.Description).HasMaxLength(PageConsts.MaxDescriptionLength); - + b.HasIndex(x => new { x.TenantId, x.Url }); }); } diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs index 234757384f..f42b0890e7 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs @@ -22,7 +22,6 @@ namespace Volo.CmsKit.MongoDB.Contents CancellationToken cancellationToken = default) { return GetAsync(x => - !x.IsDeleted && x.EntityType == entityType && x.EntityId == entityId && x.TenantId == tenantId, @@ -37,7 +36,6 @@ namespace Volo.CmsKit.MongoDB.Contents CancellationToken cancellationToken = default) { return FindAsync(x => - !x.IsDeleted && x.EntityType == entityType && x.EntityId == entityId && x.TenantId == tenantId, @@ -57,7 +55,6 @@ namespace Volo.CmsKit.MongoDB.Contents public async Task ExistsAsync([NotNull] string entityType, [NotNull] string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default) { return await (await GetMongoQueryableAsync()).AnyAsync(x => - !x.IsDeleted && x.EntityType == entityType && x.EntityId == entityId && x.TenantId == tenantId, From a735aa5ac7a9fc891490b53a28a5dfa8259dc6ec Mon Sep 17 00:00:00 2001 From: enisn Date: Tue, 5 Jan 2021 15:23:27 +0300 Subject: [PATCH 26/32] CmsKit - Handle SofDelete manually for temporarily --- .../CmsKitDbContextModelCreatingExtensions.cs | 2 ++ .../Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs index 3c937a3432..b61b35a363 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs @@ -105,6 +105,8 @@ namespace Volo.CmsKit.EntityFrameworkCore b.ConfigureByConvention(); + b.HasQueryFilter(x => !x.IsDeleted); // TODO: Find out why default filter doesn't work. + b.Property(x => x.EntityType).IsRequired().HasMaxLength(ContentConsts.MaxEntityTypeLength); b.Property(x => x.EntityId).IsRequired().HasMaxLength(ContentConsts.MaxEntityIdLength); b.Property(x => x.Value).IsRequired().HasMaxLength(ContentConsts.MaxValueLength); diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs index 442a86c0b9..cdc364b172 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs @@ -215,9 +215,20 @@ namespace Volo.CmsKit _cmsKitTestData.Content_2_EntityId, _cmsKitTestData.Content_2 ); + + var content3 = new Content( + Guid.NewGuid(), + "a", + "b", + "Content" + ) + { + IsDeleted = true, + }; await _contentRepository.InsertAsync(content1); await _contentRepository.InsertAsync(content2); + await _contentRepository.InsertAsync(content3); } private async Task SeedTagsAsync() From 74070ecc768c6cec5a3f3ce09613b5f6fd33eae0 Mon Sep 17 00:00:00 2001 From: enisn Date: Tue, 5 Jan 2021 15:23:27 +0300 Subject: [PATCH 27/32] CmsKit - Handle SofDelete manually as temporary solution --- .../CmsKitDbContextModelCreatingExtensions.cs | 2 ++ .../Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs index 3c937a3432..b61b35a363 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs @@ -105,6 +105,8 @@ namespace Volo.CmsKit.EntityFrameworkCore b.ConfigureByConvention(); + b.HasQueryFilter(x => !x.IsDeleted); // TODO: Find out why default filter doesn't work. + b.Property(x => x.EntityType).IsRequired().HasMaxLength(ContentConsts.MaxEntityTypeLength); b.Property(x => x.EntityId).IsRequired().HasMaxLength(ContentConsts.MaxEntityIdLength); b.Property(x => x.Value).IsRequired().HasMaxLength(ContentConsts.MaxValueLength); diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs index 442a86c0b9..cdc364b172 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs @@ -215,9 +215,20 @@ namespace Volo.CmsKit _cmsKitTestData.Content_2_EntityId, _cmsKitTestData.Content_2 ); + + var content3 = new Content( + Guid.NewGuid(), + "a", + "b", + "Content" + ) + { + IsDeleted = true, + }; await _contentRepository.InsertAsync(content1); await _contentRepository.InsertAsync(content2); + await _contentRepository.InsertAsync(content3); } private async Task SeedTagsAsync() From 93e05e25d44da63d0a0acf32b886175548302ee2 Mon Sep 17 00:00:00 2001 From: enisn Date: Tue, 5 Jan 2021 15:28:26 +0300 Subject: [PATCH 28/32] CmsKit - Update CmsKitDataSeedContributor --- .../test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs index cdc364b172..46a552641b 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs @@ -218,8 +218,8 @@ namespace Volo.CmsKit var content3 = new Content( Guid.NewGuid(), - "a", - "b", + "deleted_entity_type", + "deleted_entity_id", "Content" ) { From fa05c14dbcfc4fe8a42b354c00af4efc81f31c68 Mon Sep 17 00:00:00 2001 From: enisn Date: Wed, 6 Jan 2021 12:15:15 +0300 Subject: [PATCH 29/32] CmsKit - Add EntityId to ContentDto --- .../Volo/CmsKit/Admin/Contents/ContentDto.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentDto.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentDto.cs index d58ba1c9a3..69ece26ca4 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentDto.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Contents/ContentDto.cs @@ -6,6 +6,9 @@ namespace Volo.CmsKit.Admin.Contents public class ContentDto : EntityDto { public string EntityType { get; set; } + + public string EntityId { get; set; } + public string Value { get; set; } } } From 23e14c03cdd9c6044cac728fba7d7efef8c74d95 Mon Sep 17 00:00:00 2001 From: enisn Date: Wed, 6 Jan 2021 14:32:37 +0300 Subject: [PATCH 30/32] CmsKit - Refactor on ContentAdminController --- .../{ContentController.cs => ContentAdminController.cs} | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) rename modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/{ContentController.cs => ContentAdminController.cs} (85%) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentAdminController.cs similarity index 85% rename from modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs rename to modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentAdminController.cs index 2dec4b60d5..935606b686 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Contents/ContentAdminController.cs @@ -4,20 +4,23 @@ using System; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Application.Dtos; +using Volo.Abp.GlobalFeatures; using Volo.CmsKit.Admin.Contents; +using Volo.CmsKit.GlobalFeatures; using Volo.CmsKit.Permissions; namespace Volo.CmsKit.Admin.Contents { [Authorize(CmsKitAdminPermissions.Contents.Default)] + [RequiresGlobalFeature(typeof(ContentsFeature))] [RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] [Area("cms-kit")] [Route("api/cms-kit-admin/contents")] - public class ContentController : CmsKitAdminController, IContentAdminAppService + public class ContentAdminController : CmsKitAdminController, IContentAdminAppService { protected IContentAdminAppService ContentAdminAppService { get; } - public ContentController(IContentAdminAppService contentAdminAppService) + public ContentAdminController(IContentAdminAppService contentAdminAppService) { ContentAdminAppService = contentAdminAppService; } From d3c7b5fc9867289a2f2bcc7dcd2b59325cd5aaa0 Mon Sep 17 00:00:00 2001 From: enisn Date: Wed, 6 Jan 2021 14:35:30 +0300 Subject: [PATCH 31/32] CmsKit - Remove custom queryfilter from Content entity --- .../CmsKitDbContextModelCreatingExtensions.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs index b61b35a363..3c937a3432 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs @@ -105,8 +105,6 @@ namespace Volo.CmsKit.EntityFrameworkCore b.ConfigureByConvention(); - b.HasQueryFilter(x => !x.IsDeleted); // TODO: Find out why default filter doesn't work. - b.Property(x => x.EntityType).IsRequired().HasMaxLength(ContentConsts.MaxEntityTypeLength); b.Property(x => x.EntityId).IsRequired().HasMaxLength(ContentConsts.MaxEntityIdLength); b.Property(x => x.Value).IsRequired().HasMaxLength(ContentConsts.MaxValueLength); From 2192f20df593d8612ffff7a9ac9a5f31f4811420 Mon Sep 17 00:00:00 2001 From: Ilkay Ilknur Date: Wed, 6 Jan 2021 15:39:17 +0300 Subject: [PATCH 32/32] fix build break caused by conflict resolving. --- .../CmsKitDbContextModelCreatingExtensions.cs | 71 ++++++++++--------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs index 6a077b4f4d..5de45ed8b8 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs @@ -41,8 +41,8 @@ namespace Volo.CmsKit.EntityFrameworkCore b.ConfigureByConvention(); b.ConfigureAbpUser(); - b.HasIndex(x => new { x.TenantId, x.UserName }); - b.HasIndex(x => new { x.TenantId, x.Email }); + b.HasIndex(x => new {x.TenantId, x.UserName}); + b.HasIndex(x => new {x.TenantId, x.Email}); }); } @@ -58,8 +58,8 @@ namespace Volo.CmsKit.EntityFrameworkCore b.Property(x => x.EntityId).IsRequired().HasMaxLength(UserReactionConsts.MaxEntityIdLength); b.Property(x => x.ReactionName).IsRequired().HasMaxLength(UserReactionConsts.MaxReactionNameLength); - b.HasIndex(x => new { x.TenantId, x.EntityType, x.EntityId, x.ReactionName }); - b.HasIndex(x => new { x.TenantId, x.CreatorId, x.EntityType, x.EntityId, x.ReactionName }); + b.HasIndex(x => new {x.TenantId, x.EntityType, x.EntityId, x.ReactionName}); + b.HasIndex(x => new {x.TenantId, x.CreatorId, x.EntityType, x.EntityId, x.ReactionName}); }); } @@ -76,8 +76,8 @@ namespace Volo.CmsKit.EntityFrameworkCore b.Property(x => x.Text).IsRequired().HasMaxLength(CommentConsts.MaxTextLength); b.Property(x => x.RepliedCommentId); - b.HasIndex(x => new { x.TenantId, x.EntityType, x.EntityId }); - b.HasIndex(x => new { x.TenantId, x.RepliedCommentId }); + b.HasIndex(x => new {x.TenantId, x.EntityType, x.EntityId}); + b.HasIndex(x => new {x.TenantId, x.RepliedCommentId}); }); } @@ -93,7 +93,7 @@ namespace Volo.CmsKit.EntityFrameworkCore r.Property(x => x.EntityType).IsRequired().HasMaxLength(RatingConsts.MaxEntityTypeLength); r.Property(x => x.EntityId).IsRequired().HasMaxLength(RatingConsts.MaxEntityIdLength); - r.HasIndex(x => new { x.TenantId, x.EntityType, x.EntityId, x.CreatorId }); + r.HasIndex(x => new {x.TenantId, x.EntityType, x.EntityId, x.CreatorId}); }); } @@ -109,49 +109,52 @@ namespace Volo.CmsKit.EntityFrameworkCore b.Property(x => x.EntityId).IsRequired().HasMaxLength(ContentConsts.MaxEntityIdLength); b.Property(x => x.Value).IsRequired().HasMaxLength(ContentConsts.MaxValueLength); - b.HasIndex(x => new { x.TenantId, x.EntityType, x.EntityId }); + b.HasIndex(x => new {x.TenantId, x.EntityType, x.EntityId}); }); } - builder.Entity(b => + if (GlobalFeatureManager.Instance.IsEnabled()) { - b.ToTable(options.TablePrefix + "Tags", options.Schema); + builder.Entity(b => + { + b.ToTable(options.TablePrefix + "Tags", options.Schema); - b.ConfigureByConvention(); + b.ConfigureByConvention(); - b.Property(x => x.EntityType).IsRequired().HasMaxLength(TagConsts.MaxEntityTypeLength); - b.Property(x => x.Name).IsRequired().HasMaxLength(TagConsts.MaxNameLength); + b.Property(x => x.EntityType).IsRequired().HasMaxLength(TagConsts.MaxEntityTypeLength); + b.Property(x => x.Name).IsRequired().HasMaxLength(TagConsts.MaxNameLength); - b.HasIndex(x => new { x.TenantId, x.Name }); - }); + b.HasIndex(x => new {x.TenantId, x.Name}); + }); - builder.Entity(b => - { - b.ToTable(options.TablePrefix + "EntityTags", options.Schema); + builder.Entity(b => + { + b.ToTable(options.TablePrefix + "EntityTags", options.Schema); - b.ConfigureByConvention(); + b.ConfigureByConvention(); - b.HasKey(x => new { x.EntityId, x.TagId }); + b.HasKey(x => new {x.EntityId, x.TagId}); - b.Property(x => x.EntityId).IsRequired(); - b.Property(x => x.TagId).IsRequired(); + b.Property(x => x.EntityId).IsRequired(); + b.Property(x => x.TagId).IsRequired(); - b.HasIndex(x => new { x.TenantId, x.EntityId, x.TagId }); - }); + b.HasIndex(x => new {x.TenantId, x.EntityId, x.TagId}); + }); + } - builder.Entity(b => + if (GlobalFeatureManager.Instance.IsEnabled()) { - b.ToTable(options.TablePrefix + "Pages", options.Schema); + builder.Entity(b => + { + b.ToTable(options.TablePrefix + "Pages", options.Schema); - b.ConfigureByConvention(); + b.ConfigureByConvention(); - b.Property(x => x.Title).IsRequired().HasMaxLength(PageConsts.MaxTitleLength); - b.Property(x => x.Url).IsRequired().HasMaxLength(PageConsts.MaxUrlLength); - b.Property(x => x.Description).HasMaxLength(PageConsts.MaxDescriptionLength); + b.Property(x => x.Title).IsRequired().HasMaxLength(PageConsts.MaxTitleLength); + b.Property(x => x.Url).IsRequired().HasMaxLength(PageConsts.MaxUrlLength); + b.Property(x => x.Description).HasMaxLength(PageConsts.MaxDescriptionLength); - b.HasIndex(x => new { x.TenantId, x.Url }); - }); - b.HasIndex(x => new {x.TenantId, x.EntityType, x.EntityId}); + b.HasIndex(x => new {x.TenantId, x.Url}); }); } @@ -201,4 +204,4 @@ namespace Volo.CmsKit.EntityFrameworkCore } } } -} +} \ No newline at end of file