From 8973c6e853ccca8f15849db8ee6a4d8fbfc83572 Mon Sep 17 00:00:00 2001 From: Ilkay Ilknur Date: Tue, 5 Jan 2021 14:52:45 +0300 Subject: [PATCH 1/4] missing attributes added. --- .../Tags/{TagController.cs => TagAdminController.cs} | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) rename modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Tags/{TagController.cs => TagAdminController.cs} (76%) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Tags/TagController.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Tags/TagAdminController.cs similarity index 76% rename from modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Tags/TagController.cs rename to modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Tags/TagAdminController.cs index 11dcc9a846..cc755fa63f 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Tags/TagController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/Tags/TagAdminController.cs @@ -2,18 +2,26 @@ using Microsoft.AspNetCore.Mvc; using System; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Application.Dtos; +using Volo.Abp.GlobalFeatures; using Volo.CmsKit.Admin.Tags; +using Volo.CmsKit.GlobalFeatures; using Volo.CmsKit.Permissions; using Volo.CmsKit.Tags; namespace Volo.CmsKit.Admin.Tags { - public class TagController : CmsKitAdminController, ITagAdminAppService + [RequiresGlobalFeature(typeof(TagsFeature))] + [RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] + [Area("cms-kit")] + [Authorize(CmsKitAdminPermissions.Tags.Default)] + [Route("api/cms-kit-admin/tags")] + public class TagAdminController : CmsKitAdminController, ITagAdminAppService { protected ITagAdminAppService TagAdminAppService { get; } - public TagController(ITagAdminAppService tagAdminAppService) + public TagAdminController(ITagAdminAppService tagAdminAppService) { TagAdminAppService = tagAdminAppService; } From 1153d72ffaaad6882f3c7bfe04be81f60df1e69f Mon Sep 17 00:00:00 2001 From: Ilkay Ilknur Date: Tue, 5 Jan 2021 14:53:44 +0300 Subject: [PATCH 2/4] tag methods refactoring. Renamed controllers. Changed method signatures. --- .../CmsKit/Public/Tags/GetRelatedTagsInput.cs | 13 ------- .../Volo/CmsKit/Public/Tags/ITagAppService.cs | 4 +- .../Volo/CmsKit/Public/Tags/TagAppService.cs | 19 +++------ .../Volo/CmsKit/Public/Tags/TagController.cs | 27 ------------- .../CmsKit/Public/Tags/TagPublicController.cs | 31 +++++++++++++++ .../Components/Tags/TagViewComponent.cs | 6 +-- .../Tags/TagPublicAppService_Tests.cs | 39 ++----------------- 7 files changed, 44 insertions(+), 95 deletions(-) delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Tags/GetRelatedTagsInput.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagController.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagPublicController.cs diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Tags/GetRelatedTagsInput.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Tags/GetRelatedTagsInput.cs deleted file mode 100644 index b8df8ec439..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Tags/GetRelatedTagsInput.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace Volo.CmsKit.Public.Tags -{ - public class GetRelatedTagsInput - { - [Required] - public string EntityType { get; set; } - - [Required] - public string EntityId { get; set; } - } -} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Tags/ITagAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Tags/ITagAppService.cs index 29d786f086..34d54b9006 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Tags/ITagAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Tags/ITagAppService.cs @@ -7,6 +7,6 @@ namespace Volo.CmsKit.Public.Tags { public interface ITagAppService : IApplicationService { - Task> GetAllRelatedTagsAsync(GetRelatedTagsInput input); + Task> GetAllRelatedTagsAsync(string entityType, string entityId); } -} +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Tags/TagAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Tags/TagAppService.cs index 8feaaa0130..593f011b02 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Tags/TagAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Tags/TagAppService.cs @@ -9,28 +9,21 @@ namespace Volo.CmsKit.Public.Tags { public class TagAppService : CmsKitAppServiceBase, ITagAppService { - protected readonly ITagManager TagManager; protected readonly ITagRepository TagRepository; - protected readonly IEntityTagRepository EntityTagRepository; - public TagAppService( - ITagManager tagManager, - ITagRepository tagRepository, - IEntityTagRepository entityTagRepository) + public TagAppService(ITagRepository tagRepository) { - TagManager = tagManager; TagRepository = tagRepository; - EntityTagRepository = entityTagRepository; } - public virtual async Task> GetAllRelatedTagsAsync(GetRelatedTagsInput input) + public virtual async Task> GetAllRelatedTagsAsync(string entityType, string entityId) { var entities = await TagRepository.GetAllRelatedTagsAsync( - input.EntityType, - input.EntityId, - CurrentTenant.Id); + entityType, + entityId, + CurrentTenant.Id); return ObjectMapper.Map, List>(entities); } } -} +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagController.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagController.cs deleted file mode 100644 index 307c5a4247..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagController.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using System.Collections.Generic; -using System.Threading.Tasks; -using Volo.Abp; -using Volo.CmsKit.Tags; - -namespace Volo.CmsKit.Public.Tags -{ - [RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] - [Area("cms-kit")] - [Route("api/cms-kit/tags")] - public class TagController : CmsKitPublicControllerBase, ITagAppService - { - protected readonly ITagAppService TagAppService; - - public TagController(ITagAppService tagAppService) - { - TagAppService = tagAppService; - } - - [HttpGet] - public Task> GetAllRelatedTagsAsync(GetRelatedTagsInput input) - { - return TagAppService.GetAllRelatedTagsAsync(input); - } - } -} diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagPublicController.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagPublicController.cs new file mode 100644 index 0000000000..55041e5c6e --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagPublicController.cs @@ -0,0 +1,31 @@ +using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.GlobalFeatures; +using Volo.CmsKit.GlobalFeatures; +using Volo.CmsKit.Tags; + +namespace Volo.CmsKit.Public.Tags +{ + [RequiresGlobalFeature(typeof(TagsFeature))] + [RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] + [Area("cms-kit")] + [Route("api/cms-kit-public/tags")] + public class TagPublicController : CmsKitPublicControllerBase, ITagAppService + { + protected readonly ITagAppService TagAppService; + + public TagPublicController(ITagAppService tagAppService) + { + TagAppService = tagAppService; + } + + [HttpGet] + [Route("{entityType}/{entityId}")] + public Task> GetAllRelatedTagsAsync(string entityType, string entityId) + { + return TagAppService.GetAllRelatedTagsAsync(entityType, entityId); + } + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Tags/TagViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Tags/TagViewComponent.cs index 44deaad0ed..c40408117a 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Tags/TagViewComponent.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Tags/TagViewComponent.cs @@ -24,11 +24,7 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Tags string entityType, string entityId) { - var tagDtos = await TagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput - { - EntityId = entityId, - EntityType = entityType - }); + var tagDtos = await TagAppService.GetAllRelatedTagsAsync(entityType, entityId); var viewModel = new TagViewModel { diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagPublicAppService_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagPublicAppService_Tests.cs index 6ad1136167..50eefd186b 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagPublicAppService_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagPublicAppService_Tests.cs @@ -2,9 +2,7 @@ using NSubstitute; using Shouldly; using System.Threading.Tasks; -using Volo.Abp.Clients; using Volo.Abp.Users; -using Volo.Abp.Validation; using Volo.CmsKit.Public.Tags; using Xunit; @@ -31,11 +29,8 @@ namespace Volo.CmsKit.Tags [Fact] public async Task GetAllRelatedTagsAsync() { - var list = await _tagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput - { - EntityType = _cmsKitTestData.Content_1_EntityType, - EntityId = _cmsKitTestData.EntityId1 - }); + var list = await _tagAppService.GetAllRelatedTagsAsync(_cmsKitTestData.Content_1_EntityType, + _cmsKitTestData.EntityId1); list.ShouldNotBeEmpty(); list.Count.ShouldBe(2); @@ -44,35 +39,9 @@ namespace Volo.CmsKit.Tags [Fact] public async Task ShouldntGet_GetAllRelatedTagsAsync() { - var list = await _tagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput - { - EntityType = "any_other_type", - EntityId = "1" - }); + var list = await _tagAppService.GetAllRelatedTagsAsync("any_other_type", "1"); list.ShouldBeEmpty(); } - - [Fact] - public async Task GetRelatedTagsAsync_ShouldThrowValidationException_WithoutEntityType() - { - await Assert.ThrowsAsync(async () => - await _tagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput - { - EntityType = null, - EntityId = _cmsKitTestData.EntityId1 - })); - } - - [Fact] - public async Task GetRelatedTagsAsync_ShouldThrowValidationException_WithoutEntityId() - { - await Assert.ThrowsAsync(async () => - await _tagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput - { - EntityType = null, - EntityId = _cmsKitTestData.EntityId1 - })); - } } -} +} \ No newline at end of file From f48409be6c6f2f6ed745be5b62a63c8ee48d81a5 Mon Sep 17 00:00:00 2001 From: enisn Date: Wed, 6 Jan 2021 14:42:23 +0300 Subject: [PATCH 3/4] CmsKit - Add GlobalFeature check to configuration of ModelBuilder --- .../CmsKitDbContextModelCreatingExtensions.cs | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 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..a0a4ca06d0 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,59 +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 => { b.ToTable(options.TablePrefix + "Contents", options.Schema); - + b.ConfigureByConvention(); - + 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 => + + if (GlobalFeatureManager.Instance.IsEnabled()) { - 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 + "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 }); }); } From 0f786308893ebb8bccdd5e4875d508f6f7ca476c Mon Sep 17 00:00:00 2001 From: enisn Date: Thu, 7 Jan 2021 15:21:53 +0300 Subject: [PATCH 4/4] Fix syntax error at CmsKitDbContextModelCreatingExtensions --- .../CmsKitDbContextModelCreatingExtensions.cs | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 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 d089a8fe9d..8e3b7160db 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 @@ -99,16 +99,19 @@ namespace Volo.CmsKit.EntityFrameworkCore 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.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.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.HasIndex(x => new { x.TenantId, x.EntityType, x.EntityId }); + }); + } if (GlobalFeatureManager.Instance.IsEnabled()) { @@ -121,7 +124,11 @@ namespace Volo.CmsKit.EntityFrameworkCore 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 => @@ -151,7 +158,7 @@ namespace Volo.CmsKit.EntityFrameworkCore 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.Url }); }); } }