mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
Use the correct policy enum type (#2045)
Explicit conversion from non-generics to generics doesn't seem to work here, so I moved to using the read methods already on base Policy.
This commit is contained in:
@ -182,10 +182,10 @@ namespace Bit.Api.Controllers
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
var masterPasswordPolicy = await _policyRepository.GetByOrganizationIdTypeAsync<ResetPasswordDataModel>(orgId, PolicyType.MasterPassword);
|
||||
var masterPasswordPolicy = await _policyRepository.GetByOrganizationIdTypeAsync(orgId, PolicyType.ResetPassword);
|
||||
var useMasterPasswordPolicy = masterPasswordPolicy != null &&
|
||||
masterPasswordPolicy.Enabled &&
|
||||
masterPasswordPolicy.DataModel.AutoEnrollEnabled;
|
||||
masterPasswordPolicy.GetDataModel<ResetPasswordDataModel>().AutoEnrollEnabled;
|
||||
|
||||
if (useMasterPasswordPolicy &&
|
||||
string.IsNullOrWhiteSpace(model.ResetPasswordKey))
|
||||
|
@ -30,13 +30,4 @@ namespace Bit.Core.Entities
|
||||
Data = CoreHelpers.ClassToJsonData(dataModel);
|
||||
}
|
||||
}
|
||||
|
||||
public class Policy<T> : Policy where T : IPolicyDataModel, new()
|
||||
{
|
||||
public T DataModel
|
||||
{
|
||||
get => GetDataModel<T>();
|
||||
set => SetDataModel(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ namespace Bit.Core.Repositories
|
||||
public interface IPolicyRepository : IRepository<Policy, Guid>
|
||||
{
|
||||
Task<Policy> GetByOrganizationIdTypeAsync(Guid organizationId, PolicyType type);
|
||||
Task<Policy<T>> GetByOrganizationIdTypeAsync<T>(Guid organizationId, PolicyType type) where T : IPolicyDataModel, new();
|
||||
Task<ICollection<Policy>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||
Task<ICollection<Policy>> GetManyByUserIdAsync(Guid userId);
|
||||
Task<ICollection<Policy>> GetManyByTypeApplicableToUserIdAsync(Guid userId, PolicyType policyType,
|
||||
|
@ -23,8 +23,6 @@ namespace Bit.Infrastructure.Dapper.Repositories
|
||||
: base(connectionString, readOnlyConnectionString)
|
||||
{ }
|
||||
|
||||
public async Task<Policy<T>> GetByOrganizationIdTypeAsync<T>(Guid organizationId, PolicyType type) where T : IPolicyDataModel, new() =>
|
||||
(Policy<T>)await GetByOrganizationIdTypeAsync(organizationId, type);
|
||||
public async Task<Policy> GetByOrganizationIdTypeAsync(Guid organizationId, PolicyType type)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
|
@ -19,8 +19,6 @@ namespace Bit.Infrastructure.EntityFramework.Repositories
|
||||
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.Policies)
|
||||
{ }
|
||||
|
||||
public async Task<Core.Entities.Policy<T>> GetByOrganizationIdTypeAsync<T>(Guid organizationId, PolicyType type) where T : IPolicyDataModel, new() =>
|
||||
(Core.Entities.Policy<T>)await GetByOrganizationIdTypeAsync(organizationId, type);
|
||||
public async Task<Core.Entities.Policy> GetByOrganizationIdTypeAsync(Guid organizationId, PolicyType type)
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
|
Reference in New Issue
Block a user