Added layers for permission system.

pull/206/head
Halil İbrahim Kalkan 7 years ago
parent 9ec8ccf80d
commit 5ddcdc27fd

@ -260,6 +260,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Abp.Settings", "Abp.Setting
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Permissions", "src\Volo.Abp.Permissions\Volo.Abp.Permissions.csproj", "{0FDD21F9-9E73-4DB5-8356-A110D3FBDB1D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Abp.Permissions", "Abp.Permissions", "{055F4AC0-46C4-4E99-89CD-0F30D4A97382}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Permissions.Domain", "src\Volo.Abp.Permissions.Domain\Volo.Abp.Permissions.Domain.csproj", "{D77E0662-8404-43C5-9C46-6289EA207A40}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Permissions.Domain.Shared", "src\Volo.Abp.Permissions.Domain.Shared\Volo.Abp.Permissions.Domain.Shared.csproj", "{E4D0326C-515D-46FA-AF7E-1AC32155BD03}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Permissions.EntityFrameworkCore", "src\Volo.Abp.Permissions.EntityFrameworkCore\Volo.Abp.Permissions.EntityFrameworkCore.csproj", "{2300E155-2621-4FCF-BD44-B61BA5A92B82}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -678,6 +686,18 @@ Global
{0FDD21F9-9E73-4DB5-8356-A110D3FBDB1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0FDD21F9-9E73-4DB5-8356-A110D3FBDB1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0FDD21F9-9E73-4DB5-8356-A110D3FBDB1D}.Release|Any CPU.Build.0 = Release|Any CPU
{D77E0662-8404-43C5-9C46-6289EA207A40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D77E0662-8404-43C5-9C46-6289EA207A40}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D77E0662-8404-43C5-9C46-6289EA207A40}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D77E0662-8404-43C5-9C46-6289EA207A40}.Release|Any CPU.Build.0 = Release|Any CPU
{E4D0326C-515D-46FA-AF7E-1AC32155BD03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4D0326C-515D-46FA-AF7E-1AC32155BD03}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4D0326C-515D-46FA-AF7E-1AC32155BD03}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4D0326C-515D-46FA-AF7E-1AC32155BD03}.Release|Any CPU.Build.0 = Release|Any CPU
{2300E155-2621-4FCF-BD44-B61BA5A92B82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2300E155-2621-4FCF-BD44-B61BA5A92B82}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2300E155-2621-4FCF-BD44-B61BA5A92B82}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2300E155-2621-4FCF-BD44-B61BA5A92B82}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -804,6 +824,10 @@ Global
{27F990E2-6820-4159-B54A-59C8ADED8D28} = {D62B8D43-B8D9-4FC6-97E2-DC54CD765915}
{D62B8D43-B8D9-4FC6-97E2-DC54CD765915} = {3B481ACC-5BB3-4189-880C-5F7A27EAEB70}
{0FDD21F9-9E73-4DB5-8356-A110D3FBDB1D} = {4C753F64-0C93-4D65-96C2-A40893AFC1E8}
{055F4AC0-46C4-4E99-89CD-0F30D4A97382} = {3B481ACC-5BB3-4189-880C-5F7A27EAEB70}
{D77E0662-8404-43C5-9C46-6289EA207A40} = {055F4AC0-46C4-4E99-89CD-0F30D4A97382}
{E4D0326C-515D-46FA-AF7E-1AC32155BD03} = {055F4AC0-46C4-4E99-89CD-0F30D4A97382}
{2300E155-2621-4FCF-BD44-B61BA5A92B82} = {055F4AC0-46C4-4E99-89CD-0F30D4A97382}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5}

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\common.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Volo.Abp.Permissions.Domain.Shared</AssemblyName>
<PackageId>Volo.Abp.Permissions.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="..\Volo.Abp.Core\Volo.Abp.Core.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,13 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Modularity;
namespace Volo.Abp.Permissions
{
public class AbpPermissionsDomainSharedModule : AbpModule
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddAssemblyOf<AbpPermissionsDomainSharedModule>();
}
}
}

@ -0,0 +1,11 @@
namespace Volo.Abp.Permissions
{
public static class PermissionGrantConsts
{
public const int MaxNameLength = 128;
public const int MaxProviderNameLength = 64;
public const int MaxProviderKeyLength = 64;
}
}

@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\common.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Volo.Abp.Permissions.Domain</AssemblyName>
<PackageId>Volo.Abp.Permissions.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.Ddd\Volo.Abp.Ddd.csproj" />
<ProjectReference Include="..\Volo.Abp.Permissions.Domain.Shared\Volo.Abp.Permissions.Domain.Shared.csproj" />
<ProjectReference Include="..\Volo.Abp.Permissions\Volo.Abp.Permissions.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,16 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Modularity;
namespace Volo.Abp.Permissions
{
[DependsOn(typeof(AbpPermissionsModule))]
[DependsOn(typeof(AbpDddModule))]
[DependsOn(typeof(AbpPermissionsDomainSharedModule))]
public class AbpPermissionsDomainModule : AbpModule
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddAssemblyOf<AbpPermissionsDomainModule>();
}
}
}

@ -0,0 +1,9 @@
namespace Volo.Abp.Permissions
{
public static class AbpPermissionConsts
{
public const string DefaultDbTablePrefix = "Abp";
public const string DefaultDbSchema = null;
}
}

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
namespace Volo.Abp.Permissions
{
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,41 @@
using System;
using JetBrains.Annotations;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.Permissions
{
public class PermissionGrant : Entity<Guid>
{
[NotNull]
public virtual string Name { get; protected set; }
public virtual bool IsGranted { get; internal set; }
[CanBeNull]
public virtual string ProviderName { get; protected set; }
[CanBeNull]
public virtual string ProviderKey { get; protected set; }
protected PermissionGrant()
{
}
public PermissionGrant(
Guid id,
[NotNull] string name,
bool isGranted,
[CanBeNull] string providerName = null,
[CanBeNull] string providerKey = null)
{
Check.NotNull(name, nameof(name));
Id = id;
Name = name;
IsGranted = isGranted;
ProviderName = providerName;
ProviderKey = providerKey;
}
}
}

@ -0,0 +1,53 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Permissions
{
public class PermissionStore : AbpServiceBase, IPermissionStore, ITransientDependency
{
private readonly IPermissionGrantRepository _permissionGrantRepository;
public PermissionStore(IPermissionGrantRepository permissionGrantRepository)
{
_permissionGrantRepository = permissionGrantRepository;
}
public async Task<bool?> IsGrantedAsync(string name, string providerName, string providerKey)
{
var permissionGrant = await _permissionGrantRepository.FindAsync(name, providerName, providerKey);
return permissionGrant?.IsGranted;
}
public async Task SetAsync(string name, bool isGranted, string providerName, string providerKey)
{
var permissionGrant = await _permissionGrantRepository.FindAsync(name, providerName, providerKey);
if (permissionGrant == null)
{
permissionGrant = new PermissionGrant(GuidGenerator.Create(), name, isGranted, providerName, providerKey);
await _permissionGrantRepository.InsertAsync(permissionGrant);
}
else
{
permissionGrant.IsGranted = isGranted;
await _permissionGrantRepository.UpdateAsync(permissionGrant);
}
}
public async Task<List<PermissionGrantInfo>> GetListAsync(string providerName, string providerKey)
{
var permissionGrants = await _permissionGrantRepository.GetListAsync(providerName, providerKey);
return permissionGrants.Select(s => new PermissionGrantInfo(s.Name, s.IsGranted)).ToList();
}
public async Task DeleteAsync(string name, string providerName, string providerKey)
{
var permissionGrant = await _permissionGrantRepository.FindAsync(name, providerName, providerKey);
if (permissionGrant != null)
{
await _permissionGrantRepository.DeleteAsync(permissionGrant);
}
}
}
}

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\common.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Volo.Abp.Permissions.EntityFrameworkCore</AssemblyName>
<PackageId>Volo.Abp.Permissions.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.EntityFrameworkCore\Volo.Abp.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\Volo.Abp.Permissions.Domain\Volo.Abp.Permissions.Domain.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
namespace Volo.Abp.Permissions.EntityFrameworkCore
{
[ConnectionStringName("AbpPermissions")]
public class AbpPermissionsDbContext : AbpDbContext<AbpPermissionsDbContext>, IAbpPermissionsDbContext
{
public static string TablePrefix { get; set; } = AbpPermissionConsts.DefaultDbTablePrefix;
public static string Schema { get; set; } = AbpPermissionConsts.DefaultDbSchema;
public DbSet<PermissionGrant> PermissionGrants { get; set; }
public AbpPermissionsDbContext(DbContextOptions<AbpPermissionsDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.ConfigureAbpPermissions(TablePrefix, Schema);
}
}
}

@ -0,0 +1,33 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
namespace Volo.Abp.Permissions.EntityFrameworkCore
{
public static class AbpPermissionsDbContextModelBuilderExtensions
{
public static void ConfigureAbpPermissions(
[NotNull] this ModelBuilder builder,
[CanBeNull] string tablePrefix = AbpPermissionConsts.DefaultDbTablePrefix,
[CanBeNull] string schema = AbpPermissionConsts.DefaultDbSchema)
{
Check.NotNull(builder, nameof(builder));
if (tablePrefix == null)
{
tablePrefix = "";
}
builder.Entity<PermissionGrant>(b =>
{
b.ToTable(tablePrefix + "Permissions", schema);
b.Property(x => x.Name).HasMaxLength(PermissionGrantConsts.MaxNameLength).IsRequired();
b.Property(x => x.IsGranted).IsRequired().HasDefaultValue(true);
b.Property(x => x.ProviderName).HasMaxLength(PermissionGrantConsts.MaxProviderNameLength);
b.Property(x => x.ProviderKey).HasMaxLength(PermissionGrantConsts.MaxProviderKeyLength);
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.Permissions.EntityFrameworkCore
{
[DependsOn(typeof(AbpPermissionsDomainModule))]
[DependsOn(typeof(AbpEntityFrameworkCoreModule))]
public class AbpPermissionsEntityFrameworkCoreModule : AbpModule
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddAbpDbContext<AbpPermissionsDbContext>(options =>
{
options.AddDefaultRepositories<IAbpPermissionsDbContext>();
options.AddRepository<PermissionGrant, EfCorePermissionGrantRepository>();
});
services.AddAssemblyOf<AbpPermissionsEntityFrameworkCoreModule>();
}
}
}

@ -0,0 +1,29 @@
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.Permissions.EntityFrameworkCore
{
public class EfCorePermissionGrantRepository : EfCoreRepository<IAbpPermissionsDbContext, PermissionGrant, Guid>, IPermissionGrantRepository
{
public EfCorePermissionGrantRepository(IDbContextProvider<IAbpPermissionsDbContext> 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,10 @@
using Microsoft.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
namespace Volo.Abp.Permissions.EntityFrameworkCore
{
public interface IAbpPermissionsDbContext : IEfCoreDbContext
{
DbSet<PermissionGrant> PermissionGrants { get; set; }
}
}

@ -6,7 +6,7 @@ namespace Volo.Abp.Permissions
{
public interface IPermissionStore
{
Task<bool?> GetOrNullAsync([NotNull] string name, [CanBeNull] string providerName, [CanBeNull] string providerKey);
Task<bool?> IsGrantedAsync([NotNull] string name, [CanBeNull] string providerName, [CanBeNull] string providerKey);
Task SetAsync([NotNull] string name, bool isGranted, [CanBeNull] string providerName, [CanBeNull] string providerKey);

@ -15,7 +15,7 @@ namespace Volo.Abp.Permissions
Logger = NullLogger<NullPermissionStore>.Instance;
}
public Task<bool?> GetOrNullAsync(string name, string providerName, string providerKey)
public Task<bool?> IsGrantedAsync(string name, string providerName, string providerKey)
{
return Task.FromResult((bool?)null);
}

@ -28,15 +28,17 @@ namespace Volo.Abp.Settings
setting = new Setting(GuidGenerator.Create(), name, value, providerName, providerKey);
await _settingRepository.InsertAsync(setting);
}
setting.Value = value;
await _settingRepository.UpdateAsync(setting);
else
{
setting.Value = value;
await _settingRepository.UpdateAsync(setting);
}
}
public async Task<List<SettingValue>> GetListAsync(string providerName, string providerKey)
{
var setting = await _settingRepository.GetListAsync(providerName, providerKey);
return setting.Select(s => new SettingValue(s.Name, s.Value)).ToList();
var settings = await _settingRepository.GetListAsync(providerName, providerKey);
return settings.Select(s => new SettingValue(s.Name, s.Value)).ToList();
}
public async Task DeleteAsync(string name, string providerName, string providerKey)

Loading…
Cancel
Save