mirror of https://github.com/abpframework/abp.git
4 changed files with 155 additions and 0 deletions
@ -0,0 +1,74 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.EntityFrameworkCore; |
|||
|
|||
public class EfCoreResourcePermissionGrantRepository : EfCoreRepository<IPermissionManagementDbContext, ResourcePermissionGrant, Guid>, IResourcePermissionGrantRepository |
|||
{ |
|||
public EfCoreResourcePermissionGrantRepository(IDbContextProvider<IPermissionManagementDbContext> dbContextProvider) |
|||
: base(dbContextProvider) |
|||
{ |
|||
|
|||
} |
|||
|
|||
public virtual async Task<ResourcePermissionGrant> FindAsync(string name, string resourceName, string resourceKey, string providerName, string providerKey, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.OrderBy(x => x.Id) |
|||
.FirstOrDefaultAsync(s => |
|||
s.Name == name && |
|||
s.ResourceName == resourceName && |
|||
s.ResourceKey == resourceKey && |
|||
s.ProviderName == providerName && |
|||
s.ProviderKey == providerKey, |
|||
GetCancellationToken(cancellationToken) |
|||
); |
|||
} |
|||
|
|||
public virtual async Task<List<ResourcePermissionGrant>> GetListAsync(string resourceName, string resourceKey, string providerName, string providerKey, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.Where(s => |
|||
s.ResourceName == resourceName && |
|||
s.ResourceKey == resourceKey && |
|||
s.ProviderName == providerName && |
|||
s.ProviderKey == providerKey |
|||
).ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<ResourcePermissionGrant>> GetListAsync(string[] names, string resourceName, string resourceKey, string providerName, string providerKey, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.Where(s => |
|||
names.Contains(s.Name) && |
|||
s.ResourceName == resourceName && |
|||
s.ResourceKey == resourceKey && |
|||
s.ProviderName == providerName && |
|||
s.ProviderKey == providerKey |
|||
).ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<string>> GetPermissionsAsync(string resourceName, string resourceKey, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.Where(s => |
|||
s.ResourceName == resourceName && |
|||
s.ResourceKey == resourceKey |
|||
).Select(x => x.Name).ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
|
|||
public virtual async Task<List<string>> GetResourceKeys(string resourceName, string name, CancellationToken cancellationToken = default) |
|||
{ |
|||
return await (await GetDbSetAsync()) |
|||
.Where(s => |
|||
s.ResourceName == resourceName && |
|||
s.Name == name |
|||
).Select(x => x.ResourceKey).ToListAsync(GetCancellationToken(cancellationToken)); |
|||
} |
|||
} |
|||
@ -0,0 +1,79 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using MongoDB.Driver.Linq; |
|||
using Volo.Abp.Domain.Repositories.MongoDB; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.PermissionManagement.MongoDB; |
|||
|
|||
public class MongoResourcePermissionGrantRepository : MongoDbRepository<IPermissionManagementMongoDbContext, ResourcePermissionGrant, Guid>, IResourcePermissionGrantRepository |
|||
{ |
|||
public MongoResourcePermissionGrantRepository(IMongoDbContextProvider<IPermissionManagementMongoDbContext> dbContextProvider) |
|||
: base(dbContextProvider) |
|||
{ |
|||
|
|||
} |
|||
|
|||
public virtual async Task<ResourcePermissionGrant> FindAsync(string name, string resourceName, string resourceKey, string providerName, string providerKey, CancellationToken cancellationToken = default) |
|||
{ |
|||
cancellationToken = GetCancellationToken(cancellationToken); |
|||
return await (await GetQueryableAsync(cancellationToken)) |
|||
.OrderBy(x => x.Id) |
|||
.FirstOrDefaultAsync(s => |
|||
s.Name == name && |
|||
s.ResourceName == resourceName && |
|||
s.ResourceKey == resourceKey && |
|||
s.ProviderName == providerName && |
|||
s.ProviderKey == providerKey, |
|||
cancellationToken |
|||
); |
|||
} |
|||
|
|||
public virtual async Task<List<ResourcePermissionGrant>> GetListAsync(string resourceName, string resourceKey, string providerName, string providerKey, CancellationToken cancellationToken = default) |
|||
{ |
|||
cancellationToken = GetCancellationToken(cancellationToken); |
|||
return await (await GetQueryableAsync(cancellationToken)) |
|||
.Where(s => |
|||
s.ResourceName == resourceName && |
|||
s.ResourceKey == resourceKey && |
|||
s.ProviderName == providerName && |
|||
s.ProviderKey == providerKey |
|||
).ToListAsync(cancellationToken); |
|||
} |
|||
|
|||
public virtual async Task<List<ResourcePermissionGrant>> GetListAsync(string[] names, string resourceName, string resourceKey, string providerName, string providerKey, CancellationToken cancellationToken = default) |
|||
{ |
|||
cancellationToken = GetCancellationToken(cancellationToken); |
|||
return await (await GetQueryableAsync(cancellationToken)) |
|||
.Where(s => |
|||
names.AsEnumerable().Contains(s.Name) && |
|||
s.ResourceName == resourceName && |
|||
s.ResourceKey == resourceKey && |
|||
s.ProviderName == providerName && |
|||
s.ProviderKey == providerKey |
|||
).ToListAsync(cancellationToken); |
|||
} |
|||
|
|||
public virtual async Task<List<string>> GetPermissionsAsync(string resourceName, string resourceKey, CancellationToken cancellationToken = default) |
|||
{ |
|||
cancellationToken = GetCancellationToken(cancellationToken); |
|||
return await (await GetQueryableAsync(cancellationToken)) |
|||
.Where(s => |
|||
s.ResourceName == resourceName && |
|||
s.ResourceKey == resourceKey |
|||
).Select(x => x.Name).ToListAsync(cancellationToken); |
|||
} |
|||
|
|||
public virtual async Task<List<string>> GetResourceKeys(string resourceName, string name, CancellationToken cancellationToken = default) |
|||
{ |
|||
cancellationToken = GetCancellationToken(cancellationToken); |
|||
return await (await GetQueryableAsync(cancellationToken)) |
|||
.Where(s => |
|||
s.ResourceName == resourceName && |
|||
s.Name == name |
|||
).Select(x => x.ResourceKey).ToListAsync(cancellationToken); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue