mirror of
https://github.com/bitwarden/server.git
synced 2026-02-02 15:13:19 +08:00
Turn on file scoped namespaces (#2225)
This commit is contained in:
@@ -6,72 +6,71 @@ using Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories;
|
||||
|
||||
public class PolicyRepository : Repository<Core.Entities.Policy, Policy, Guid>, IPolicyRepository
|
||||
{
|
||||
public class PolicyRepository : Repository<Core.Entities.Policy, Policy, Guid>, IPolicyRepository
|
||||
public PolicyRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
|
||||
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.Policies)
|
||||
{ }
|
||||
|
||||
public async Task<Core.Entities.Policy> GetByOrganizationIdTypeAsync(Guid organizationId, PolicyType type)
|
||||
{
|
||||
public PolicyRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
|
||||
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.Policies)
|
||||
{ }
|
||||
|
||||
public async Task<Core.Entities.Policy> GetByOrganizationIdTypeAsync(Guid organizationId, PolicyType type)
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var results = await dbContext.Policies
|
||||
.FirstOrDefaultAsync(p => p.OrganizationId == organizationId && p.Type == type);
|
||||
return Mapper.Map<Core.Entities.Policy>(results);
|
||||
}
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var results = await dbContext.Policies
|
||||
.FirstOrDefaultAsync(p => p.OrganizationId == organizationId && p.Type == type);
|
||||
return Mapper.Map<Core.Entities.Policy>(results);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<Core.Entities.Policy>> GetManyByOrganizationIdAsync(Guid organizationId)
|
||||
public async Task<ICollection<Core.Entities.Policy>> GetManyByOrganizationIdAsync(Guid organizationId)
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var results = await dbContext.Policies
|
||||
.Where(p => p.OrganizationId == organizationId)
|
||||
.ToListAsync();
|
||||
return Mapper.Map<List<Core.Entities.Policy>>(results);
|
||||
}
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var results = await dbContext.Policies
|
||||
.Where(p => p.OrganizationId == organizationId)
|
||||
.ToListAsync();
|
||||
return Mapper.Map<List<Core.Entities.Policy>>(results);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<Core.Entities.Policy>> GetManyByUserIdAsync(Guid userId)
|
||||
public async Task<ICollection<Core.Entities.Policy>> GetManyByUserIdAsync(Guid userId)
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
|
||||
var query = new PolicyReadByUserIdQuery(userId);
|
||||
var results = await query.Run(dbContext).ToListAsync();
|
||||
return Mapper.Map<List<Core.Entities.Policy>>(results);
|
||||
}
|
||||
var query = new PolicyReadByUserIdQuery(userId);
|
||||
var results = await query.Run(dbContext).ToListAsync();
|
||||
return Mapper.Map<List<Core.Entities.Policy>>(results);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ICollection<Core.Entities.Policy>> GetManyByTypeApplicableToUserIdAsync(Guid userId, PolicyType policyType,
|
||||
OrganizationUserStatusType minStatus)
|
||||
public async Task<ICollection<Core.Entities.Policy>> GetManyByTypeApplicableToUserIdAsync(Guid userId, PolicyType policyType,
|
||||
OrganizationUserStatusType minStatus)
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
|
||||
var query = new PolicyReadByTypeApplicableToUserQuery(userId, policyType, minStatus);
|
||||
var results = await query.Run(dbContext).ToListAsync();
|
||||
return Mapper.Map<List<Core.Entities.Policy>>(results);
|
||||
}
|
||||
var query = new PolicyReadByTypeApplicableToUserQuery(userId, policyType, minStatus);
|
||||
var results = await query.Run(dbContext).ToListAsync();
|
||||
return Mapper.Map<List<Core.Entities.Policy>>(results);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> GetCountByTypeApplicableToUserIdAsync(Guid userId, PolicyType policyType,
|
||||
OrganizationUserStatusType minStatus)
|
||||
public async Task<int> GetCountByTypeApplicableToUserIdAsync(Guid userId, PolicyType policyType,
|
||||
OrganizationUserStatusType minStatus)
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
|
||||
var query = new PolicyReadByTypeApplicableToUserQuery(userId, policyType, minStatus);
|
||||
return await GetCountFromQuery(query);
|
||||
}
|
||||
var query = new PolicyReadByTypeApplicableToUserQuery(userId, policyType, minStatus);
|
||||
return await GetCountFromQuery(query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user