From 46ad9fe360fb8596af16d68927366a0efc2dfd41 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 18 Jan 2019 17:35:56 +0300 Subject: [PATCH] microservice demo: added product permissions --- ...roductManagementPermissionDefinitionProvider.cs | 7 ++++++- .../ProductManagementPermissions.cs | 14 +++++++++++++- .../ProductManagement/ProductAppService.cs | 5 +++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/ProductManagementPermissionDefinitionProvider.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/ProductManagementPermissionDefinitionProvider.cs index 5ebc51d258..23d8b4b7ee 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/ProductManagementPermissionDefinitionProvider.cs +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/ProductManagementPermissionDefinitionProvider.cs @@ -8,7 +8,12 @@ namespace ProductManagement { public override void Define(IPermissionDefinitionContext context) { - //var moduleGroup = context.AddGroup(ProductManagementPermissions.GroupName, L("Permission:ProductManagement")); + var productManagementGroup = context.AddGroup(ProductManagementPermissions.GroupName, L("Permission:ProductManagement")); + + var products = productManagementGroup.AddPermission(ProductManagementPermissions.Products.Default, L("Permission:Products")); + products.AddChild(ProductManagementPermissions.Products.Update, L("Permission:Edit")); + products.AddChild(ProductManagementPermissions.Products.Delete, L("Permission:Delete")); + products.AddChild(ProductManagementPermissions.Products.Create, L("Permission:Create")); } private static LocalizableString L(string name) diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/ProductManagementPermissions.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/ProductManagementPermissions.cs index f804b97815..b4dd949a73 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/ProductManagementPermissions.cs +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application.Contracts/MyCompanyName/ProductManagement/ProductManagementPermissions.cs @@ -4,11 +4,23 @@ { public const string GroupName = "ProductManagement"; + public static class Products + { + public const string Default = GroupName + ".Product"; + public const string Delete = Default + ".Delete"; + public const string Update = Default + ".Update"; + public const string Create = Default + ".Create"; + + } public static string[] GetAll() { return new[] { - GroupName + GroupName, + Products.Default, + Products.Delete, + Products.Update, + Products.Create }; } } diff --git a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/MyCompanyName/ProductManagement/ProductAppService.cs b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/MyCompanyName/ProductManagement/ProductAppService.cs index d32d1c1800..e11eac435f 100644 --- a/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/MyCompanyName/ProductManagement/ProductAppService.cs +++ b/samples/MicroserviceDemo/modules/product/src/ProductManagement.Application/MyCompanyName/ProductManagement/ProductAppService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; using ProductManagement; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; @@ -8,6 +9,7 @@ using Volo.Abp.Domain.Repositories; namespace ProductManagement { + [Authorize(ProductManagementPermissions.Products.Default)] public class ProductAppService : ApplicationService, IProductAppService { private readonly ProductManager _productManager; @@ -46,6 +48,7 @@ namespace ProductManagement return ObjectMapper.Map(product); } + [Authorize(ProductManagementPermissions.Products.Create)] public async Task CreateAsync(CreateProductDto input) { var product = await _productManager.CreateAsync(input.Code, input.Name, input.Price, input.StockCount); @@ -53,6 +56,7 @@ namespace ProductManagement return ObjectMapper.Map(product); } + [Authorize(ProductManagementPermissions.Products.Update)] public async Task UpdateAsync(Guid id, UpdateProductDto input) { var product = await _productRepository.GetAsync(id); @@ -64,6 +68,7 @@ namespace ProductManagement return ObjectMapper.Map(product); } + [Authorize(ProductManagementPermissions.Products.Delete)] public async Task DeleteAsync(Guid id) { await _productRepository.DeleteAsync(id);