mirror of
https://github.com/bitwarden/server.git
synced 2025-04-28 08:12:22 -05:00

* add new classes * initial commit * revert the changes on this files Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * revert unnecessary changes * Add a model * add the delete token endpoint * add a unit test for delete provider Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * add the delete provider method Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * resolve the failing test Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * resolve the delete request redirect issue Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * changes to correct the json issue Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * resolve errors Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * resolve pr comment Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * move ProviderDeleteTokenable to the adminConsole Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * Add feature flag * resolve pr comments Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * add some unit test Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * resolve the failing test Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * resolve test Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * add the remove feature flag Signed-off-by: Cy Okeke <cokeke@bitwarden.com> * [AC-2378] Added `ProviderId` to PayPal transaction model (#3995) * Added ProviderId to PayPal transaction model * Fixed issue with parsing provider id * [AC-1923] Add endpoint to create client organization (#3977) * Add new endpoint for creating client organizations in consolidated billing * Create empty org and then assign seats for code re-use * Fixes made from debugging client side * few more small fixes * Vincent's feedback * Bumped version to 2024.4.1 (#3997) * [AC-1923] Add endpoint to create client organization (#3977) * Add new endpoint for creating client organizations in consolidated billing * Create empty org and then assign seats for code re-use * Fixes made from debugging client side * few more small fixes * Vincent's feedback * [AC-1923] Add endpoint to create client organization (#3977) * Add new endpoint for creating client organizations in consolidated billing * Create empty org and then assign seats for code re-use * Fixes made from debugging client side * few more small fixes * Vincent's feedback * add changes after merge conflict Signed-off-by: Cy Okeke <cokeke@bitwarden.com> --------- Signed-off-by: Cy Okeke <cokeke@bitwarden.com> Co-authored-by: Conner Turnbull <133619638+cturnbull-bitwarden@users.noreply.github.com> Co-authored-by: Alex Morask <144709477+amorask-bitwarden@users.noreply.github.com> Co-authored-by: Bitwarden DevOps <106330231+bitwarden-devops-bot@users.noreply.github.com>
120 lines
3.8 KiB
C#
120 lines
3.8 KiB
C#
using Bit.Core.AdminConsole.Entities;
|
|
using Bit.Core.AdminConsole.Entities.Provider;
|
|
using Bit.Core.AdminConsole.Models.Data.Provider;
|
|
using Bit.Core.AdminConsole.Repositories;
|
|
using Bit.Core.Models.Data.Organizations;
|
|
using Bit.Core.Repositories;
|
|
|
|
namespace Bit.Core.Services;
|
|
|
|
public class InMemoryApplicationCacheService : IApplicationCacheService
|
|
{
|
|
private readonly IOrganizationRepository _organizationRepository;
|
|
private readonly IProviderRepository _providerRepository;
|
|
private DateTime _lastOrgAbilityRefresh = DateTime.MinValue;
|
|
private IDictionary<Guid, OrganizationAbility> _orgAbilities;
|
|
private TimeSpan _orgAbilitiesRefreshInterval = TimeSpan.FromMinutes(10);
|
|
|
|
private IDictionary<Guid, ProviderAbility> _providerAbilities;
|
|
|
|
public InMemoryApplicationCacheService(
|
|
IOrganizationRepository organizationRepository, IProviderRepository providerRepository)
|
|
{
|
|
_organizationRepository = organizationRepository;
|
|
_providerRepository = providerRepository;
|
|
}
|
|
|
|
public virtual async Task<IDictionary<Guid, OrganizationAbility>> GetOrganizationAbilitiesAsync()
|
|
{
|
|
await InitOrganizationAbilitiesAsync();
|
|
return _orgAbilities;
|
|
}
|
|
|
|
#nullable enable
|
|
public async Task<OrganizationAbility?> GetOrganizationAbilityAsync(Guid organizationId)
|
|
{
|
|
(await GetOrganizationAbilitiesAsync())
|
|
.TryGetValue(organizationId, out var organizationAbility);
|
|
return organizationAbility;
|
|
}
|
|
#nullable disable
|
|
|
|
public virtual async Task<IDictionary<Guid, ProviderAbility>> GetProviderAbilitiesAsync()
|
|
{
|
|
await InitProviderAbilitiesAsync();
|
|
return _providerAbilities;
|
|
}
|
|
|
|
public virtual async Task UpsertProviderAbilityAsync(Provider provider)
|
|
{
|
|
await InitProviderAbilitiesAsync();
|
|
var newAbility = new ProviderAbility(provider);
|
|
|
|
if (_providerAbilities.ContainsKey(provider.Id))
|
|
{
|
|
_providerAbilities[provider.Id] = newAbility;
|
|
}
|
|
else
|
|
{
|
|
_providerAbilities.Add(provider.Id, newAbility);
|
|
}
|
|
}
|
|
|
|
public virtual async Task UpsertOrganizationAbilityAsync(Organization organization)
|
|
{
|
|
await InitOrganizationAbilitiesAsync();
|
|
var newAbility = new OrganizationAbility(organization);
|
|
|
|
if (_orgAbilities.ContainsKey(organization.Id))
|
|
{
|
|
_orgAbilities[organization.Id] = newAbility;
|
|
}
|
|
else
|
|
{
|
|
_orgAbilities.Add(organization.Id, newAbility);
|
|
}
|
|
}
|
|
|
|
public virtual Task DeleteOrganizationAbilityAsync(Guid organizationId)
|
|
{
|
|
if (_orgAbilities != null && _orgAbilities.ContainsKey(organizationId))
|
|
{
|
|
_orgAbilities.Remove(organizationId);
|
|
}
|
|
|
|
return Task.FromResult(0);
|
|
}
|
|
|
|
public virtual Task DeleteProviderAbilityAsync(Guid providerId)
|
|
{
|
|
if (_providerAbilities != null && _providerAbilities.ContainsKey(providerId))
|
|
{
|
|
_providerAbilities.Remove(providerId);
|
|
}
|
|
|
|
return Task.FromResult(0);
|
|
}
|
|
|
|
private async Task InitOrganizationAbilitiesAsync()
|
|
{
|
|
var now = DateTime.UtcNow;
|
|
if (_orgAbilities == null || (now - _lastOrgAbilityRefresh) > _orgAbilitiesRefreshInterval)
|
|
{
|
|
var abilities = await _organizationRepository.GetManyAbilitiesAsync();
|
|
_orgAbilities = abilities.ToDictionary(a => a.Id);
|
|
_lastOrgAbilityRefresh = now;
|
|
}
|
|
}
|
|
|
|
private async Task InitProviderAbilitiesAsync()
|
|
{
|
|
var now = DateTime.UtcNow;
|
|
if (_providerAbilities == null || (now - _lastOrgAbilityRefresh) > _orgAbilitiesRefreshInterval)
|
|
{
|
|
var abilities = await _providerRepository.GetManyAbilitiesAsync();
|
|
_providerAbilities = abilities.ToDictionary(a => a.Id);
|
|
_lastOrgAbilityRefresh = now;
|
|
}
|
|
}
|
|
}
|