mirror of https://github.com/abpframework/abp.git
25 changed files with 360 additions and 54 deletions
@ -0,0 +1,10 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
using Volo.CmsKit.Tags; |
||||
|
|
||||
|
namespace Volo.CmsKit.Admin.Tags |
||||
|
{ |
||||
|
public interface ITagAdminAppService : ICrudAppService<TagDto, Guid, TagGetListInput, TagCreateDto, TagUpdateDto> |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
|
||||
|
namespace Volo.CmsKit.Admin.Tags |
||||
|
{ |
||||
|
public class TagCreateDto |
||||
|
{ |
||||
|
[Required] |
||||
|
public string EntityType { get; set; } |
||||
|
[Required] |
||||
|
public string Name { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
using Volo.Abp.Application.Dtos; |
||||
|
|
||||
|
namespace Volo.CmsKit.Admin.Tags |
||||
|
{ |
||||
|
public class TagGetListInput : PagedAndSortedResultRequestDto |
||||
|
{ |
||||
|
public string Filter { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
using System.ComponentModel.DataAnnotations; |
||||
|
|
||||
|
namespace Volo.CmsKit.Admin.Tags |
||||
|
{ |
||||
|
public class TagUpdateDto |
||||
|
{ |
||||
|
[Required] |
||||
|
public string Name { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
using Volo.Abp.Authorization.Permissions; |
||||
|
using Volo.Abp.Localization; |
||||
|
using Volo.CmsKit.Localization; |
||||
|
|
||||
|
namespace Volo.CmsKit.Permissions |
||||
|
{ |
||||
|
public class CmsKitAdminPermissionDefinitionProvider : PermissionDefinitionProvider |
||||
|
{ |
||||
|
public override void Define(IPermissionDefinitionContext context) |
||||
|
{ |
||||
|
var cmsGroup = context.GetGroupOrNull(CmsKitAdminPermissions.GroupName) ?? context.AddGroup(CmsKitAdminPermissions.GroupName, L("Permission:CmsKit")); |
||||
|
|
||||
|
cmsGroup |
||||
|
.AddPermission(CmsKitAdminPermissions.Tags.Default, L("Permission:TagManagement")) |
||||
|
.AddChild(CmsKitAdminPermissions.Tags.Create, L("Permission:TagManagement.Create")) |
||||
|
.AddChild(CmsKitAdminPermissions.Tags.Update, L("Permission:TagManagement.Update")) |
||||
|
.AddChild(CmsKitAdminPermissions.Tags.Delete, L("Permission:TagManagement.Delete")); |
||||
|
} |
||||
|
|
||||
|
private static LocalizableString L(string name) |
||||
|
{ |
||||
|
return LocalizableString.Create<CmsKitResource>(name); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
using Volo.Abp.Reflection; |
||||
|
|
||||
|
namespace Volo.CmsKit.Permissions |
||||
|
{ |
||||
|
public class CmsKitAdminPermissions |
||||
|
{ |
||||
|
public const string GroupName = "CmsKit"; |
||||
|
public static class Tags |
||||
|
{ |
||||
|
public const string Default = GroupName + ".Tags"; |
||||
|
public const string Create = Default + ".Create"; |
||||
|
public const string Update = Default + ".Update"; |
||||
|
public const string Delete = Default + ".Delete"; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,72 @@ |
|||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Application.Services; |
||||
|
using Volo.Abp.Domain.Repositories; |
||||
|
using Volo.CmsKit.Admin.Tags; |
||||
|
using Volo.CmsKit.Permissions; |
||||
|
using Volo.CmsKit.Tags; |
||||
|
|
||||
|
namespace Volo.CmsKit.Admin.Tags |
||||
|
{ |
||||
|
[Authorize(CmsKitAdminPermissions.Tags.Default)] |
||||
|
public class TagAdminAppService : |
||||
|
CrudAppService< |
||||
|
Tag, |
||||
|
TagDto, |
||||
|
Guid, |
||||
|
TagGetListInput, |
||||
|
TagCreateDto, |
||||
|
TagUpdateDto>, |
||||
|
ITagAdminAppService |
||||
|
{ |
||||
|
protected ITagManager TagManager { get; } |
||||
|
|
||||
|
public TagAdminAppService( |
||||
|
IRepository<Tag, Guid> repository, |
||||
|
ITagManager tagManager) : base(repository) |
||||
|
{ |
||||
|
TagManager = tagManager; |
||||
|
|
||||
|
GetListPolicyName = CmsKitAdminPermissions.Tags.Default; |
||||
|
GetPolicyName = CmsKitAdminPermissions.Tags.Default; |
||||
|
CreatePolicyName = CmsKitAdminPermissions.Tags.Create; |
||||
|
UpdatePolicyName = CmsKitAdminPermissions.Tags.Update; |
||||
|
DeletePolicyName = CmsKitAdminPermissions.Tags.Delete; |
||||
|
} |
||||
|
|
||||
|
[Authorize(CmsKitAdminPermissions.Tags.Create)] |
||||
|
public override async Task<TagDto> CreateAsync(TagCreateDto input) |
||||
|
{ |
||||
|
var tag = await TagManager.InsertAsync( |
||||
|
GuidGenerator.Create(), |
||||
|
input.EntityType, |
||||
|
input.Name, |
||||
|
CurrentTenant?.Id); |
||||
|
|
||||
|
return MapToGetOutputDto(tag); |
||||
|
} |
||||
|
|
||||
|
[Authorize(CmsKitAdminPermissions.Tags.Update)] |
||||
|
public override async Task<TagDto> UpdateAsync(Guid id, TagUpdateDto input) |
||||
|
{ |
||||
|
var tag = await TagManager.UpdateAsync( |
||||
|
id, |
||||
|
input.Name); |
||||
|
|
||||
|
return MapToGetOutputDto(tag); |
||||
|
} |
||||
|
protected override IQueryable<Tag> CreateFilteredQuery(TagGetListInput input) |
||||
|
{ |
||||
|
return base.CreateFilteredQuery(input) |
||||
|
.WhereIf( |
||||
|
!input.Filter.IsNullOrEmpty(), |
||||
|
x => |
||||
|
x.Name.ToLower().Contains(input.Filter) || |
||||
|
x.EntityType.ToLower().Contains(input.Filter)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,56 @@ |
|||||
|
using Microsoft.AspNetCore.Authorization; |
||||
|
using Microsoft.AspNetCore.Mvc; |
||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.CmsKit.Admin.Tags; |
||||
|
using Volo.CmsKit.Permissions; |
||||
|
using Volo.CmsKit.Tags; |
||||
|
|
||||
|
namespace Volo.CmsKit.Admin.Tags |
||||
|
{ |
||||
|
public class TagController : CmsKitAdminController, ITagAdminAppService |
||||
|
{ |
||||
|
protected ITagAdminAppService TagAdminAppService { get; } |
||||
|
|
||||
|
public TagController(ITagAdminAppService tagAdminAppService) |
||||
|
{ |
||||
|
TagAdminAppService = tagAdminAppService; |
||||
|
} |
||||
|
|
||||
|
[HttpPost] |
||||
|
[Authorize(CmsKitAdminPermissions.Tags.Create)] |
||||
|
public Task<TagDto> CreateAsync(TagCreateDto input) |
||||
|
{ |
||||
|
return TagAdminAppService.CreateAsync(input); |
||||
|
} |
||||
|
|
||||
|
[HttpDelete("{id}")] |
||||
|
[Authorize(CmsKitAdminPermissions.Tags.Delete)] |
||||
|
public Task DeleteAsync(Guid id) |
||||
|
{ |
||||
|
return TagAdminAppService.DeleteAsync(id); |
||||
|
} |
||||
|
|
||||
|
[HttpGet("{id}")] |
||||
|
[Authorize(CmsKitAdminPermissions.Tags.Default)] |
||||
|
public Task<TagDto> GetAsync(Guid id) |
||||
|
{ |
||||
|
return TagAdminAppService.GetAsync(id); |
||||
|
} |
||||
|
|
||||
|
[HttpGet] |
||||
|
[Authorize(CmsKitAdminPermissions.Tags.Default)] |
||||
|
public Task<PagedResultDto<TagDto>> GetListAsync(TagGetListInput input) |
||||
|
{ |
||||
|
return TagAdminAppService.GetListAsync(input); |
||||
|
} |
||||
|
|
||||
|
[HttpPut("{id}")] |
||||
|
[Authorize(CmsKitAdminPermissions.Tags.Update)] |
||||
|
public Task<TagDto> UpdateAsync(Guid id, [FromBody] TagUpdateDto input) |
||||
|
{ |
||||
|
return TagAdminAppService.UpdateAsync(id, input); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,22 +1,29 @@ |
|||||
{ |
{ |
||||
"culture": "en", |
"culture": "en", |
||||
"texts": { |
"texts": { |
||||
"PickYourReaction": "Pick your reaction", |
"CommentAuthorizationExceptionMessage": "Those comments are not allowed for public display.", |
||||
"YourComment": "Your comment", |
|
||||
"YourReply": "Your reply", |
|
||||
"Comments": "Comments", |
"Comments": "Comments", |
||||
"Send": "Send", |
|
||||
"Delete": "Delete", |
"Delete": "Delete", |
||||
"Reply": "Reply", |
|
||||
"Update": "Update", |
|
||||
"Edit": "Edit", |
"Edit": "Edit", |
||||
"LoginToAddComment": "Login to add comment", |
"LoginToAddComment": "Login to add comment", |
||||
|
"LoginToRate": "Login to rate", |
||||
"LoginToReply": "Login to reply", |
"LoginToReply": "Login to reply", |
||||
"MessageDeletionConfirmationMessage": "This comment will be deleted completely.", |
"MessageDeletionConfirmationMessage": "This comment will be deleted completely.", |
||||
"CommentAuthorizationExceptionMessage": "Those comments are not allowed for public display.", |
"Permission:CmsKit": "CmsKit", |
||||
"Undo": "Undo", |
"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.", |
"RatingUndoMessage": "Your rating will be undo.", |
||||
"LoginToRate": "Login to rate", |
"Reply": "Reply", |
||||
"Star": "Star" |
"Send": "Send", |
||||
|
"Star": "Star", |
||||
|
"TagDeletionConfirmationMessage": "Are you sure to delete '{0}' tag?", |
||||
|
"Tags": "Tags", |
||||
|
"Undo": "Undo", |
||||
|
"Update": "Update", |
||||
|
"YourComment": "Your comment", |
||||
|
"YourReply": "Your reply" |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,22 +1,29 @@ |
|||||
{ |
{ |
||||
"culture": "tr", |
"culture": "tr", |
||||
"texts": { |
"texts": { |
||||
"PickYourReaction": "Tepkinizi seçin", |
"CommentAuthorizationExceptionMessage": "Bu yorumları görebilmek için yetki gerekir.", |
||||
"YourComment": "Yorumunuz", |
|
||||
"YourReply": "Cevabınız", |
|
||||
"Comments": "Yorumlar", |
"Comments": "Yorumlar", |
||||
"Send": "Gönder", |
|
||||
"Delete": "Sil", |
"Delete": "Sil", |
||||
"Reply": "Cevapla", |
|
||||
"Update": "Güncelle", |
|
||||
"Edit": "Düzenle", |
"Edit": "Düzenle", |
||||
"LoginToAddComment": "Yorum yapmak için giriş yap", |
"LoginToAddComment": "Yorum yapmak için giriş yap", |
||||
|
"LoginToRate": "Oylamak için giriş yapın", |
||||
"LoginToReply": "Cevap vermek için giriş yap", |
"LoginToReply": "Cevap vermek için giriş yap", |
||||
"MessageDeletionConfirmationMessage": "Bu yorum tamamen silinecektir", |
"MessageDeletionConfirmationMessage": "Bu yorum tamamen silinecektir", |
||||
"CommentAuthorizationExceptionMessage": "Bu yorumları görebilmek için yetki gerekir.", |
"Permission:CmsKit": "CmsKit", |
||||
"Undo": "Geri al", |
"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.", |
"RatingUndoMessage": "Oylamanız geri alınacak.", |
||||
"LoginToRate": "Oylamak için giriş yapın", |
"Reply": "Cevapla", |
||||
"Star": "Yıldız" |
"Send": "Gönder", |
||||
|
"Star": "Yıldız", |
||||
|
"TagDeletionConfirmationMessage": "'{0}' etiketini silmek istediğinize emin misiniz?", |
||||
|
"Tags": "Etiketler", |
||||
|
"Undo": "Geri al", |
||||
|
"Update": "Güncelle", |
||||
|
"YourComment": "Yorumunuz", |
||||
|
"YourReply": "Cevabınız" |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,7 +1,6 @@ |
|||||
using System.Collections.Generic; |
using System.ComponentModel.DataAnnotations; |
||||
using System.ComponentModel.DataAnnotations; |
|
||||
|
|
||||
namespace Volo.CmsKit.Tags |
namespace Volo.CmsKit.Public.Tags |
||||
{ |
{ |
||||
public class GetRelatedTagsInput |
public class GetRelatedTagsInput |
||||
{ |
{ |
||||
@ -1,8 +1,9 @@ |
|||||
using System.Collections.Generic; |
using System.Collections.Generic; |
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
using Volo.Abp.Application.Services; |
using Volo.Abp.Application.Services; |
||||
|
using Volo.CmsKit.Tags; |
||||
|
|
||||
namespace Volo.CmsKit.Tags |
namespace Volo.CmsKit.Public.Tags |
||||
{ |
{ |
||||
public interface ITagAppService : IApplicationService |
public interface ITagAppService : IApplicationService |
||||
{ |
{ |
||||
@ -1,15 +1,15 @@ |
|||||
using System.Collections.Generic; |
using Microsoft.AspNetCore.Mvc; |
||||
|
using System.Collections.Generic; |
||||
using System.Threading.Tasks; |
using System.Threading.Tasks; |
||||
using Microsoft.AspNetCore.Mvc; |
|
||||
using Volo.Abp; |
using Volo.Abp; |
||||
using Volo.CmsKit.Tags; |
using Volo.CmsKit.Tags; |
||||
|
|
||||
namespace Volo.CmsKit.Controllers.Tags |
namespace Volo.CmsKit.Public.Tags |
||||
{ |
{ |
||||
[RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] |
[RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] |
||||
[Area("cms-kit")] |
[Area("cms-kit")] |
||||
[Route("api/cms-kit/tags")] |
[Route("api/cms-kit/tags")] |
||||
public class TagController : CmsKitControllerBase, ITagAppService |
public class TagController : CmsKitPublicControllerBase, ITagAppService |
||||
{ |
{ |
||||
protected readonly ITagAppService TagAppService; |
protected readonly ITagAppService TagAppService; |
||||
|
|
||||
@ -1,4 +1,4 @@ |
|||||
@using Volo.CmsKit.Web.Pages.CmsKit.Shared.Components.Tags |
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Tags |
||||
|
|
||||
@model TagViewComponent.TagViewModel |
@model TagViewComponent.TagViewModel |
||||
|
|
||||
@ -0,0 +1,78 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
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; |
||||
|
|
||||
|
namespace Volo.CmsKit.Tags |
||||
|
{ |
||||
|
public class TagAppService_Tests : CmsKitApplicationTestBase |
||||
|
{ |
||||
|
private readonly ITagAppService _tagAppService; |
||||
|
private ICurrentUser _currentUser; |
||||
|
private readonly CmsKitTestData _cmsKitTestData; |
||||
|
|
||||
|
public TagAppService_Tests() |
||||
|
{ |
||||
|
_tagAppService = GetRequiredService<ITagAppService>(); |
||||
|
_cmsKitTestData = GetRequiredService<CmsKitTestData>(); |
||||
|
} |
||||
|
|
||||
|
protected override void AfterAddApplication(IServiceCollection services) |
||||
|
{ |
||||
|
_currentUser = Substitute.For<ICurrentUser>(); |
||||
|
services.AddSingleton(_currentUser); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task GetAllRelatedTagsAsync() |
||||
|
{ |
||||
|
var list = await _tagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput |
||||
|
{ |
||||
|
EntityType = _cmsKitTestData.Content_1_EntityType, |
||||
|
EntityId = _cmsKitTestData.EntityId1 |
||||
|
}); |
||||
|
|
||||
|
list.ShouldNotBeEmpty(); |
||||
|
list.Count.ShouldBe(2); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task ShouldntGet_GetAllRelatedTagsAsync() |
||||
|
{ |
||||
|
var list = await _tagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput |
||||
|
{ |
||||
|
EntityType = "any_other_type", |
||||
|
EntityId = "1" |
||||
|
}); |
||||
|
|
||||
|
list.ShouldBeEmpty(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task GetRelatedTagsAsync_ShouldThrowValidationException_WithoutEntityType() |
||||
|
{ |
||||
|
await Assert.ThrowsAsync<AbpValidationException>(async () => |
||||
|
await _tagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput |
||||
|
{ |
||||
|
EntityType = null, |
||||
|
EntityId = _cmsKitTestData.EntityId1 |
||||
|
})); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task GetRelatedTagsAsync_ShouldThrowValidationException_WithoutEntityId() |
||||
|
{ |
||||
|
await Assert.ThrowsAsync<AbpValidationException>(async () => |
||||
|
await _tagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput |
||||
|
{ |
||||
|
EntityType = null, |
||||
|
EntityId = _cmsKitTestData.EntityId1 |
||||
|
})); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue