1
0
mirror of https://github.com/bitwarden/server.git synced 2025-01-07 19:37:51 +01:00

Make policyDefinitions dict immutable

This commit is contained in:
Thomas Rittson 2024-10-04 13:55:23 +10:00
parent 8ffadc09e5
commit 9d75bcbc86
No known key found for this signature in database
GPG Key ID: CDDDA03861C35E27

View File

@ -1,5 +1,6 @@
#nullable enable #nullable enable
using System.Collections.Immutable;
using Bit.Core.AdminConsole.Entities; using Bit.Core.AdminConsole.Entities;
using Bit.Core.AdminConsole.Enums; using Bit.Core.AdminConsole.Enums;
using Bit.Core.AdminConsole.Models.Data.Organizations.Policies; using Bit.Core.AdminConsole.Models.Data.Organizations.Policies;
@ -20,7 +21,7 @@ public class PolicyServicevNext : IPolicyServicevNext
private readonly IApplicationCacheService _applicationCacheService; private readonly IApplicationCacheService _applicationCacheService;
private readonly IEventService _eventService; private readonly IEventService _eventService;
private readonly IPolicyRepository _policyRepository; private readonly IPolicyRepository _policyRepository;
private readonly Dictionary<PolicyType, IPolicyDefinition> _policyDefinitions = new(); private readonly IReadOnlyDictionary<PolicyType, IPolicyDefinition> _policyDefinitions;
public PolicyServicevNext( public PolicyServicevNext(
IApplicationCacheService applicationCacheService, IApplicationCacheService applicationCacheService,
@ -32,10 +33,9 @@ public class PolicyServicevNext : IPolicyServicevNext
_eventService = eventService; _eventService = eventService;
_policyRepository = policyRepository; _policyRepository = policyRepository;
foreach (var policyDefinition in policyDefinitions) _policyDefinitions = ImmutableDictionary.CreateRange(
{ policyDefinitions.Select(def => KeyValuePair.Create(def.Type, def))
_policyDefinitions.Add(policyDefinition.Type, policyDefinition); );
}
} }
public async Task SaveAsync(Policy policy, IUserService userService, IOrganizationService organizationService, public async Task SaveAsync(Policy policy, IUserService userService, IOrganizationService organizationService,