mirror of https://github.com/abpframework/abp.git
20 changed files with 376 additions and 7 deletions
@ -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; } |
|||
} |
|||
} |
|||
Loading…
Reference in new issue