mirror of https://github.com/abpframework/abp.git
79 changed files with 2184 additions and 0 deletions
@ -0,0 +1,2 @@ |
|||
# abp-permissionmanagement |
|||
Permission management module for ABP framework. |
|||
@ -0,0 +1,102 @@ |
|||
|
|||
Microsoft Visual Studio Solution File, Format Version 12.00 |
|||
# Visual Studio 15 |
|||
VisualStudioVersion = 15.0.27428.1 |
|||
MinimumVisualStudioVersion = 10.0.40219.1 |
|||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B559B878-38F7-49CC-BC06-43A32D68C1A7}" |
|||
EndProject |
|||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{63DA4A89-5908-4F37-B7E6-525AEEF20C77}" |
|||
EndProject |
|||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.PermissionManagement.Domain.Shared", "src\Volo.Abp.PermissionManagement.Domain.Shared\Volo.Abp.PermissionManagement.Domain.Shared.csproj", "{0B94EC37-84A7-487A-A764-335E81F3214B}" |
|||
EndProject |
|||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.PermissionManagement.Domain", "src\Volo.Abp.PermissionManagement.Domain\Volo.Abp.PermissionManagement.Domain.csproj", "{3D53B3FC-E6F1-4125-A502-1C5EFFAA1F10}" |
|||
EndProject |
|||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.PermissionManagement.Application.Contracts", "src\Volo.Abp.PermissionManagement.Application.Contracts\Volo.Abp.PermissionManagement.Application.Contracts.csproj", "{A375FAF9-4D87-4C7C-8E42-6EF87FB89F33}" |
|||
EndProject |
|||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.PermissionManagement.Application", "src\Volo.Abp.PermissionManagement.Application\Volo.Abp.PermissionManagement.Application.csproj", "{1B205C45-B5D7-4A75-9745-776A987E47F8}" |
|||
EndProject |
|||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.PermissionManagement.EntityFrameworkCore", "src\Volo.Abp.PermissionManagement.EntityFrameworkCore\Volo.Abp.PermissionManagement.EntityFrameworkCore.csproj", "{0A6772C8-A77C-4E85-8380-4870534E552C}" |
|||
EndProject |
|||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.PermissionManagement.Web", "src\Volo.Abp.PermissionManagement.Web\Volo.Abp.PermissionManagement.Web.csproj", "{97A386F8-DAE0-4BEA-ADE5-1D57C3336515}" |
|||
EndProject |
|||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.PermissionManagement.Tests", "test\Volo.Abp.PermissionManagement.Tests\Volo.Abp.PermissionManagement.Tests.csproj", "{48297098-79D0-413B-939C-6C432142C42D}" |
|||
EndProject |
|||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.PermissionManagement.TestBase", "test\Volo.Abp.PermissionManagement.TestBase\Volo.Abp.PermissionManagement.TestBase.csproj", "{49259427-CAEB-4FAE-81E4-848F789487EA}" |
|||
EndProject |
|||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.PermissionManagement.EntityFrameworkCore.Tests", "test\Volo.Abp.PermissionManagement.EntityFrameworkCore.Tests\Volo.Abp.PermissionManagement.EntityFrameworkCore.Tests.csproj", "{6E710DE0-F3B1-45D7-85BA-F39D839D9B65}" |
|||
EndProject |
|||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.PermissionManagement.MongoDB", "src\Volo.Abp.PermissionManagement.MongoDB\Volo.Abp.PermissionManagement.MongoDB.csproj", "{903C1729-CEBC-4BCD-A102-8D1B1B5465AF}" |
|||
EndProject |
|||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.PermissionManagement.MongoDB.Tests", "test\Volo.Abp.PermissionManagement.MongoDB.Tests\Volo.Abp.PermissionManagement.MongoDB.Tests.csproj", "{AFA65E08-1F17-4BBE-96A6-80F3CFE22A75}" |
|||
EndProject |
|||
Global |
|||
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
|||
Debug|Any CPU = Debug|Any CPU |
|||
Release|Any CPU = Release|Any CPU |
|||
EndGlobalSection |
|||
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
|||
{0B94EC37-84A7-487A-A764-335E81F3214B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{0B94EC37-84A7-487A-A764-335E81F3214B}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{0B94EC37-84A7-487A-A764-335E81F3214B}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{0B94EC37-84A7-487A-A764-335E81F3214B}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{3D53B3FC-E6F1-4125-A502-1C5EFFAA1F10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{3D53B3FC-E6F1-4125-A502-1C5EFFAA1F10}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{3D53B3FC-E6F1-4125-A502-1C5EFFAA1F10}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{3D53B3FC-E6F1-4125-A502-1C5EFFAA1F10}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{A375FAF9-4D87-4C7C-8E42-6EF87FB89F33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{A375FAF9-4D87-4C7C-8E42-6EF87FB89F33}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{A375FAF9-4D87-4C7C-8E42-6EF87FB89F33}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{A375FAF9-4D87-4C7C-8E42-6EF87FB89F33}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{1B205C45-B5D7-4A75-9745-776A987E47F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{1B205C45-B5D7-4A75-9745-776A987E47F8}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{1B205C45-B5D7-4A75-9745-776A987E47F8}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{1B205C45-B5D7-4A75-9745-776A987E47F8}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{0A6772C8-A77C-4E85-8380-4870534E552C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{0A6772C8-A77C-4E85-8380-4870534E552C}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{0A6772C8-A77C-4E85-8380-4870534E552C}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{0A6772C8-A77C-4E85-8380-4870534E552C}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{97A386F8-DAE0-4BEA-ADE5-1D57C3336515}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{97A386F8-DAE0-4BEA-ADE5-1D57C3336515}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{97A386F8-DAE0-4BEA-ADE5-1D57C3336515}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{97A386F8-DAE0-4BEA-ADE5-1D57C3336515}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{48297098-79D0-413B-939C-6C432142C42D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{48297098-79D0-413B-939C-6C432142C42D}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{48297098-79D0-413B-939C-6C432142C42D}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{48297098-79D0-413B-939C-6C432142C42D}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{49259427-CAEB-4FAE-81E4-848F789487EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{49259427-CAEB-4FAE-81E4-848F789487EA}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{49259427-CAEB-4FAE-81E4-848F789487EA}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{49259427-CAEB-4FAE-81E4-848F789487EA}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{6E710DE0-F3B1-45D7-85BA-F39D839D9B65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{6E710DE0-F3B1-45D7-85BA-F39D839D9B65}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{6E710DE0-F3B1-45D7-85BA-F39D839D9B65}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{6E710DE0-F3B1-45D7-85BA-F39D839D9B65}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{903C1729-CEBC-4BCD-A102-8D1B1B5465AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{903C1729-CEBC-4BCD-A102-8D1B1B5465AF}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{903C1729-CEBC-4BCD-A102-8D1B1B5465AF}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{903C1729-CEBC-4BCD-A102-8D1B1B5465AF}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
{AFA65E08-1F17-4BBE-96A6-80F3CFE22A75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|||
{AFA65E08-1F17-4BBE-96A6-80F3CFE22A75}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|||
{AFA65E08-1F17-4BBE-96A6-80F3CFE22A75}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|||
{AFA65E08-1F17-4BBE-96A6-80F3CFE22A75}.Release|Any CPU.Build.0 = Release|Any CPU |
|||
EndGlobalSection |
|||
GlobalSection(SolutionProperties) = preSolution |
|||
HideSolutionNode = FALSE |
|||
EndGlobalSection |
|||
GlobalSection(NestedProjects) = preSolution |
|||
{0B94EC37-84A7-487A-A764-335E81F3214B} = {B559B878-38F7-49CC-BC06-43A32D68C1A7} |
|||
{3D53B3FC-E6F1-4125-A502-1C5EFFAA1F10} = {B559B878-38F7-49CC-BC06-43A32D68C1A7} |
|||
{A375FAF9-4D87-4C7C-8E42-6EF87FB89F33} = {B559B878-38F7-49CC-BC06-43A32D68C1A7} |
|||
{1B205C45-B5D7-4A75-9745-776A987E47F8} = {B559B878-38F7-49CC-BC06-43A32D68C1A7} |
|||
{0A6772C8-A77C-4E85-8380-4870534E552C} = {B559B878-38F7-49CC-BC06-43A32D68C1A7} |
|||
{97A386F8-DAE0-4BEA-ADE5-1D57C3336515} = {B559B878-38F7-49CC-BC06-43A32D68C1A7} |
|||
{48297098-79D0-413B-939C-6C432142C42D} = {63DA4A89-5908-4F37-B7E6-525AEEF20C77} |
|||
{49259427-CAEB-4FAE-81E4-848F789487EA} = {63DA4A89-5908-4F37-B7E6-525AEEF20C77} |
|||
{6E710DE0-F3B1-45D7-85BA-F39D839D9B65} = {63DA4A89-5908-4F37-B7E6-525AEEF20C77} |
|||
{903C1729-CEBC-4BCD-A102-8D1B1B5465AF} = {B559B878-38F7-49CC-BC06-43A32D68C1A7} |
|||
{AFA65E08-1F17-4BBE-96A6-80F3CFE22A75} = {63DA4A89-5908-4F37-B7E6-525AEEF20C77} |
|||
EndGlobalSection |
|||
GlobalSection(ExtensibilityGlobals) = postSolution |
|||
SolutionGuid = {8FC7DF78-5E2D-489F-9D43-147D2ABAA112} |
|||
EndGlobalSection |
|||
EndGlobal |
|||
@ -0,0 +1,16 @@ |
|||
<Project> |
|||
<PropertyGroup> |
|||
<LangVersion>latest</LangVersion> |
|||
<Version>0.3.0</Version> |
|||
<NoWarn>$(NoWarn);CS1591</NoWarn> |
|||
<PackageIconUrl>http://www.aspnetboilerplate.com/images/abp_nupkg.png</PackageIconUrl> |
|||
<PackageProjectUrl>http://abp.io</PackageProjectUrl> |
|||
<RepositoryType>git</RepositoryType> |
|||
<RepositoryUrl>https://github.com/volosoft/abp/</RepositoryUrl> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.8.1" PrivateAssets="All" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,23 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<AssemblyName>Volo.Abp.PermissionManagement.Application.Contracts</AssemblyName> |
|||
<PackageId>Volo.Abp.PermissionManagement.Application.Contracts</PackageId> |
|||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Volo.Abp.PermissionManagement.Domain.Shared\Volo.Abp.PermissionManagement.Domain.Shared.csproj" /> |
|||
|
|||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.Authorization\Volo.Abp.Authorization.csproj" /> |
|||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.Ddd.Application\Volo.Abp.Ddd.Application.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,16 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Application; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
[DependsOn(typeof(AbpDddApplicationModule))] |
|||
[DependsOn(typeof(AbpPermissionManagementDomainSharedModule))] |
|||
public class AbpPermissionManagementApplicationContractsModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddAssemblyOf<AbpPermissionManagementApplicationContractsModule>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public class GetPermissionListResultDto |
|||
{ |
|||
public string EntityDisplayName { get; set; } |
|||
|
|||
public List<PermissionGroupDto> Groups { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public class PermissionGrantInfoDto |
|||
{ |
|||
public string Name { get; set; } |
|||
|
|||
public string DisplayName { get; set; } |
|||
|
|||
public string ParentName { get; set; } |
|||
|
|||
public bool IsGranted { get; set; } |
|||
|
|||
public List<ProviderInfoDto> Providers { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public class PermissionGroupDto |
|||
{ |
|||
public string Name { get; set; } |
|||
|
|||
public string DisplayName { get; set; } |
|||
|
|||
public List<PermissionGrantInfoDto> Permissions { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public class ProviderInfoDto |
|||
{ |
|||
public string ProviderName { get; set; } |
|||
|
|||
public string ProviderKey { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public class UpdatePermissionDto |
|||
{ |
|||
public string Name { get; set; } |
|||
|
|||
public bool IsGranted { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public class UpdatePermissionsDto |
|||
{ |
|||
public UpdatePermissionDto[] Permissions { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<AssemblyName>Volo.Abp.PermissionManagement.Application</AssemblyName> |
|||
<PackageId>Volo.Abp.PermissionManagement.Application</PackageId> |
|||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Volo.Abp.PermissionManagement.Application.Contracts\Volo.Abp.PermissionManagement.Application.Contracts.csproj" /> |
|||
<ProjectReference Include="..\Volo.Abp.PermissionManagement.Domain\Volo.Abp.PermissionManagement.Domain.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,15 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
[DependsOn(typeof(AbpPermissionManagementDomainModule))] |
|||
[DependsOn(typeof(AbpPermissionManagementApplicationContractsModule))] |
|||
public class AbpPermissionManagementApplicationModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddAssemblyOf<AbpPermissionManagementApplicationModule>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using System.Threading.Tasks; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public interface IPermissionAppServiceHelper |
|||
{ |
|||
Task<GetPermissionListResultDto> GetAsync([NotNull] string providerName, [NotNull] string providerKey); |
|||
|
|||
Task UpdateAsync([NotNull] string providerName, [NotNull] string providerKey, UpdatePermissionsDto input); |
|||
} |
|||
} |
|||
@ -0,0 +1,82 @@ |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.Localization; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public class PermissionAppServiceHelper : IPermissionAppServiceHelper, ITransientDependency |
|||
{ |
|||
private readonly IPermissionManager _permissionManager; |
|||
private readonly IPermissionDefinitionManager _permissionDefinitionManager; |
|||
private readonly IStringLocalizerFactory _stringLocalizerFactory; |
|||
|
|||
public PermissionAppServiceHelper( |
|||
IPermissionManager permissionManager, |
|||
IPermissionDefinitionManager permissionDefinitionManager, |
|||
IStringLocalizerFactory stringLocalizerFactory) |
|||
{ |
|||
_permissionManager = permissionManager; |
|||
_permissionDefinitionManager = permissionDefinitionManager; |
|||
_stringLocalizerFactory = stringLocalizerFactory; |
|||
} |
|||
|
|||
public async Task<GetPermissionListResultDto> GetAsync(string providerName, string providerKey) |
|||
{ |
|||
var result = new GetPermissionListResultDto |
|||
{ |
|||
EntityDisplayName = providerKey, |
|||
Groups = new List<PermissionGroupDto>() |
|||
}; |
|||
|
|||
foreach (var group in _permissionDefinitionManager.GetGroups()) |
|||
{ |
|||
var groupDto = new PermissionGroupDto |
|||
{ |
|||
Name = group.Name, |
|||
DisplayName = group.DisplayName.Localize(_stringLocalizerFactory), |
|||
Permissions = new List<PermissionGrantInfoDto>() |
|||
}; |
|||
|
|||
foreach (var permission in group.GetPermissionsWithChildren()) |
|||
{ |
|||
var grantInfoDto = new PermissionGrantInfoDto |
|||
{ |
|||
Name = permission.Name, |
|||
DisplayName = permission.DisplayName.Localize(_stringLocalizerFactory), |
|||
ParentName = permission.Parent?.Name, |
|||
Providers = new List<ProviderInfoDto>() |
|||
}; |
|||
|
|||
var grantInfo = await _permissionManager.GetAsync(permission.Name, providerName, providerKey); |
|||
|
|||
grantInfoDto.IsGranted = grantInfo.IsGranted; |
|||
|
|||
foreach (var provider in grantInfo.Providers) |
|||
{ |
|||
grantInfoDto.Providers.Add(new ProviderInfoDto |
|||
{ |
|||
ProviderName = provider.Name, |
|||
ProviderKey = provider.Key, |
|||
}); |
|||
} |
|||
|
|||
groupDto.Permissions.Add(grantInfoDto); |
|||
} |
|||
|
|||
result.Groups.Add(groupDto); |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
public async Task UpdateAsync(string providerName, string providerKey, UpdatePermissionsDto input) |
|||
{ |
|||
foreach (var permission in input.Permissions) |
|||
{ |
|||
await _permissionManager.SetAsync(permission.Name, providerName, providerKey, permission.IsGranted); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<AssemblyName>Volo.Abp.PermissionManagement.Domain.Shared</AssemblyName> |
|||
<PackageId>Volo.Abp.PermissionManagement.Domain.Shared</PackageId> |
|||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.Core\Volo.Abp.Core.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,13 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public class AbpPermissionManagementDomainSharedModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddAssemblyOf<AbpPermissionManagementDomainSharedModule>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public static class PermissionGrantConsts |
|||
{ |
|||
public const int MaxNameLength = 128; |
|||
|
|||
public const int MaxProviderNameLength = 64; |
|||
|
|||
public const int MaxProviderKeyLength = 64; |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<AssemblyName>Volo.Abp.PermissionManagement.Domain</AssemblyName> |
|||
<PackageId>Volo.Abp.PermissionManagement.Domain</PackageId> |
|||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Volo.Abp.PermissionManagement.Domain.Shared\Volo.Abp.PermissionManagement.Domain.Shared.csproj" /> |
|||
|
|||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.Authorization\Volo.Abp.Authorization.csproj" /> |
|||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.Caching\Volo.Abp.Caching.csproj" /> |
|||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.Ddd.Domain\Volo.Abp.Ddd.Domain.csproj" /> |
|||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.Json\Volo.Abp.Json.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,9 @@ |
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public static class AbpPermissionManagementConsts |
|||
{ |
|||
public const string DefaultDbTablePrefix = "Abp"; |
|||
|
|||
public const string DefaultDbSchema = null; |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Authorization; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.Domain; |
|||
using Volo.Abp.Json; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
[DependsOn(typeof(AbpAuthorizationModule))] |
|||
[DependsOn(typeof(AbpDddDomainModule))] |
|||
[DependsOn(typeof(AbpPermissionManagementDomainSharedModule))] |
|||
[DependsOn(typeof(AbpCachingModule))] |
|||
[DependsOn(typeof(AbpJsonModule))] |
|||
public class AbpPermissionManagementDomainModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddAssemblyOf<AbpPermissionManagementDomainModule>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public interface IPermissionGrantRepository : IBasicRepository<PermissionGrant, Guid> |
|||
{ |
|||
Task<PermissionGrant> FindAsync(string name, string providerName, string providerKey); |
|||
|
|||
Task<List<PermissionGrant>> GetListAsync(string providerName, string providerKey); |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
using System.Threading.Tasks; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public interface IPermissionManagementProvider : ISingletonDependency |
|||
{ |
|||
string Name { get; } |
|||
|
|||
Task<PermissionValueProviderGrantInfo> CheckAsync([NotNull] string name, [NotNull] string providerName, [NotNull] string providerKey); |
|||
|
|||
Task SetAsync([NotNull] string name, [NotNull] string providerKey, bool isGranted); |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
//TODO: Write extension methods for simple IsGranted check
|
|||
|
|||
public interface IPermissionManager |
|||
{ |
|||
Task<PermissionWithGrantedProviders> GetAsync(string permissionName, string providerName, string providerKey); |
|||
|
|||
Task<List<PermissionWithGrantedProviders>> GetAllAsync([NotNull] string providerName, [NotNull] string providerKey); |
|||
|
|||
Task SetAsync(string permissionName, string providerName, string providerKey, bool isGranted); |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Domain.Entities; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public class PermissionGrant : Entity<Guid>, IMultiTenant |
|||
{ |
|||
public virtual Guid? TenantId { get; protected set; } |
|||
|
|||
[NotNull] |
|||
public virtual string Name { get; protected set; } |
|||
|
|||
[NotNull] |
|||
public virtual string ProviderName { get; protected set; } |
|||
|
|||
[NotNull] |
|||
public virtual string ProviderKey { get; protected set; } |
|||
|
|||
protected PermissionGrant() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public PermissionGrant( |
|||
Guid id, |
|||
[NotNull] string name, |
|||
[NotNull] string providerName , |
|||
[NotNull] string providerKey, |
|||
Guid? tenantId = null) |
|||
{ |
|||
Check.NotNull(name, nameof(name)); |
|||
|
|||
Id = id; |
|||
Name = name; |
|||
ProviderName = providerName; |
|||
ProviderKey = providerKey; |
|||
TenantId = tenantId; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
using System; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
[Serializable] |
|||
public class PermissionGrantCacheItem |
|||
{ |
|||
public string Name { get; set; } |
|||
|
|||
public bool IsGranted { get; set; } |
|||
|
|||
public PermissionGrantCacheItem() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public PermissionGrantCacheItem(string name, bool isGranted) |
|||
{ |
|||
Name = name; |
|||
IsGranted = isGranted; |
|||
} |
|||
|
|||
public static string CalculateCacheKey(string name, string providerName, string providerKey) |
|||
{ |
|||
return "pn:" + providerName + ",pk:" + providerKey + ",n:" + name; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Domain.Entities.Events; |
|||
using Volo.Abp.EventBus; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public class PermissionGrantCacheItemInvalidator : IEventHandler<EntityChangedEventData<PermissionGrant>>, ITransientDependency |
|||
{ |
|||
protected ICurrentTenant CurrentTenant { get; } |
|||
|
|||
protected IDistributedCache<PermissionGrantCacheItem> Cache { get; } |
|||
|
|||
public PermissionGrantCacheItemInvalidator(IDistributedCache<PermissionGrantCacheItem> cache, ICurrentTenant currentTenant) |
|||
{ |
|||
Cache = cache; |
|||
CurrentTenant = currentTenant; |
|||
} |
|||
|
|||
public virtual async Task HandleEventAsync(EntityChangedEventData<PermissionGrant> eventData) |
|||
{ |
|||
var cacheKey = CalculateCacheKey( |
|||
eventData.Entity.Name, |
|||
eventData.Entity.ProviderName, |
|||
eventData.Entity.ProviderKey |
|||
); |
|||
|
|||
using (CurrentTenant.Change(eventData.Entity.TenantId)) |
|||
{ |
|||
await Cache.RemoveAsync(cacheKey); |
|||
} |
|||
} |
|||
|
|||
protected virtual string CalculateCacheKey(string name, string providerName, string providerKey) |
|||
{ |
|||
return PermissionGrantCacheItem.CalculateCacheKey(name, providerName, providerKey); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using Volo.Abp.Collections; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public class PermissionManagementOptions |
|||
{ |
|||
public ITypeList<IPermissionManagementProvider> ManagementProviders { get; } |
|||
|
|||
public PermissionManagementOptions() |
|||
{ |
|||
ManagementProviders = new TypeList<IPermissionManagementProvider>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,79 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.Guids; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public abstract class PermissionManagementProvider : IPermissionManagementProvider |
|||
{ |
|||
public abstract string Name { get; } |
|||
|
|||
protected IPermissionGrantRepository PermissionGrantRepository { get; } |
|||
|
|||
protected IGuidGenerator GuidGenerator { get; } |
|||
|
|||
protected ICurrentTenant CurrentTenant { get; } |
|||
|
|||
protected PermissionManagementProvider( |
|||
IPermissionGrantRepository permissionGrantRepository, |
|||
IGuidGenerator guidGenerator, |
|||
ICurrentTenant currentTenant) |
|||
{ |
|||
PermissionGrantRepository = permissionGrantRepository; |
|||
GuidGenerator = guidGenerator; |
|||
CurrentTenant = currentTenant; |
|||
} |
|||
|
|||
|
|||
public virtual async Task<PermissionValueProviderGrantInfo> CheckAsync(string name, string providerName, string providerKey) |
|||
{ |
|||
if (providerName != Name) |
|||
{ |
|||
return PermissionValueProviderGrantInfo.NonGranted; |
|||
} |
|||
|
|||
return new PermissionValueProviderGrantInfo( |
|||
await PermissionGrantRepository.FindAsync(name, providerName, providerKey) != null, |
|||
providerKey |
|||
); |
|||
} |
|||
|
|||
public virtual Task SetAsync(string name, string providerKey, bool isGranted) |
|||
{ |
|||
return isGranted |
|||
? GrantAsync(name, providerKey) |
|||
: RevokeAsync(name, providerKey); |
|||
} |
|||
|
|||
protected virtual async Task GrantAsync(string name, string providerKey) |
|||
{ |
|||
var permissionGrant = await PermissionGrantRepository.FindAsync(name, Name, providerKey); |
|||
if (permissionGrant != null) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
await PermissionGrantRepository.InsertAsync( |
|||
new PermissionGrant( |
|||
GuidGenerator.Create(), |
|||
name, |
|||
Name, |
|||
providerKey, |
|||
CurrentTenant.Id |
|||
) |
|||
); |
|||
} |
|||
|
|||
protected virtual async Task RevokeAsync(string name, string providerKey) |
|||
{ |
|||
var permissionGrant = await PermissionGrantRepository.FindAsync(name, Name, providerKey); |
|||
if (permissionGrant == null) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
await PermissionGrantRepository.DeleteAsync(permissionGrant); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,99 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Guids; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public class PermissionManager : IPermissionManager, ISingletonDependency |
|||
{ |
|||
protected IPermissionGrantRepository PermissionGrantRepository { get; } |
|||
|
|||
protected IPermissionDefinitionManager PermissionDefinitionManager { get; } |
|||
|
|||
protected IGuidGenerator GuidGenerator { get; } |
|||
|
|||
protected IReadOnlyList<IPermissionManagementProvider> ManagementProviders => _lazyProviders.Value; |
|||
|
|||
protected PermissionManagementOptions Options { get; } |
|||
|
|||
private readonly Lazy<List<IPermissionManagementProvider>> _lazyProviders; |
|||
|
|||
public PermissionManager( |
|||
IPermissionDefinitionManager permissionDefinitionManager, |
|||
IPermissionGrantRepository permissionGrantRepository, |
|||
IServiceProvider serviceProvider, |
|||
IGuidGenerator guidGenerator, |
|||
IOptions<PermissionManagementOptions> options) |
|||
{ |
|||
GuidGenerator = guidGenerator; |
|||
PermissionGrantRepository = permissionGrantRepository; |
|||
PermissionDefinitionManager = permissionDefinitionManager; |
|||
Options = options.Value; |
|||
|
|||
_lazyProviders = new Lazy<List<IPermissionManagementProvider>>( |
|||
() => Options |
|||
.ManagementProviders |
|||
.Select(c => serviceProvider.GetRequiredService(c) as IPermissionManagementProvider) |
|||
.ToList(), |
|||
true |
|||
); |
|||
} |
|||
|
|||
public async Task<PermissionWithGrantedProviders> GetAsync(string permissionName, string providerName, string providerKey) |
|||
{ |
|||
return await GetInternalAsync(PermissionDefinitionManager.Get(permissionName), providerName, providerKey); |
|||
} |
|||
|
|||
public async Task<List<PermissionWithGrantedProviders>> GetAllAsync(string providerName, string providerKey) |
|||
{ |
|||
var results = new List<PermissionWithGrantedProviders>(); |
|||
|
|||
foreach (var permissionDefinition in PermissionDefinitionManager.GetPermissions()) |
|||
{ |
|||
results.Add(await GetInternalAsync(permissionDefinition, providerName, providerKey)); |
|||
} |
|||
|
|||
return results; |
|||
} |
|||
|
|||
public async Task SetAsync(string permissionName, string providerName, string providerKey, bool isGranted) |
|||
{ |
|||
var currentGrantInfo = await GetAsync(permissionName, providerName, providerKey); |
|||
if (currentGrantInfo.IsGranted == isGranted) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
var provider = ManagementProviders.FirstOrDefault(m => m.Name == providerName); |
|||
if (provider == null) |
|||
{ |
|||
throw new AbpException("Unknown permission management provider: " + providerName); |
|||
} |
|||
|
|||
await provider.SetAsync(permissionName, providerKey, isGranted); |
|||
} |
|||
|
|||
protected virtual async Task<PermissionWithGrantedProviders> GetInternalAsync(PermissionDefinition permissionDefinition, string providerName, string providerKey) |
|||
{ |
|||
var result = new PermissionWithGrantedProviders(permissionDefinition.Name, false); |
|||
|
|||
foreach (var provider in ManagementProviders) |
|||
{ |
|||
var providerResult = await provider.CheckAsync(permissionDefinition.Name, providerName, providerKey); |
|||
if (providerResult.IsGranted) |
|||
{ |
|||
result.IsGranted = true; |
|||
result.Providers.Add(new PermissionValueProviderInfo(provider.Name, providerResult.ProviderKey)); |
|||
} |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,55 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public class PermissionStore : IPermissionStore, ITransientDependency |
|||
{ |
|||
protected IPermissionGrantRepository PermissionGrantRepository { get; } |
|||
|
|||
protected IDistributedCache<PermissionGrantCacheItem> Cache { get; } |
|||
|
|||
public PermissionStore( |
|||
IPermissionGrantRepository permissionGrantRepository, |
|||
IDistributedCache<PermissionGrantCacheItem> cache) |
|||
{ |
|||
PermissionGrantRepository = permissionGrantRepository; |
|||
Cache = cache; |
|||
} |
|||
|
|||
public async Task<bool> IsGrantedAsync(string name, string providerName, string providerKey) |
|||
{ |
|||
return (await GetCacheItemAsync(name, providerName, providerKey)).IsGranted; |
|||
} |
|||
|
|||
protected virtual async Task<PermissionGrantCacheItem> GetCacheItemAsync(string name, string providerName, string providerKey) |
|||
{ |
|||
var cacheKey = CalculateCacheKey(name, providerName, providerKey); |
|||
var cacheItem = await Cache.GetAsync(cacheKey); |
|||
|
|||
if (cacheItem != null) |
|||
{ |
|||
return cacheItem; |
|||
} |
|||
|
|||
cacheItem = new PermissionGrantCacheItem( |
|||
name, |
|||
await PermissionGrantRepository.FindAsync(name, providerName, providerKey) != null |
|||
); |
|||
|
|||
await Cache.SetAsync( |
|||
cacheKey, |
|||
cacheItem |
|||
); |
|||
|
|||
return cacheItem; |
|||
} |
|||
|
|||
protected virtual string CalculateCacheKey(string name, string providerName, string providerKey) |
|||
{ |
|||
return PermissionGrantCacheItem.CalculateCacheKey(name, providerName, providerKey); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public class PermissionValueProviderInfo |
|||
{ |
|||
public string Name { get; } |
|||
|
|||
public string Key { get; } |
|||
|
|||
public PermissionValueProviderInfo([NotNull]string name, [NotNull]string key) |
|||
{ |
|||
Check.NotNull(name, nameof(name)); |
|||
Check.NotNull(key, nameof(key)); |
|||
|
|||
Name = name; |
|||
Key = key; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
using System.Collections.Generic; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public class PermissionWithGrantedProviders |
|||
{ |
|||
public string Name { get; } |
|||
|
|||
public bool IsGranted { get; set; } |
|||
|
|||
public List<PermissionValueProviderInfo> Providers { get; set; } |
|||
|
|||
public PermissionWithGrantedProviders([NotNull] string name, bool isGranted) |
|||
{ |
|||
Check.NotNull(name, nameof(name)); |
|||
|
|||
Name = name; |
|||
IsGranted = isGranted; |
|||
|
|||
Providers = new List<PermissionValueProviderInfo>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<AssemblyName>Volo.Abp.PermissionManagement.EntityFrameworkCore</AssemblyName> |
|||
<PackageId>Volo.Abp.PermissionManagement.EntityFrameworkCore</PackageId> |
|||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Volo.Abp.PermissionManagement.Domain\Volo.Abp.PermissionManagement.Domain.csproj" /> |
|||
|
|||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.EntityFrameworkCore\Volo.Abp.EntityFrameworkCore.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,32 @@ |
|||
using JetBrains.Annotations; |
|||
using Microsoft.EntityFrameworkCore; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.EntityFrameworkCore |
|||
{ |
|||
public static class AbpPermissionManagementDbContextModelBuilderExtensions |
|||
{ |
|||
public static void ConfigurePermissionManagement( |
|||
[NotNull] this ModelBuilder builder, |
|||
[CanBeNull] string tablePrefix = AbpPermissionManagementConsts.DefaultDbTablePrefix, |
|||
[CanBeNull] string schema = AbpPermissionManagementConsts.DefaultDbSchema) |
|||
{ |
|||
Check.NotNull(builder, nameof(builder)); |
|||
|
|||
if (tablePrefix == null) |
|||
{ |
|||
tablePrefix = ""; |
|||
} |
|||
|
|||
builder.Entity<PermissionGrant>(b => |
|||
{ |
|||
b.ToTable(tablePrefix + "PermissionGrants", schema); |
|||
|
|||
b.Property(x => x.Name).HasMaxLength(PermissionGrantConsts.MaxNameLength).IsRequired(); |
|||
b.Property(x => x.ProviderName).HasMaxLength(PermissionGrantConsts.MaxProviderNameLength).IsRequired(); |
|||
b.Property(x => x.ProviderKey).HasMaxLength(PermissionGrantConsts.MaxProviderKeyLength).IsRequired(); |
|||
|
|||
b.HasIndex(x => new {x.Name, x.ProviderName, x.ProviderKey}); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.EntityFrameworkCore |
|||
{ |
|||
[DependsOn(typeof(AbpPermissionManagementDomainModule))] |
|||
[DependsOn(typeof(AbpEntityFrameworkCoreModule))] |
|||
public class AbpPermissionManagementEntityFrameworkCoreModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddAbpDbContext<PermissionManagementDbContext>(options => |
|||
{ |
|||
options.AddDefaultRepositories<IPermissionManagementDbContext>(); |
|||
|
|||
options.AddRepository<PermissionGrant, EfCorePermissionGrantRepository>(); |
|||
}); |
|||
|
|||
services.AddAssemblyOf<AbpPermissionManagementEntityFrameworkCoreModule>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.EntityFrameworkCore |
|||
{ |
|||
public class EfCorePermissionGrantRepository : EfCoreRepository<IPermissionManagementDbContext, PermissionGrant, Guid>, IPermissionGrantRepository |
|||
{ |
|||
public EfCorePermissionGrantRepository(IDbContextProvider<IPermissionManagementDbContext> dbContextProvider) |
|||
: base(dbContextProvider) |
|||
{ |
|||
|
|||
} |
|||
|
|||
public async Task<PermissionGrant> FindAsync(string name, string providerName, string providerKey) |
|||
{ |
|||
return await DbSet |
|||
.FirstOrDefaultAsync(s => |
|||
s.Name == name && |
|||
s.ProviderName == providerName && |
|||
s.ProviderKey == providerKey |
|||
); |
|||
} |
|||
|
|||
public async Task<List<PermissionGrant>> GetListAsync(string providerName, string providerKey) |
|||
{ |
|||
return await DbSet |
|||
.Where(s => |
|||
s.ProviderName == providerName && |
|||
s.ProviderKey == providerKey |
|||
).ToListAsync(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.EntityFrameworkCore |
|||
{ |
|||
[ConnectionStringName("AbpPermissionManagement")] |
|||
public interface IPermissionManagementDbContext : IEfCoreDbContext |
|||
{ |
|||
DbSet<PermissionGrant> PermissionGrants { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.EntityFrameworkCore |
|||
{ |
|||
[ConnectionStringName("AbpPermissionManagement")] |
|||
public class PermissionManagementDbContext : AbpDbContext<PermissionManagementDbContext>, IPermissionManagementDbContext |
|||
{ |
|||
public static string TablePrefix { get; set; } = AbpPermissionManagementConsts.DefaultDbTablePrefix; |
|||
|
|||
public static string Schema { get; set; } = AbpPermissionManagementConsts.DefaultDbSchema; |
|||
|
|||
public DbSet<PermissionGrant> PermissionGrants { get; set; } |
|||
|
|||
public PermissionManagementDbContext(DbContextOptions<PermissionManagementDbContext> options) |
|||
: base(options) |
|||
{ |
|||
|
|||
} |
|||
|
|||
protected override void OnModelCreating(ModelBuilder builder) |
|||
{ |
|||
base.OnModelCreating(builder); |
|||
|
|||
builder.ConfigurePermissionManagement(TablePrefix, Schema); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<AssemblyName>Volo.Abp.PermissionManagement.MongoDB</AssemblyName> |
|||
<PackageId>Volo.Abp.PermissionManagement.MongoDB</PackageId> |
|||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Volo.Abp.PermissionManagement.Domain\Volo.Abp.PermissionManagement.Domain.csproj" /> |
|||
|
|||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.MongoDB\Volo.Abp.MongoDB.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,21 @@ |
|||
using MongoDB.Bson.Serialization; |
|||
using Volo.Abp.Threading; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.MongoDB |
|||
{ |
|||
public static class AbpPermissionManagementBsonClassMap |
|||
{ |
|||
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner(); |
|||
|
|||
public static void Configure() |
|||
{ |
|||
OneTimeRunner.Run(() => |
|||
{ |
|||
BsonClassMap.RegisterClassMap<PermissionGrant>(map => |
|||
{ |
|||
map.AutoMap(); |
|||
}); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
using System; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.MongoDB |
|||
{ |
|||
public static class AbpPermissionManagementMongoDbContextExtensions |
|||
{ |
|||
public static void ConfigurePermissionManagement( |
|||
this IMongoModelBuilder builder, |
|||
Action<MongoModelBuilderConfigurationOptions> optionsAction = null) |
|||
{ |
|||
Check.NotNull(builder, nameof(builder)); |
|||
|
|||
var options = new PermissionManagementMongoModelBuilderConfigurationOptions(); |
|||
|
|||
optionsAction?.Invoke(options); |
|||
|
|||
builder.Entity<PermissionGrant>(b => |
|||
{ |
|||
b.CollectionName = options.CollectionPrefix + "PermissionGrants"; |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using MongoDB.Driver; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.MongoDB |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpPermissionManagementDomainModule), |
|||
typeof(AbpMongoDbModule) |
|||
)] |
|||
public class AbpPermissionManagementMongoDbModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
AbpPermissionManagementBsonClassMap.Configure(); |
|||
|
|||
services.AddMongoDbContext<PermissionManagementMongoDbContext>(options => |
|||
{ |
|||
options.AddDefaultRepositories<IPermissionManagementMongoDbContext>(); |
|||
|
|||
options.AddRepository<PermissionGrant, MongoPermissionGrantRepository>(); |
|||
}); |
|||
|
|||
services.AddAssemblyOf<AbpPermissionManagementMongoDbModule>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using MongoDB.Driver; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.MongoDB |
|||
{ |
|||
[ConnectionStringName("AbpPermissionManagement")] |
|||
public interface IPermissionManagementMongoDbContext : IAbpMongoDbContext |
|||
{ |
|||
IMongoCollection<PermissionGrant> PermissionGrants { get; } |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using MongoDB.Driver; |
|||
using MongoDB.Driver.Linq; |
|||
using Volo.Abp.Domain.Repositories.MongoDB; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.MongoDB |
|||
{ |
|||
public class MongoPermissionGrantRepository : MongoDbRepository<IPermissionManagementMongoDbContext, PermissionGrant, Guid>, IPermissionGrantRepository |
|||
{ |
|||
public MongoPermissionGrantRepository(IMongoDbContextProvider<IPermissionManagementMongoDbContext> dbContextProvider) |
|||
: base(dbContextProvider) |
|||
{ |
|||
|
|||
} |
|||
|
|||
public async Task<PermissionGrant> FindAsync(string name, string providerName, string providerKey) |
|||
{ |
|||
return await GetMongoQueryable() |
|||
.FirstOrDefaultAsync(s => |
|||
s.Name == name && |
|||
s.ProviderName == providerName && |
|||
s.ProviderKey == providerKey |
|||
); |
|||
} |
|||
|
|||
public async Task<List<PermissionGrant>> GetListAsync(string providerName, string providerKey) |
|||
{ |
|||
return await GetMongoQueryable() |
|||
.Where(s => |
|||
s.ProviderName == providerName && |
|||
s.ProviderKey == providerKey |
|||
).ToListAsync(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
using MongoDB.Driver; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.MongoDB |
|||
{ |
|||
[ConnectionStringName("AbpPermissionManagement")] |
|||
public class PermissionManagementMongoDbContext : AbpMongoDbContext, IPermissionManagementMongoDbContext |
|||
{ |
|||
public static string CollectionPrefix { get; set; } = AbpPermissionManagementConsts.DefaultDbTablePrefix; |
|||
|
|||
public IMongoCollection<PermissionGrant> PermissionGrants => Collection<PermissionGrant>(); |
|||
|
|||
protected override void CreateModel(IMongoModelBuilder modelBuilder) |
|||
{ |
|||
base.CreateModel(modelBuilder); |
|||
|
|||
modelBuilder.ConfigurePermissionManagement(options => |
|||
{ |
|||
options.CollectionPrefix = CollectionPrefix; |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.MongoDB |
|||
{ |
|||
public class PermissionManagementMongoModelBuilderConfigurationOptions : MongoModelBuilderConfigurationOptions |
|||
{ |
|||
public PermissionManagementMongoModelBuilderConfigurationOptions([NotNull] string tablePrefix = AbpPermissionManagementConsts.DefaultDbTablePrefix) |
|||
: base(tablePrefix) |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using AutoMapper; |
|||
using Volo.Abp.PermissionManagement.Web.Pages.AbpPermissionManagement; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.Web |
|||
{ |
|||
public class AbpPermissionManagementWebAutoMapperProfile : Profile |
|||
{ |
|||
public AbpPermissionManagementWebAutoMapperProfile() |
|||
{ |
|||
CreateMap<PermissionGroupDto, PermissionManagementModal.PermissionGroupViewModel>(); |
|||
|
|||
CreateMap<PermissionGrantInfoDto, PermissionManagementModal.PermissionGrantInfoViewModel>() |
|||
.ForMember(p => p.Depth, opts => opts.Ignore()); |
|||
|
|||
CreateMap<ProviderInfoDto, PermissionManagementModal.ProviderInfoViewModel>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.AspNetCore.Mvc.Localization; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap; |
|||
using Volo.Abp.AutoMapper; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.PermissionManagement.Web.Localization.Resources.AbpPermissionManagement; |
|||
using Volo.Abp.VirtualFileSystem; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.Web |
|||
{ |
|||
[DependsOn(typeof(AbpPermissionManagementApplicationContractsModule))] |
|||
[DependsOn(typeof(AbpAspNetCoreMvcUiBootstrapModule))] |
|||
[DependsOn(typeof(AbpAutoMapperModule))] |
|||
public class AbpPermissionManagementWebModule : AbpModule |
|||
{ |
|||
public override void PreConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.PreConfigure<AbpMvcDataAnnotationsLocalizationOptions>(options => |
|||
{ |
|||
options.AddAssemblyResource(typeof(AbpPermissionManagementResource)); |
|||
}); |
|||
} |
|||
|
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddAssemblyOf<AbpPermissionManagementWebModule>(); |
|||
|
|||
services.Configure<VirtualFileSystemOptions>(options => |
|||
{ |
|||
options.FileSets.AddEmbedded<AbpPermissionManagementWebModule>("Volo.Abp.PermissionManagement.Web"); |
|||
}); |
|||
|
|||
services.Configure<AbpLocalizationOptions>(options => |
|||
{ |
|||
options.Resources |
|||
.Add<AbpPermissionManagementResource>("en") |
|||
.AddVirtualJson("/Localization/Resources/AbpPermissionManagement"); |
|||
}); |
|||
|
|||
services.Configure<AbpAutoMapperOptions>(options => |
|||
{ |
|||
options.AddProfile<AbpPermissionManagementWebAutoMapperProfile>(validate: true); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
using Localization.Resources.AbpUi; |
|||
using Volo.Abp.Localization; |
|||
using Volo.Abp.Localization.Resources.AbpValidation; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.Web.Localization.Resources.AbpPermissionManagement |
|||
{ |
|||
[InheritResource( |
|||
typeof(AbpValidationResource), |
|||
typeof(AbpUiResource))] |
|||
[LocalizationResourceName("AbpPermissionManagement")] |
|||
public class AbpPermissionManagementResource |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
{ |
|||
"culture": "en", |
|||
"texts": { |
|||
"Permissions": "Permissions" |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
{ |
|||
"culture": "tr", |
|||
"texts": { |
|||
"Permissions": "İzinler" |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using System.Threading.Tasks; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.Web.Pages.AbpPermissionManagement |
|||
{ |
|||
public interface IPermissionAppServiceGateway |
|||
{ |
|||
Task<GetPermissionListResultDto> GetAsync([NotNull] string providerName, [NotNull] string providerKey); |
|||
|
|||
Task UpdateAsync([NotNull] string providerName, [NotNull] string providerKey, UpdatePermissionsDto input); |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.Web.Pages.AbpPermissionManagement |
|||
{ |
|||
public class NotImplementedPermissionAppServiceGateway : IPermissionAppServiceGateway, ISingletonDependency |
|||
{ |
|||
public Task<GetPermissionListResultDto> GetAsync(string providerName, string providerKey) |
|||
{ |
|||
throw new System.NotImplementedException(); |
|||
} |
|||
|
|||
public Task UpdateAsync(string providerName, string providerKey, UpdatePermissionsDto input) |
|||
{ |
|||
throw new System.NotImplementedException(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,58 @@ |
|||
@page |
|||
@using Microsoft.AspNetCore.Mvc.Localization |
|||
@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal |
|||
@using Volo.Abp.PermissionManagement.Web.Localization.Resources.AbpPermissionManagement |
|||
@using Volo.Abp.PermissionManagement.Web.Pages.AbpPermissionManagement |
|||
@model PermissionManagementModal |
|||
@inject IHtmlLocalizer<AbpPermissionManagementResource> L |
|||
@{ |
|||
Layout = null; |
|||
} |
|||
<form method="post" asp-page="/AbpPermissionManagement/PermissionManagementModal" data-script-class="abp.modals.PermissionManagement"> |
|||
|
|||
<abp-modal size="Large"> |
|||
|
|||
<abp-modal-header title="@(L["Permissions"].Value) - @Model.EntityDisplayName"></abp-modal-header> |
|||
|
|||
<abp-modal-body> |
|||
|
|||
<input asp-for="@Model.ProviderKey" /> |
|||
<input asp-for="@Model.ProviderName" /> |
|||
|
|||
<abp-row> |
|||
<abp-column size-sm="_4"> |
|||
<div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical"> |
|||
@for (var i = 0; i < Model.Groups.Count; i++) |
|||
{ |
|||
<a class="nav-link @(i == 0 ? "active" : "")" id="v-pills-tab-@Model.Groups[i].GetNormalizedGroupName()" data-toggle="pill" href="#v-pills-@Model.Groups[i].GetNormalizedGroupName()" role="tab" aria-controls="v-pills-@Model.Groups[i].GetNormalizedGroupName()" aria-selected="false">@Model.Groups[i].DisplayName</a> |
|||
} |
|||
</div> |
|||
</abp-column> |
|||
<abp-column size-sm="_8"> |
|||
<div class="tab-content" id="v-pills-tabContent"> |
|||
@for (var i = 0; i < Model.Groups.Count; i++) |
|||
{ |
|||
<div class="tab-pane fade @(i == 0 ? "show active" : "")" id="v-pills-@Model.Groups[i].GetNormalizedGroupName()" role="tabpanel" aria-labelledby="v-pills-tab-@Model.Groups[i].GetNormalizedGroupName()"> |
|||
@for (var j = 0; j < Model.Groups[i].Permissions.Count; j++) |
|||
{ |
|||
<abp-input asp-for="@Model.Groups[i].Permissions[j].IsGranted" |
|||
label="@Model.Groups[i].Permissions[j].GetShownName(Model.ProviderName)" |
|||
disabled="@Model.Groups[i].Permissions[j].IsDisabled(Model.ProviderName)" |
|||
data-permission-name="@Model.Groups[i].Permissions[j].Name" |
|||
data-parent-name="@(Model.Groups[i].Permissions[j].ParentName ?? "")" |
|||
style="margin-left: @(Model.Groups[i].Permissions[j].Depth * 20)px" /> |
|||
<input asp-for="@Model.Groups[i].Permissions[j].Name" /> |
|||
} |
|||
</div> |
|||
} |
|||
</div> |
|||
</abp-column> |
|||
</abp-row> |
|||
|
|||
</abp-modal-body> |
|||
|
|||
<abp-modal-footer buttons="@(AbpModalButtons.Cancel|AbpModalButtons.Save)"></abp-modal-footer> |
|||
|
|||
</abp-modal> |
|||
|
|||
</form> |
|||
@ -0,0 +1,139 @@ |
|||
using System.Collections.Generic; |
|||
using System.ComponentModel.DataAnnotations; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; |
|||
using Volo.Abp.PermissionManagement.Web.Utils; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.Web.Pages.AbpPermissionManagement |
|||
{ |
|||
public class PermissionManagementModal : AbpPageModel |
|||
{ |
|||
private readonly IPermissionAppServiceGateway _permissionAppServiceGateway; |
|||
|
|||
[Required] |
|||
[HiddenInput] |
|||
[BindProperty(SupportsGet = true)] |
|||
public string ProviderName { get; set; } |
|||
|
|||
[Required] |
|||
[HiddenInput] |
|||
[BindProperty(SupportsGet = true)] |
|||
public string ProviderKey { get; set; } |
|||
|
|||
[BindProperty] |
|||
public List<PermissionGroupViewModel> Groups { get; set; } |
|||
|
|||
public string EntityDisplayName { get; set; } |
|||
|
|||
public PermissionManagementModal(IPermissionAppServiceGateway permissionAppServiceGateway) |
|||
{ |
|||
_permissionAppServiceGateway = permissionAppServiceGateway; |
|||
} |
|||
|
|||
public async Task OnGetAsync() |
|||
{ |
|||
ValidateModel(); |
|||
|
|||
var result = await _permissionAppServiceGateway.GetAsync(ProviderName, ProviderKey); |
|||
|
|||
EntityDisplayName = result.EntityDisplayName; |
|||
|
|||
Groups = ObjectMapper |
|||
.Map<List<PermissionGroupDto>, List<PermissionGroupViewModel>>(result.Groups) |
|||
.OrderBy(g => g.DisplayName) |
|||
.ToList(); |
|||
|
|||
foreach (var group in Groups) |
|||
{ |
|||
new FlatTreeDepthFinder<PermissionGrantInfoViewModel>().SetDepths(group.Permissions); |
|||
} |
|||
} |
|||
|
|||
public async Task<IActionResult> OnPostAsync() |
|||
{ |
|||
ValidateModel(); |
|||
|
|||
var updatePermissionDtos = Groups |
|||
.SelectMany(g => g.Permissions) |
|||
.Select(p => new UpdatePermissionDto |
|||
{ |
|||
Name = p.Name, |
|||
IsGranted = p.IsGranted |
|||
}) |
|||
.ToArray(); |
|||
|
|||
await _permissionAppServiceGateway.UpdateAsync( |
|||
ProviderName, |
|||
ProviderKey, |
|||
new UpdatePermissionsDto |
|||
{ |
|||
Permissions = updatePermissionDtos |
|||
} |
|||
); |
|||
|
|||
return NoContent(); |
|||
} |
|||
|
|||
public class PermissionGroupViewModel |
|||
{ |
|||
public string Name { get; set; } |
|||
|
|||
public string DisplayName { get; set; } |
|||
|
|||
public List<PermissionGrantInfoViewModel> Permissions { get; set; } |
|||
|
|||
public string GetNormalizedGroupName() |
|||
{ |
|||
return Name.Replace(".", "_"); |
|||
} |
|||
} |
|||
|
|||
public class PermissionGrantInfoViewModel : IFlatTreeItem |
|||
{ |
|||
[Required] |
|||
[HiddenInput] |
|||
public string Name { get; set; } |
|||
|
|||
public string DisplayName { get; set; } |
|||
|
|||
public int Depth { get; set; } |
|||
|
|||
public string ParentName { get; set; } |
|||
|
|||
public bool IsGranted { get; set; } |
|||
|
|||
public List<ProviderInfoViewModel> Providers { get; set; } |
|||
|
|||
public bool IsDisabled(string currentProviderName) |
|||
{ |
|||
return IsGranted && Providers.All(p => p.ProviderName != currentProviderName); |
|||
} |
|||
|
|||
public string GetShownName(string currentProviderName) |
|||
{ |
|||
if (!IsDisabled(currentProviderName)) |
|||
{ |
|||
return DisplayName; |
|||
} |
|||
|
|||
return string.Format( |
|||
"{0} <span class=\"text-muted\">({1})</span>", |
|||
DisplayName, |
|||
Providers |
|||
.Where(p => p.ProviderName != currentProviderName) |
|||
.Select(p => p.ProviderName) |
|||
.JoinAsString(", ") |
|||
); |
|||
} |
|||
} |
|||
|
|||
public class ProviderInfoViewModel |
|||
{ |
|||
public string ProviderName { get; set; } |
|||
|
|||
public string ProviderKey { get; set; } |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,2 @@ |
|||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers |
|||
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap |
|||
@ -0,0 +1,27 @@ |
|||
{ |
|||
"iisSettings": { |
|||
"windowsAuthentication": false, |
|||
"anonymousAuthentication": true, |
|||
"iisExpress": { |
|||
"applicationUrl": "http://localhost:55926/", |
|||
"sslPort": 0 |
|||
} |
|||
}, |
|||
"profiles": { |
|||
"IIS Express": { |
|||
"commandName": "IISExpress", |
|||
"launchBrowser": true, |
|||
"environmentVariables": { |
|||
"ASPNETCORE_ENVIRONMENT": "Development" |
|||
} |
|||
}, |
|||
"Volo.Abp.PermissionManagement.Web": { |
|||
"commandName": "Project", |
|||
"launchBrowser": true, |
|||
"environmentVariables": { |
|||
"ASPNETCORE_ENVIRONMENT": "Development" |
|||
}, |
|||
"applicationUrl": "http://localhost:55927/" |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.Web.Utils |
|||
{ |
|||
public class FlatTreeDepthFinder<T> |
|||
where T : class, IFlatTreeItem |
|||
{ |
|||
public void SetDepths(List<T> items) |
|||
{ |
|||
SetDepths(items, null, 0); |
|||
} |
|||
|
|||
private static void SetDepths(List<T> items, string currentParent, int currentDepth) |
|||
{ |
|||
foreach (var item in items) |
|||
{ |
|||
if (item.ParentName == currentParent) |
|||
{ |
|||
item.Depth = currentDepth; |
|||
SetDepths(items, item.Name, currentDepth + 1); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
namespace Volo.Abp.PermissionManagement.Web.Utils |
|||
{ |
|||
public interface IFlatTreeItem |
|||
{ |
|||
string Name { get; } |
|||
|
|||
string ParentName { get; } |
|||
|
|||
int Depth { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk.Web"> |
|||
|
|||
<Import Project="..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<AssemblyName>Volo.Abp.PermissionManagement.Web</AssemblyName> |
|||
<PackageId>Volo.Abp.PermissionManagement.Web</PackageId> |
|||
<IsPackable>true</IsPackable> |
|||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
|||
<OutputType>Library</OutputType> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<EmbeddedResource Include="wwwroot\**\*.*" /> |
|||
<EmbeddedResource Include="Pages\**\*.cshtml" /> |
|||
<EmbeddedResource Include="Localization\Resources\**\*.json" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Volo.Abp.PermissionManagement.Application.Contracts\Volo.Abp.PermissionManagement.Application.Contracts.csproj" /> |
|||
|
|||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.AspNetCore.Mvc.UI.Bootstrap\Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.csproj" /> |
|||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.AutoMapper\Volo.Abp.AutoMapper.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,54 @@ |
|||
var abp = abp || {}; |
|||
(function ($) { |
|||
abp.modals = abp.modals || {}; |
|||
|
|||
abp.modals.PermissionManagement = function () { |
|||
function checkParents($tab, $checkBox) { |
|||
var parentName = $checkBox.closest('.form-check').attr('data-parent-name'); |
|||
if (!parentName) { |
|||
return; |
|||
} |
|||
|
|||
$tab.find('.form-check') |
|||
.filter('[data-permission-name="' + parentName + '"]') |
|||
.find('input[type="checkbox"]') |
|||
.each(function() { |
|||
var $parent = $(this); |
|||
$parent.prop('checked', true); |
|||
checkParents($tab, $parent); |
|||
}); |
|||
} |
|||
|
|||
function uncheckChildren($tab, $checkBox) { |
|||
var permissionName = $checkBox.closest('.form-check').attr('data-permission-name'); |
|||
if (!permissionName) { |
|||
return; |
|||
} |
|||
|
|||
$tab.find('.form-check') |
|||
.filter('[data-parent-name="' + permissionName + '"]') |
|||
.find('input[type="checkbox"]') |
|||
.each(function () { |
|||
var $child = $(this); |
|||
$child.prop('checked', false); |
|||
uncheckChildren($tab, $child); |
|||
}); |
|||
} |
|||
|
|||
this.initDom = function($el) { |
|||
$el.find('.tab-pane').each(function () { |
|||
var $tab = $(this); |
|||
$tab.find('input[type="checkbox"]').each(function () { |
|||
var $checkBox = $(this); |
|||
$checkBox.change(function () { |
|||
if ($checkBox.is(':checked')) { |
|||
checkParents($tab, $checkBox); |
|||
} else { |
|||
uncheckChildren($tab, $checkBox); |
|||
} |
|||
}); |
|||
}); |
|||
}); |
|||
}; |
|||
}; |
|||
})(jQuery); |
|||
@ -0,0 +1,24 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp2.0</TargetFramework> |
|||
<AssemblyName>Volo.Abp.PermissionManagement.EntityFrameworkCore.Tests</AssemblyName> |
|||
<PackageId>Volo.Abp.PermissionManagement.EntityFrameworkCore.Tests</PackageId> |
|||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.PermissionManagement.EntityFrameworkCore\Volo.Abp.PermissionManagement.EntityFrameworkCore.csproj" /> |
|||
<ProjectReference Include="..\Volo.Abp.PermissionManagement.TestBase\Volo.Abp.PermissionManagement.TestBase.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.1.0" /> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,37 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.EntityFrameworkCore |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpPermissionManagementEntityFrameworkCoreModule), |
|||
typeof(AbpPermissionManagementTestBaseModule))] |
|||
public class AbpPermissionManagementEntityFrameworkCoreTestModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddEntityFrameworkInMemoryDatabase(); |
|||
|
|||
var databaseName = Guid.NewGuid().ToString(); |
|||
|
|||
services.Configure<AbpDbContextOptions>(options => |
|||
{ |
|||
options.Configure(context => |
|||
{ |
|||
context.DbContextOptions.UseInMemoryDatabase(databaseName); |
|||
}); |
|||
}); |
|||
|
|||
services.Configure<UnitOfWorkDefaultOptions>(options => |
|||
{ |
|||
options.TransactionBehavior = UnitOfWorkTransactionBehavior.Disabled; //EF in-memory database does not support transactions
|
|||
}); |
|||
|
|||
services.AddAssemblyOf<AbpPermissionManagementEntityFrameworkCoreTestModule>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.PermissionManagement.EntityFrameworkCore |
|||
{ |
|||
public class PermissionGrantRepository_Tests : PermissionGrantRepository_Tests<AbpPermissionManagementEntityFrameworkCoreTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp2.0</TargetFramework> |
|||
<AssemblyName>Volo.Abp.PermissionManagement.MongoDB.Tests</AssemblyName> |
|||
<PackageId>Volo.Abp.PermissionManagement.MongoDB.Tests</PackageId> |
|||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.PermissionManagement.MongoDB\Volo.Abp.PermissionManagement.MongoDB.csproj" /> |
|||
<ProjectReference Include="..\Volo.Abp.PermissionManagement.TestBase\Volo.Abp.PermissionManagement.TestBase.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> |
|||
<PackageReference Include="Mongo2Go" Version="2.2.1" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,33 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Mongo2Go; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.PermissionManagement.MongoDB; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.MongoDb |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpPermissionManagementMongoDbModule), |
|||
typeof(AbpPermissionManagementTestBaseModule))] |
|||
public class AbpPermissionManagementMongoDbTestModule : AbpModule |
|||
{ |
|||
private MongoDbRunner _mongoDbRunner; |
|||
|
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
_mongoDbRunner = MongoDbRunner.Start(); |
|||
|
|||
services.Configure<DbConnectionOptions>(options => |
|||
{ |
|||
options.ConnectionStrings.Default = _mongoDbRunner.ConnectionString; |
|||
}); |
|||
|
|||
services.AddAssemblyOf<AbpPermissionManagementMongoDbTestModule>(); |
|||
} |
|||
|
|||
public override void OnApplicationShutdown(ApplicationShutdownContext context) |
|||
{ |
|||
_mongoDbRunner.Dispose(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.PermissionManagement.MongoDb |
|||
{ |
|||
public class PermissionGrantRepository_Tests : PermissionGrantRepository_Tests<AbpPermissionManagementMongoDbTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp2.0</TargetFramework> |
|||
<AssemblyName>Volo.Abp.PermissionManagement.TestBase</AssemblyName> |
|||
<PackageId>Volo.Abp.PermissionManagement.TestBase</PackageId> |
|||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> |
|||
<ProjectReference Include="..\..\..\abp\src\Volo.Abp.TestBase\Volo.Abp.TestBase.csproj" /> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.PermissionManagement.Domain\Volo.Abp.PermissionManagement.Domain.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> |
|||
<PackageReference Include="NSubstitute" Version="3.1.0" /> |
|||
<PackageReference Include="Shouldly" Version="3.0.0" /> |
|||
<PackageReference Include="xunit" Version="2.3.1" /> |
|||
<PackageReference Include="xunit.extensibility.execution" Version="2.3.1" /> |
|||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,40 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.Autofac; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpPermissionManagementDomainModule), |
|||
typeof(AbpAutofacModule), |
|||
typeof(AbpTestBaseModule) |
|||
)] |
|||
public class AbpPermissionManagementTestBaseModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.Configure<PermissionOptions>(options => |
|||
{ |
|||
options.DefinitionProviders.Add<TestPermissionDefinitionProvider>(); |
|||
}); |
|||
|
|||
services.AddAssemblyOf<AbpPermissionManagementTestBaseModule>(); |
|||
} |
|||
|
|||
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|||
{ |
|||
SeedTestData(context); |
|||
} |
|||
|
|||
private static void SeedTestData(ApplicationInitializationContext context) |
|||
{ |
|||
using (var scope = context.ServiceProvider.CreateScope()) |
|||
{ |
|||
scope.ServiceProvider |
|||
.GetRequiredService<PermissionTestDataBuilder>() |
|||
.Build(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.Modularity; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public abstract class PermissionGrantRepository_Tests<TStartupModule> : PermissionManagementTestBase<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
protected IPermissionGrantRepository PermissionGrantRepository { get; } |
|||
|
|||
protected PermissionGrantRepository_Tests() |
|||
{ |
|||
PermissionGrantRepository = GetRequiredService<IPermissionGrantRepository>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindAsync() |
|||
{ |
|||
(await PermissionGrantRepository.FindAsync("MyPermission1", UserPermissionValueProvider.ProviderName, PermissionTestDataBuilder.User1Id.ToString())).ShouldNotBeNull(); |
|||
|
|||
(await PermissionGrantRepository.FindAsync("Undefined-Permission", UserPermissionValueProvider.ProviderName, PermissionTestDataBuilder.User1Id.ToString())).ShouldBeNull(); |
|||
(await PermissionGrantRepository.FindAsync("MyPermission1", "Undefined-Provider", "Unknown-Id")).ShouldBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetListAsync() |
|||
{ |
|||
var permissionGrants = await PermissionGrantRepository.GetListAsync(UserPermissionValueProvider.ProviderName, PermissionTestDataBuilder.User1Id.ToString()); |
|||
|
|||
permissionGrants.ShouldContain(p => p.Name == "MyPermission1"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public abstract class PermissionManagementTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) |
|||
{ |
|||
options.UseAutofac(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
using System; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Guids; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public class PermissionTestDataBuilder : ITransientDependency |
|||
{ |
|||
public static Guid User1Id { get; } = Guid.NewGuid(); |
|||
public static Guid User2Id { get; } = Guid.NewGuid(); |
|||
|
|||
private readonly IPermissionGrantRepository _permissionGrantRepository; |
|||
private readonly IGuidGenerator _guidGenerator; |
|||
|
|||
public PermissionTestDataBuilder(IGuidGenerator guidGenerator, IPermissionGrantRepository permissionGrantRepository) |
|||
{ |
|||
_guidGenerator = guidGenerator; |
|||
_permissionGrantRepository = permissionGrantRepository; |
|||
} |
|||
|
|||
public void Build() |
|||
{ |
|||
_permissionGrantRepository.Insert( |
|||
new PermissionGrant( |
|||
_guidGenerator.Create(), |
|||
"MyPermission1", |
|||
UserPermissionValueProvider.ProviderName, |
|||
User1Id.ToString() |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
using Volo.Abp.Authorization.Permissions; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public class TestPermissionDefinitionProvider : PermissionDefinitionProvider |
|||
{ |
|||
public override void Define(IPermissionDefinitionContext context) |
|||
{ |
|||
var testGroup = context.AddGroup("TestGroup"); |
|||
|
|||
testGroup.AddPermission("MyPermission1"); |
|||
|
|||
var myPermission2 = testGroup.AddPermission("MyPermission2"); |
|||
myPermission2.AddChild("MyPermission2.ChildPermission1"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp2.0</TargetFramework> |
|||
<AssemblyName>Volo.Abp.PermissionManagement.Tests</AssemblyName> |
|||
<PackageId>Volo.Abp.PermissionManagement.Tests</PackageId> |
|||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.PermissionManagement.EntityFrameworkCore\Volo.Abp.PermissionManagement.EntityFrameworkCore.csproj" /> |
|||
<ProjectReference Include="..\Volo.Abp.PermissionManagement.TestBase\Volo.Abp.PermissionManagement.TestBase.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.1.0" /> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,38 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.PermissionManagement.EntityFrameworkCore; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpPermissionManagementEntityFrameworkCoreModule), |
|||
typeof(AbpPermissionManagementTestBaseModule))] |
|||
public class AbpPermissionManagementTestModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddEntityFrameworkInMemoryDatabase(); |
|||
|
|||
var databaseName = Guid.NewGuid().ToString(); |
|||
|
|||
services.Configure<AbpDbContextOptions>(options => |
|||
{ |
|||
options.Configure(context => |
|||
{ |
|||
context.DbContextOptions.UseInMemoryDatabase(databaseName); |
|||
}); |
|||
}); |
|||
|
|||
services.Configure<UnitOfWorkDefaultOptions>(options => |
|||
{ |
|||
options.TransactionBehavior = UnitOfWorkTransactionBehavior.Disabled; //EF in-memory database does not support transactions
|
|||
}); |
|||
|
|||
services.AddAssemblyOf<AbpPermissionManagementTestModule>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,59 @@ |
|||
using System; |
|||
using System.Security.Claims; |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Volo.Abp.Security.Claims; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public class PermissionChecker_User_Tests : PermissionTestBase |
|||
{ |
|||
private readonly IPermissionChecker _permissionChecker; |
|||
|
|||
public PermissionChecker_User_Tests() |
|||
{ |
|||
_permissionChecker = GetRequiredService<IPermissionChecker>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Return_True_For_Granted_Current_User() |
|||
{ |
|||
(await _permissionChecker.IsGrantedAsync( |
|||
CreatePrincipal(PermissionTestDataBuilder.User1Id), |
|||
"MyPermission1" |
|||
)).ShouldBeTrue(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Return_False_For_Non_Granted_Current_User() |
|||
{ |
|||
(await _permissionChecker.IsGrantedAsync( |
|||
CreatePrincipal(PermissionTestDataBuilder.User2Id), |
|||
"MyPermission1" |
|||
)).ShouldBeFalse(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Return_False_For_Current_User_If_Anonymous() |
|||
{ |
|||
(await _permissionChecker.IsGrantedAsync( |
|||
CreatePrincipal(null), |
|||
"MyPermission1" |
|||
)).ShouldBeFalse(); |
|||
} |
|||
|
|||
private static ClaimsPrincipal CreatePrincipal(Guid? userId) |
|||
{ |
|||
var claimsIdentity = new ClaimsIdentity(); |
|||
|
|||
if (userId != null) |
|||
{ |
|||
claimsIdentity.AddClaim(new Claim(AbpClaimTypes.UserId, userId.ToString())); |
|||
} |
|||
|
|||
return new ClaimsPrincipal(claimsIdentity); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Authorization.Permissions; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public class PermissionChecker_Basic_Tests : PermissionTestBase |
|||
{ |
|||
private readonly IPermissionChecker _permissionChecker; |
|||
|
|||
public PermissionChecker_Basic_Tests() |
|||
{ |
|||
_permissionChecker = GetRequiredService<IPermissionChecker>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Throw_Exception_If_Permission_Is_Not_Defined() |
|||
{ |
|||
await Assert.ThrowsAsync<AbpException>(async () => |
|||
await _permissionChecker.IsGrantedAsync("UndefinedPermissionName") |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Return_False_As_Default_For_Any_Permission() |
|||
{ |
|||
(await _permissionChecker.IsGrantedAsync("MyPermission1")).ShouldBeFalse(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,24 @@ |
|||
using System; |
|||
using Volo.Abp.PermissionManagement.EntityFrameworkCore; |
|||
|
|||
namespace Volo.Abp.PermissionManagement |
|||
{ |
|||
public abstract class PermissionTestBase : PermissionManagementTestBase<AbpPermissionManagementTestModule> |
|||
{ |
|||
protected virtual void UsingDbContext(Action<IPermissionManagementDbContext> action) |
|||
{ |
|||
using (var dbContext = GetRequiredService<IPermissionManagementDbContext>()) |
|||
{ |
|||
action.Invoke(dbContext); |
|||
} |
|||
} |
|||
|
|||
protected virtual T UsingDbContext<T>(Func<IPermissionManagementDbContext, T> action) |
|||
{ |
|||
using (var dbContext = GetRequiredService<IPermissionManagementDbContext>()) |
|||
{ |
|||
return action.Invoke(dbContext); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue