mirror of
https://github.com/bitwarden/server.git
synced 2025-07-06 10:32:49 -05:00
Revert filescoped (#2227)
* Revert "Add git blame entry (#2226)" This reverts commit239286737d
. * Revert "Turn on file scoped namespaces (#2225)" This reverts commit34fb4cca2a
.
This commit is contained in:
@ -2,37 +2,38 @@
|
||||
using Bit.Core.Models.Data;
|
||||
using Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface ICipherRepository : IRepository<Cipher, Guid>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<CipherDetails> GetByIdAsync(Guid id, Guid userId);
|
||||
Task<CipherOrganizationDetails> GetOrganizationDetailsByIdAsync(Guid id);
|
||||
Task<ICollection<CipherOrganizationDetails>> GetManyOrganizationDetailsByOrganizationIdAsync(Guid organizationId);
|
||||
Task<bool> GetCanEditByIdAsync(Guid userId, Guid cipherId);
|
||||
Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId, bool withOrganizations = true);
|
||||
Task<ICollection<Cipher>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||
Task CreateAsync(Cipher cipher, IEnumerable<Guid> collectionIds);
|
||||
Task CreateAsync(CipherDetails cipher);
|
||||
Task CreateAsync(CipherDetails cipher, IEnumerable<Guid> collectionIds);
|
||||
Task ReplaceAsync(CipherDetails cipher);
|
||||
Task UpsertAsync(CipherDetails cipher);
|
||||
Task<bool> ReplaceAsync(Cipher obj, IEnumerable<Guid> collectionIds);
|
||||
Task UpdatePartialAsync(Guid id, Guid userId, Guid? folderId, bool favorite);
|
||||
Task UpdateAttachmentAsync(CipherAttachment attachment);
|
||||
Task DeleteAttachmentAsync(Guid cipherId, string attachmentId);
|
||||
Task DeleteAsync(IEnumerable<Guid> ids, Guid userId);
|
||||
Task DeleteByIdsOrganizationIdAsync(IEnumerable<Guid> ids, Guid organizationId);
|
||||
Task MoveAsync(IEnumerable<Guid> ids, Guid? folderId, Guid userId);
|
||||
Task DeleteByUserIdAsync(Guid userId);
|
||||
Task DeleteByOrganizationIdAsync(Guid organizationId);
|
||||
Task UpdateUserKeysAndCiphersAsync(User user, IEnumerable<Cipher> ciphers, IEnumerable<Folder> folders, IEnumerable<Send> sends);
|
||||
Task UpdateCiphersAsync(Guid userId, IEnumerable<Cipher> ciphers);
|
||||
Task CreateAsync(IEnumerable<Cipher> ciphers, IEnumerable<Folder> folders);
|
||||
Task CreateAsync(IEnumerable<Cipher> ciphers, IEnumerable<Collection> collections,
|
||||
IEnumerable<CollectionCipher> collectionCiphers);
|
||||
Task SoftDeleteAsync(IEnumerable<Guid> ids, Guid userId);
|
||||
Task SoftDeleteByIdsOrganizationIdAsync(IEnumerable<Guid> ids, Guid organizationId);
|
||||
Task<DateTime> RestoreAsync(IEnumerable<Guid> ids, Guid userId);
|
||||
Task DeleteDeletedAsync(DateTime deletedDateBefore);
|
||||
public interface ICipherRepository : IRepository<Cipher, Guid>
|
||||
{
|
||||
Task<CipherDetails> GetByIdAsync(Guid id, Guid userId);
|
||||
Task<CipherOrganizationDetails> GetOrganizationDetailsByIdAsync(Guid id);
|
||||
Task<ICollection<CipherOrganizationDetails>> GetManyOrganizationDetailsByOrganizationIdAsync(Guid organizationId);
|
||||
Task<bool> GetCanEditByIdAsync(Guid userId, Guid cipherId);
|
||||
Task<ICollection<CipherDetails>> GetManyByUserIdAsync(Guid userId, bool withOrganizations = true);
|
||||
Task<ICollection<Cipher>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||
Task CreateAsync(Cipher cipher, IEnumerable<Guid> collectionIds);
|
||||
Task CreateAsync(CipherDetails cipher);
|
||||
Task CreateAsync(CipherDetails cipher, IEnumerable<Guid> collectionIds);
|
||||
Task ReplaceAsync(CipherDetails cipher);
|
||||
Task UpsertAsync(CipherDetails cipher);
|
||||
Task<bool> ReplaceAsync(Cipher obj, IEnumerable<Guid> collectionIds);
|
||||
Task UpdatePartialAsync(Guid id, Guid userId, Guid? folderId, bool favorite);
|
||||
Task UpdateAttachmentAsync(CipherAttachment attachment);
|
||||
Task DeleteAttachmentAsync(Guid cipherId, string attachmentId);
|
||||
Task DeleteAsync(IEnumerable<Guid> ids, Guid userId);
|
||||
Task DeleteByIdsOrganizationIdAsync(IEnumerable<Guid> ids, Guid organizationId);
|
||||
Task MoveAsync(IEnumerable<Guid> ids, Guid? folderId, Guid userId);
|
||||
Task DeleteByUserIdAsync(Guid userId);
|
||||
Task DeleteByOrganizationIdAsync(Guid organizationId);
|
||||
Task UpdateUserKeysAndCiphersAsync(User user, IEnumerable<Cipher> ciphers, IEnumerable<Folder> folders, IEnumerable<Send> sends);
|
||||
Task UpdateCiphersAsync(Guid userId, IEnumerable<Cipher> ciphers);
|
||||
Task CreateAsync(IEnumerable<Cipher> ciphers, IEnumerable<Folder> folders);
|
||||
Task CreateAsync(IEnumerable<Cipher> ciphers, IEnumerable<Collection> collections,
|
||||
IEnumerable<CollectionCipher> collectionCiphers);
|
||||
Task SoftDeleteAsync(IEnumerable<Guid> ids, Guid userId);
|
||||
Task SoftDeleteByIdsOrganizationIdAsync(IEnumerable<Guid> ids, Guid organizationId);
|
||||
Task<DateTime> RestoreAsync(IEnumerable<Guid> ids, Guid userId);
|
||||
Task DeleteDeletedAsync(DateTime deletedDateBefore);
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,15 @@
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface ICollectionCipherRepository
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<ICollection<CollectionCipher>> GetManyByUserIdAsync(Guid userId);
|
||||
Task<ICollection<CollectionCipher>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||
Task<ICollection<CollectionCipher>> GetManyByUserIdCipherIdAsync(Guid userId, Guid cipherId);
|
||||
Task UpdateCollectionsAsync(Guid cipherId, Guid userId, IEnumerable<Guid> collectionIds);
|
||||
Task UpdateCollectionsForAdminAsync(Guid cipherId, Guid organizationId, IEnumerable<Guid> collectionIds);
|
||||
Task UpdateCollectionsForCiphersAsync(IEnumerable<Guid> cipherIds, Guid userId, Guid organizationId,
|
||||
IEnumerable<Guid> collectionIds);
|
||||
public interface ICollectionCipherRepository
|
||||
{
|
||||
Task<ICollection<CollectionCipher>> GetManyByUserIdAsync(Guid userId);
|
||||
Task<ICollection<CollectionCipher>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||
Task<ICollection<CollectionCipher>> GetManyByUserIdCipherIdAsync(Guid userId, Guid cipherId);
|
||||
Task UpdateCollectionsAsync(Guid cipherId, Guid userId, IEnumerable<Guid> collectionIds);
|
||||
Task UpdateCollectionsForAdminAsync(Guid cipherId, Guid organizationId, IEnumerable<Guid> collectionIds);
|
||||
Task UpdateCollectionsForCiphersAsync(IEnumerable<Guid> cipherIds, Guid userId, Guid organizationId,
|
||||
IEnumerable<Guid> collectionIds);
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,20 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface ICollectionRepository : IRepository<Collection, Guid>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<int> GetCountByOrganizationIdAsync(Guid organizationId);
|
||||
Task<Tuple<Collection, ICollection<SelectionReadOnly>>> GetByIdWithGroupsAsync(Guid id);
|
||||
Task<Tuple<CollectionDetails, ICollection<SelectionReadOnly>>> GetByIdWithGroupsAsync(Guid id, Guid userId);
|
||||
Task<ICollection<Collection>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||
Task<CollectionDetails> GetByIdAsync(Guid id, Guid userId);
|
||||
Task<ICollection<CollectionDetails>> GetManyByUserIdAsync(Guid userId);
|
||||
Task CreateAsync(Collection obj, IEnumerable<SelectionReadOnly> groups);
|
||||
Task ReplaceAsync(Collection obj, IEnumerable<SelectionReadOnly> groups);
|
||||
Task DeleteUserAsync(Guid collectionId, Guid organizationUserId);
|
||||
Task UpdateUsersAsync(Guid id, IEnumerable<SelectionReadOnly> users);
|
||||
Task<ICollection<SelectionReadOnly>> GetManyUsersByIdAsync(Guid id);
|
||||
public interface ICollectionRepository : IRepository<Collection, Guid>
|
||||
{
|
||||
Task<int> GetCountByOrganizationIdAsync(Guid organizationId);
|
||||
Task<Tuple<Collection, ICollection<SelectionReadOnly>>> GetByIdWithGroupsAsync(Guid id);
|
||||
Task<Tuple<CollectionDetails, ICollection<SelectionReadOnly>>> GetByIdWithGroupsAsync(Guid id, Guid userId);
|
||||
Task<ICollection<Collection>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||
Task<CollectionDetails> GetByIdAsync(Guid id, Guid userId);
|
||||
Task<ICollection<CollectionDetails>> GetManyByUserIdAsync(Guid userId);
|
||||
Task CreateAsync(Collection obj, IEnumerable<SelectionReadOnly> groups);
|
||||
Task ReplaceAsync(Collection obj, IEnumerable<SelectionReadOnly> groups);
|
||||
Task DeleteUserAsync(Guid collectionId, Guid organizationUserId);
|
||||
Task UpdateUsersAsync(Guid id, IEnumerable<SelectionReadOnly> users);
|
||||
Task<ICollection<SelectionReadOnly>> GetManyUsersByIdAsync(Guid id);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IDeviceRepository : IRepository<Device, Guid>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<Device> GetByIdAsync(Guid id, Guid userId);
|
||||
Task<Device> GetByIdentifierAsync(string identifier);
|
||||
Task<Device> GetByIdentifierAsync(string identifier, Guid userId);
|
||||
Task<ICollection<Device>> GetManyByUserIdAsync(Guid userId);
|
||||
Task ClearPushTokenAsync(Guid id);
|
||||
public interface IDeviceRepository : IRepository<Device, Guid>
|
||||
{
|
||||
Task<Device> GetByIdAsync(Guid id, Guid userId);
|
||||
Task<Device> GetByIdentifierAsync(string identifier);
|
||||
Task<Device> GetByIdentifierAsync(string identifier, Guid userId);
|
||||
Task<ICollection<Device>> GetManyByUserIdAsync(Guid userId);
|
||||
Task ClearPushTokenAsync(Guid id);
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,15 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IEmergencyAccessRepository : IRepository<EmergencyAccess, Guid>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<int> GetCountByGrantorIdEmailAsync(Guid grantorId, string email, bool onlyRegisteredUsers);
|
||||
Task<ICollection<EmergencyAccessDetails>> GetManyDetailsByGrantorIdAsync(Guid grantorId);
|
||||
Task<ICollection<EmergencyAccessDetails>> GetManyDetailsByGranteeIdAsync(Guid granteeId);
|
||||
Task<EmergencyAccessDetails> GetDetailsByIdGrantorIdAsync(Guid id, Guid grantorId);
|
||||
Task<ICollection<EmergencyAccessNotify>> GetManyToNotifyAsync();
|
||||
Task<ICollection<EmergencyAccessDetails>> GetExpiredRecoveriesAsync();
|
||||
public interface IEmergencyAccessRepository : IRepository<EmergencyAccess, Guid>
|
||||
{
|
||||
Task<int> GetCountByGrantorIdEmailAsync(Guid grantorId, string email, bool onlyRegisteredUsers);
|
||||
Task<ICollection<EmergencyAccessDetails>> GetManyDetailsByGrantorIdAsync(Guid grantorId);
|
||||
Task<ICollection<EmergencyAccessDetails>> GetManyDetailsByGranteeIdAsync(Guid granteeId);
|
||||
Task<EmergencyAccessDetails> GetDetailsByIdGrantorIdAsync(Guid id, Guid grantorId);
|
||||
Task<ICollection<EmergencyAccessNotify>> GetManyToNotifyAsync();
|
||||
Task<ICollection<EmergencyAccessDetails>> GetExpiredRecoveriesAsync();
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,23 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IEventRepository
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<PagedResult<IEvent>> GetManyByUserAsync(Guid userId, DateTime startDate, DateTime endDate,
|
||||
PageOptions pageOptions);
|
||||
Task<PagedResult<IEvent>> GetManyByOrganizationAsync(Guid organizationId, DateTime startDate, DateTime endDate,
|
||||
PageOptions pageOptions);
|
||||
Task<PagedResult<IEvent>> GetManyByOrganizationActingUserAsync(Guid organizationId, Guid actingUserId,
|
||||
DateTime startDate, DateTime endDate, PageOptions pageOptions);
|
||||
Task<PagedResult<IEvent>> GetManyByProviderAsync(Guid providerId, DateTime startDate, DateTime endDate,
|
||||
PageOptions pageOptions);
|
||||
Task<PagedResult<IEvent>> GetManyByProviderActingUserAsync(Guid providerId, Guid actingUserId,
|
||||
DateTime startDate, DateTime endDate, PageOptions pageOptions);
|
||||
Task<PagedResult<IEvent>> GetManyByCipherAsync(Cipher cipher, DateTime startDate, DateTime endDate,
|
||||
PageOptions pageOptions);
|
||||
Task CreateAsync(IEvent e);
|
||||
Task CreateManyAsync(IEnumerable<IEvent> e);
|
||||
public interface IEventRepository
|
||||
{
|
||||
Task<PagedResult<IEvent>> GetManyByUserAsync(Guid userId, DateTime startDate, DateTime endDate,
|
||||
PageOptions pageOptions);
|
||||
Task<PagedResult<IEvent>> GetManyByOrganizationAsync(Guid organizationId, DateTime startDate, DateTime endDate,
|
||||
PageOptions pageOptions);
|
||||
Task<PagedResult<IEvent>> GetManyByOrganizationActingUserAsync(Guid organizationId, Guid actingUserId,
|
||||
DateTime startDate, DateTime endDate, PageOptions pageOptions);
|
||||
Task<PagedResult<IEvent>> GetManyByProviderAsync(Guid providerId, DateTime startDate, DateTime endDate,
|
||||
PageOptions pageOptions);
|
||||
Task<PagedResult<IEvent>> GetManyByProviderActingUserAsync(Guid providerId, Guid actingUserId,
|
||||
DateTime startDate, DateTime endDate, PageOptions pageOptions);
|
||||
Task<PagedResult<IEvent>> GetManyByCipherAsync(Cipher cipher, DateTime startDate, DateTime endDate,
|
||||
PageOptions pageOptions);
|
||||
Task CreateAsync(IEvent e);
|
||||
Task CreateManyAsync(IEnumerable<IEvent> e);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IFolderRepository : IRepository<Folder, Guid>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<Folder> GetByIdAsync(Guid id, Guid userId);
|
||||
Task<ICollection<Folder>> GetManyByUserIdAsync(Guid userId);
|
||||
public interface IFolderRepository : IRepository<Folder, Guid>
|
||||
{
|
||||
Task<Folder> GetByIdAsync(Guid id, Guid userId);
|
||||
Task<ICollection<Folder>> GetManyByUserIdAsync(Guid userId);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IGrantRepository
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<Grant> GetByKeyAsync(string key);
|
||||
Task<ICollection<Grant>> GetManyAsync(string subjectId, string sessionId, string clientId, string type);
|
||||
Task SaveAsync(Grant obj);
|
||||
Task DeleteByKeyAsync(string key);
|
||||
Task DeleteManyAsync(string subjectId, string sessionId, string clientId, string type);
|
||||
public interface IGrantRepository
|
||||
{
|
||||
Task<Grant> GetByKeyAsync(string key);
|
||||
Task<ICollection<Grant>> GetManyAsync(string subjectId, string sessionId, string clientId, string type);
|
||||
Task SaveAsync(Grant obj);
|
||||
Task DeleteByKeyAsync(string key);
|
||||
Task DeleteManyAsync(string subjectId, string sessionId, string clientId, string type);
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,18 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IGroupRepository : IRepository<Group, Guid>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<Tuple<Group, ICollection<SelectionReadOnly>>> GetByIdWithCollectionsAsync(Guid id);
|
||||
Task<ICollection<Group>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||
Task<ICollection<Guid>> GetManyIdsByUserIdAsync(Guid organizationUserId);
|
||||
Task<ICollection<Guid>> GetManyUserIdsByIdAsync(Guid id);
|
||||
Task<ICollection<GroupUser>> GetManyGroupUsersByOrganizationIdAsync(Guid organizationId);
|
||||
Task CreateAsync(Group obj, IEnumerable<SelectionReadOnly> collections);
|
||||
Task ReplaceAsync(Group obj, IEnumerable<SelectionReadOnly> collections);
|
||||
Task DeleteUserAsync(Guid groupId, Guid organizationUserId);
|
||||
Task UpdateUsersAsync(Guid groupId, IEnumerable<Guid> organizationUserIds);
|
||||
public interface IGroupRepository : IRepository<Group, Guid>
|
||||
{
|
||||
Task<Tuple<Group, ICollection<SelectionReadOnly>>> GetByIdWithCollectionsAsync(Guid id);
|
||||
Task<ICollection<Group>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||
Task<ICollection<Guid>> GetManyIdsByUserIdAsync(Guid organizationUserId);
|
||||
Task<ICollection<Guid>> GetManyUserIdsByIdAsync(Guid id);
|
||||
Task<ICollection<GroupUser>> GetManyGroupUsersByOrganizationIdAsync(Guid organizationId);
|
||||
Task CreateAsync(Group obj, IEnumerable<SelectionReadOnly> collections);
|
||||
Task ReplaceAsync(Group obj, IEnumerable<SelectionReadOnly> collections);
|
||||
Task DeleteUserAsync(Guid groupId, Guid organizationUserId);
|
||||
Task UpdateUsersAsync(Guid groupId, IEnumerable<Guid> organizationUserIds);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IInstallationDeviceRepository
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task UpsertAsync(InstallationDeviceEntity entity);
|
||||
Task UpsertManyAsync(IList<InstallationDeviceEntity> entities);
|
||||
Task DeleteAsync(InstallationDeviceEntity entity);
|
||||
public interface IInstallationDeviceRepository
|
||||
{
|
||||
Task UpsertAsync(InstallationDeviceEntity entity);
|
||||
Task UpsertManyAsync(IList<InstallationDeviceEntity> entities);
|
||||
Task DeleteAsync(InstallationDeviceEntity entity);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IInstallationRepository : IRepository<Installation, Guid>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
public interface IInstallationRepository : IRepository<Installation, Guid>
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IMaintenanceRepository
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task UpdateStatisticsAsync();
|
||||
Task DisableCipherAutoStatsAsync();
|
||||
Task RebuildIndexesAsync();
|
||||
Task DeleteExpiredGrantsAsync();
|
||||
Task DeleteExpiredSponsorshipsAsync(DateTime validUntilBeforeDate);
|
||||
public interface IMaintenanceRepository
|
||||
{
|
||||
Task UpdateStatisticsAsync();
|
||||
Task DisableCipherAutoStatsAsync();
|
||||
Task RebuildIndexesAsync();
|
||||
Task DeleteExpiredGrantsAsync();
|
||||
Task DeleteExpiredSponsorshipsAsync(DateTime validUntilBeforeDate);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IMetaDataRepository
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task DeleteAsync(string objectName, string id);
|
||||
Task<IDictionary<string, string>> GetAsync(string objectName, string id);
|
||||
Task<string> GetAsync(string objectName, string id, string prop);
|
||||
Task UpsertAsync(string objectName, string id, IDictionary<string, string> dict);
|
||||
Task UpsertAsync(string objectName, string id, KeyValuePair<string, string> keyValuePair);
|
||||
public interface IMetaDataRepository
|
||||
{
|
||||
Task DeleteAsync(string objectName, string id);
|
||||
Task<IDictionary<string, string>> GetAsync(string objectName, string id);
|
||||
Task<string> GetAsync(string objectName, string id, string prop);
|
||||
Task UpsertAsync(string objectName, string id, IDictionary<string, string> dict);
|
||||
Task UpsertAsync(string objectName, string id, KeyValuePair<string, string> keyValuePair);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IOrganizationApiKeyRepository : IRepository<OrganizationApiKey, Guid>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<IEnumerable<OrganizationApiKey>> GetManyByOrganizationIdTypeAsync(Guid organizationId, OrganizationApiKeyType? type = null);
|
||||
public interface IOrganizationApiKeyRepository : IRepository<OrganizationApiKey, Guid>
|
||||
{
|
||||
Task<IEnumerable<OrganizationApiKey>> GetManyByOrganizationIdTypeAsync(Guid organizationId, OrganizationApiKeyType? type = null);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IOrganizationConnectionRepository : IRepository<OrganizationConnection, Guid>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<ICollection<OrganizationConnection>> GetByOrganizationIdTypeAsync(Guid organizationId, OrganizationConnectionType type);
|
||||
Task<ICollection<OrganizationConnection>> GetEnabledByOrganizationIdTypeAsync(Guid organizationId, OrganizationConnectionType type);
|
||||
public interface IOrganizationConnectionRepository : IRepository<OrganizationConnection, Guid>
|
||||
{
|
||||
Task<ICollection<OrganizationConnection>> GetByOrganizationIdTypeAsync(Guid organizationId, OrganizationConnectionType type);
|
||||
Task<ICollection<OrganizationConnection>> GetEnabledByOrganizationIdTypeAsync(Guid organizationId, OrganizationConnectionType type);
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,15 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Models.Data.Organizations;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IOrganizationRepository : IRepository<Organization, Guid>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<Organization> GetByIdentifierAsync(string identifier);
|
||||
Task<ICollection<Organization>> GetManyByEnabledAsync();
|
||||
Task<ICollection<Organization>> GetManyByUserIdAsync(Guid userId);
|
||||
Task<ICollection<Organization>> SearchAsync(string name, string userEmail, bool? paid, int skip, int take);
|
||||
Task UpdateStorageAsync(Guid id);
|
||||
Task<ICollection<OrganizationAbility>> GetManyAbilitiesAsync();
|
||||
public interface IOrganizationRepository : IRepository<Organization, Guid>
|
||||
{
|
||||
Task<Organization> GetByIdentifierAsync(string identifier);
|
||||
Task<ICollection<Organization>> GetManyByEnabledAsync();
|
||||
Task<ICollection<Organization>> GetManyByUserIdAsync(Guid userId);
|
||||
Task<ICollection<Organization>> SearchAsync(string name, string userEmail, bool? paid, int skip, int take);
|
||||
Task UpdateStorageAsync(Guid id);
|
||||
Task<ICollection<OrganizationAbility>> GetManyAbilitiesAsync();
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,16 @@
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IOrganizationSponsorshipRepository : IRepository<OrganizationSponsorship, Guid>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<ICollection<Guid>> CreateManyAsync(IEnumerable<OrganizationSponsorship> organizationSponsorships);
|
||||
Task ReplaceManyAsync(IEnumerable<OrganizationSponsorship> organizationSponsorships);
|
||||
Task UpsertManyAsync(IEnumerable<OrganizationSponsorship> organizationSponsorships);
|
||||
Task DeleteManyAsync(IEnumerable<Guid> organizationSponsorshipIds);
|
||||
Task<ICollection<OrganizationSponsorship>> GetManyBySponsoringOrganizationAsync(Guid sponsoringOrganizationId);
|
||||
Task<OrganizationSponsorship> GetBySponsoringOrganizationUserIdAsync(Guid sponsoringOrganizationUserId);
|
||||
Task<OrganizationSponsorship> GetBySponsoredOrganizationIdAsync(Guid sponsoredOrganizationId);
|
||||
Task<DateTime?> GetLatestSyncDateBySponsoringOrganizationIdAsync(Guid sponsoringOrganizationId);
|
||||
public interface IOrganizationSponsorshipRepository : IRepository<OrganizationSponsorship, Guid>
|
||||
{
|
||||
Task<ICollection<Guid>> CreateManyAsync(IEnumerable<OrganizationSponsorship> organizationSponsorships);
|
||||
Task ReplaceManyAsync(IEnumerable<OrganizationSponsorship> organizationSponsorships);
|
||||
Task UpsertManyAsync(IEnumerable<OrganizationSponsorship> organizationSponsorships);
|
||||
Task DeleteManyAsync(IEnumerable<Guid> organizationSponsorshipIds);
|
||||
Task<ICollection<OrganizationSponsorship>> GetManyBySponsoringOrganizationAsync(Guid sponsoringOrganizationId);
|
||||
Task<OrganizationSponsorship> GetBySponsoringOrganizationUserIdAsync(Guid sponsoringOrganizationUserId);
|
||||
Task<OrganizationSponsorship> GetBySponsoredOrganizationIdAsync(Guid sponsoredOrganizationId);
|
||||
Task<DateTime?> GetLatestSyncDateBySponsoringOrganizationIdAsync(Guid sponsoringOrganizationId);
|
||||
}
|
||||
}
|
||||
|
@ -3,39 +3,40 @@ using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IOrganizationUserRepository : IRepository<OrganizationUser, Guid>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<int> GetCountByOrganizationIdAsync(Guid organizationId);
|
||||
Task<int> GetCountByFreeOrganizationAdminUserAsync(Guid userId);
|
||||
Task<int> GetCountByOnlyOwnerAsync(Guid userId);
|
||||
Task<ICollection<OrganizationUser>> GetManyByUserAsync(Guid userId);
|
||||
Task<ICollection<OrganizationUser>> GetManyByOrganizationAsync(Guid organizationId, OrganizationUserType? type);
|
||||
Task<int> GetCountByOrganizationAsync(Guid organizationId, string email, bool onlyRegisteredUsers);
|
||||
Task<ICollection<string>> SelectKnownEmailsAsync(Guid organizationId, IEnumerable<string> emails, bool onlyRegisteredUsers);
|
||||
Task<OrganizationUser> GetByOrganizationAsync(Guid organizationId, Guid userId);
|
||||
Task<Tuple<OrganizationUser, ICollection<SelectionReadOnly>>> GetByIdWithCollectionsAsync(Guid id);
|
||||
Task<OrganizationUserUserDetails> GetDetailsByIdAsync(Guid id);
|
||||
Task<Tuple<OrganizationUserUserDetails, ICollection<SelectionReadOnly>>>
|
||||
GetDetailsByIdWithCollectionsAsync(Guid id);
|
||||
Task<ICollection<OrganizationUserUserDetails>> GetManyDetailsByOrganizationAsync(Guid organizationId);
|
||||
Task<ICollection<OrganizationUserOrganizationDetails>> GetManyDetailsByUserAsync(Guid userId,
|
||||
OrganizationUserStatusType? status = null);
|
||||
Task<OrganizationUserOrganizationDetails> GetDetailsByUserAsync(Guid userId, Guid organizationId,
|
||||
OrganizationUserStatusType? status = null);
|
||||
Task UpdateGroupsAsync(Guid orgUserId, IEnumerable<Guid> groupIds);
|
||||
Task UpsertManyAsync(IEnumerable<OrganizationUser> organizationUsers);
|
||||
Task<Guid> CreateAsync(OrganizationUser obj, IEnumerable<SelectionReadOnly> collections);
|
||||
Task<ICollection<Guid>> CreateManyAsync(IEnumerable<OrganizationUser> organizationIdUsers);
|
||||
Task ReplaceAsync(OrganizationUser obj, IEnumerable<SelectionReadOnly> collections);
|
||||
Task ReplaceManyAsync(IEnumerable<OrganizationUser> organizationUsers);
|
||||
Task<ICollection<OrganizationUser>> GetManyByManyUsersAsync(IEnumerable<Guid> userIds);
|
||||
Task<ICollection<OrganizationUser>> GetManyAsync(IEnumerable<Guid> Ids);
|
||||
Task DeleteManyAsync(IEnumerable<Guid> userIds);
|
||||
Task<OrganizationUser> GetByOrganizationEmailAsync(Guid organizationId, string email);
|
||||
Task<IEnumerable<OrganizationUserPublicKey>> GetManyPublicKeysByOrganizationUserAsync(Guid organizationId, IEnumerable<Guid> Ids);
|
||||
Task<IEnumerable<OrganizationUserUserDetails>> GetManyByMinimumRoleAsync(Guid organizationId, OrganizationUserType minRole);
|
||||
Task RevokeAsync(Guid id);
|
||||
Task RestoreAsync(Guid id, OrganizationUserStatusType status);
|
||||
public interface IOrganizationUserRepository : IRepository<OrganizationUser, Guid>
|
||||
{
|
||||
Task<int> GetCountByOrganizationIdAsync(Guid organizationId);
|
||||
Task<int> GetCountByFreeOrganizationAdminUserAsync(Guid userId);
|
||||
Task<int> GetCountByOnlyOwnerAsync(Guid userId);
|
||||
Task<ICollection<OrganizationUser>> GetManyByUserAsync(Guid userId);
|
||||
Task<ICollection<OrganizationUser>> GetManyByOrganizationAsync(Guid organizationId, OrganizationUserType? type);
|
||||
Task<int> GetCountByOrganizationAsync(Guid organizationId, string email, bool onlyRegisteredUsers);
|
||||
Task<ICollection<string>> SelectKnownEmailsAsync(Guid organizationId, IEnumerable<string> emails, bool onlyRegisteredUsers);
|
||||
Task<OrganizationUser> GetByOrganizationAsync(Guid organizationId, Guid userId);
|
||||
Task<Tuple<OrganizationUser, ICollection<SelectionReadOnly>>> GetByIdWithCollectionsAsync(Guid id);
|
||||
Task<OrganizationUserUserDetails> GetDetailsByIdAsync(Guid id);
|
||||
Task<Tuple<OrganizationUserUserDetails, ICollection<SelectionReadOnly>>>
|
||||
GetDetailsByIdWithCollectionsAsync(Guid id);
|
||||
Task<ICollection<OrganizationUserUserDetails>> GetManyDetailsByOrganizationAsync(Guid organizationId);
|
||||
Task<ICollection<OrganizationUserOrganizationDetails>> GetManyDetailsByUserAsync(Guid userId,
|
||||
OrganizationUserStatusType? status = null);
|
||||
Task<OrganizationUserOrganizationDetails> GetDetailsByUserAsync(Guid userId, Guid organizationId,
|
||||
OrganizationUserStatusType? status = null);
|
||||
Task UpdateGroupsAsync(Guid orgUserId, IEnumerable<Guid> groupIds);
|
||||
Task UpsertManyAsync(IEnumerable<OrganizationUser> organizationUsers);
|
||||
Task<Guid> CreateAsync(OrganizationUser obj, IEnumerable<SelectionReadOnly> collections);
|
||||
Task<ICollection<Guid>> CreateManyAsync(IEnumerable<OrganizationUser> organizationIdUsers);
|
||||
Task ReplaceAsync(OrganizationUser obj, IEnumerable<SelectionReadOnly> collections);
|
||||
Task ReplaceManyAsync(IEnumerable<OrganizationUser> organizationUsers);
|
||||
Task<ICollection<OrganizationUser>> GetManyByManyUsersAsync(IEnumerable<Guid> userIds);
|
||||
Task<ICollection<OrganizationUser>> GetManyAsync(IEnumerable<Guid> Ids);
|
||||
Task DeleteManyAsync(IEnumerable<Guid> userIds);
|
||||
Task<OrganizationUser> GetByOrganizationEmailAsync(Guid organizationId, string email);
|
||||
Task<IEnumerable<OrganizationUserPublicKey>> GetManyPublicKeysByOrganizationUserAsync(Guid organizationId, IEnumerable<Guid> Ids);
|
||||
Task<IEnumerable<OrganizationUserUserDetails>> GetManyByMinimumRoleAsync(Guid organizationId, OrganizationUserType minRole);
|
||||
Task RevokeAsync(Guid id);
|
||||
Task RestoreAsync(Guid id, OrganizationUserStatusType status);
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,16 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IPolicyRepository : IRepository<Policy, Guid>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<Policy> GetByOrganizationIdTypeAsync(Guid organizationId, PolicyType type);
|
||||
Task<ICollection<Policy>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||
Task<ICollection<Policy>> GetManyByUserIdAsync(Guid userId);
|
||||
Task<ICollection<Policy>> GetManyByTypeApplicableToUserIdAsync(Guid userId, PolicyType policyType,
|
||||
OrganizationUserStatusType minStatus = OrganizationUserStatusType.Accepted);
|
||||
Task<int> GetCountByTypeApplicableToUserIdAsync(Guid userId, PolicyType policyType,
|
||||
OrganizationUserStatusType minStatus = OrganizationUserStatusType.Accepted);
|
||||
public interface IPolicyRepository : IRepository<Policy, Guid>
|
||||
{
|
||||
Task<Policy> GetByOrganizationIdTypeAsync(Guid organizationId, PolicyType type);
|
||||
Task<ICollection<Policy>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||
Task<ICollection<Policy>> GetManyByUserIdAsync(Guid userId);
|
||||
Task<ICollection<Policy>> GetManyByTypeApplicableToUserIdAsync(Guid userId, PolicyType policyType,
|
||||
OrganizationUserStatusType minStatus = OrganizationUserStatusType.Accepted);
|
||||
Task<int> GetCountByTypeApplicableToUserIdAsync(Guid userId, PolicyType policyType,
|
||||
OrganizationUserStatusType minStatus = OrganizationUserStatusType.Accepted);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
using Bit.Core.Entities.Provider;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IProviderOrganizationRepository : IRepository<ProviderOrganization, Guid>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<ICollection<ProviderOrganizationOrganizationDetails>> GetManyDetailsByProviderAsync(Guid providerId);
|
||||
Task<ProviderOrganization> GetByOrganizationId(Guid organizationId);
|
||||
public interface IProviderOrganizationRepository : IRepository<ProviderOrganization, Guid>
|
||||
{
|
||||
Task<ICollection<ProviderOrganizationOrganizationDetails>> GetManyDetailsByProviderAsync(Guid providerId);
|
||||
Task<ProviderOrganization> GetByOrganizationId(Guid organizationId);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
using Bit.Core.Entities.Provider;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IProviderRepository : IRepository<Provider, Guid>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<ICollection<Provider>> SearchAsync(string name, string userEmail, int skip, int take);
|
||||
Task<ICollection<ProviderAbility>> GetManyAbilitiesAsync();
|
||||
public interface IProviderRepository : IRepository<Provider, Guid>
|
||||
{
|
||||
Task<ICollection<Provider>> SearchAsync(string name, string userEmail, int skip, int take);
|
||||
Task<ICollection<ProviderAbility>> GetManyAbilitiesAsync();
|
||||
}
|
||||
}
|
||||
|
@ -2,20 +2,21 @@
|
||||
using Bit.Core.Enums.Provider;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IProviderUserRepository : IRepository<ProviderUser, Guid>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<int> GetCountByProviderAsync(Guid providerId, string email, bool onlyRegisteredUsers);
|
||||
Task<ICollection<ProviderUser>> GetManyAsync(IEnumerable<Guid> ids);
|
||||
Task<ICollection<ProviderUser>> GetManyByUserAsync(Guid userId);
|
||||
Task<ProviderUser> GetByProviderUserAsync(Guid providerId, Guid userId);
|
||||
Task<ICollection<ProviderUser>> GetManyByProviderAsync(Guid providerId, ProviderUserType? type = null);
|
||||
Task<ICollection<ProviderUserUserDetails>> GetManyDetailsByProviderAsync(Guid providerId);
|
||||
Task<ICollection<ProviderUserProviderDetails>> GetManyDetailsByUserAsync(Guid userId,
|
||||
ProviderUserStatusType? status = null);
|
||||
Task<IEnumerable<ProviderUserOrganizationDetails>> GetManyOrganizationDetailsByUserAsync(Guid userId, ProviderUserStatusType? status = null);
|
||||
Task DeleteManyAsync(IEnumerable<Guid> userIds);
|
||||
Task<IEnumerable<ProviderUserPublicKey>> GetManyPublicKeysByProviderUserAsync(Guid providerId, IEnumerable<Guid> Ids);
|
||||
Task<int> GetCountByOnlyOwnerAsync(Guid userId);
|
||||
public interface IProviderUserRepository : IRepository<ProviderUser, Guid>
|
||||
{
|
||||
Task<int> GetCountByProviderAsync(Guid providerId, string email, bool onlyRegisteredUsers);
|
||||
Task<ICollection<ProviderUser>> GetManyAsync(IEnumerable<Guid> ids);
|
||||
Task<ICollection<ProviderUser>> GetManyByUserAsync(Guid userId);
|
||||
Task<ProviderUser> GetByProviderUserAsync(Guid providerId, Guid userId);
|
||||
Task<ICollection<ProviderUser>> GetManyByProviderAsync(Guid providerId, ProviderUserType? type = null);
|
||||
Task<ICollection<ProviderUserUserDetails>> GetManyDetailsByProviderAsync(Guid providerId);
|
||||
Task<ICollection<ProviderUserProviderDetails>> GetManyDetailsByUserAsync(Guid userId,
|
||||
ProviderUserStatusType? status = null);
|
||||
Task<IEnumerable<ProviderUserOrganizationDetails>> GetManyOrganizationDetailsByUserAsync(Guid userId, ProviderUserStatusType? status = null);
|
||||
Task DeleteManyAsync(IEnumerable<Guid> userIds);
|
||||
Task<IEnumerable<ProviderUserPublicKey>> GetManyPublicKeysByProviderUserAsync(Guid providerId, IEnumerable<Guid> Ids);
|
||||
Task<int> GetCountByOnlyOwnerAsync(Guid userId);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IRepository<T, TId> where TId : IEquatable<TId> where T : class, ITableObject<TId>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<T> GetByIdAsync(TId id);
|
||||
Task<T> CreateAsync(T obj);
|
||||
Task ReplaceAsync(T obj);
|
||||
Task UpsertAsync(T obj);
|
||||
Task DeleteAsync(T obj);
|
||||
public interface IRepository<T, TId> where TId : IEquatable<TId> where T : class, ITableObject<TId>
|
||||
{
|
||||
Task<T> GetByIdAsync(TId id);
|
||||
Task<T> CreateAsync(T obj);
|
||||
Task ReplaceAsync(T obj);
|
||||
Task UpsertAsync(T obj);
|
||||
Task DeleteAsync(T obj);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface ISendRepository : IRepository<Send, Guid>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<ICollection<Send>> GetManyByUserIdAsync(Guid userId);
|
||||
Task<ICollection<Send>> GetManyByDeletionDateAsync(DateTime deletionDateBefore);
|
||||
public interface ISendRepository : IRepository<Send, Guid>
|
||||
{
|
||||
Task<ICollection<Send>> GetManyByUserIdAsync(Guid userId);
|
||||
Task<ICollection<Send>> GetManyByDeletionDateAsync(DateTime deletionDateBefore);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface ISsoConfigRepository : IRepository<SsoConfig, long>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<SsoConfig> GetByOrganizationIdAsync(Guid organizationId);
|
||||
Task<SsoConfig> GetByIdentifierAsync(string identifier);
|
||||
Task<ICollection<SsoConfig>> GetManyByRevisionNotBeforeDate(DateTime? notBefore);
|
||||
public interface ISsoConfigRepository : IRepository<SsoConfig, long>
|
||||
{
|
||||
Task<SsoConfig> GetByOrganizationIdAsync(Guid organizationId);
|
||||
Task<SsoConfig> GetByIdentifierAsync(string identifier);
|
||||
Task<ICollection<SsoConfig>> GetManyByRevisionNotBeforeDate(DateTime? notBefore);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface ISsoUserRepository : IRepository<SsoUser, long>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task DeleteAsync(Guid userId, Guid? organizationId);
|
||||
Task<SsoUser> GetByUserIdOrganizationIdAsync(Guid organizationId, Guid userId);
|
||||
public interface ISsoUserRepository : IRepository<SsoUser, long>
|
||||
{
|
||||
Task DeleteAsync(Guid userId, Guid? organizationId);
|
||||
Task<SsoUser> GetByUserIdOrganizationIdAsync(Guid organizationId, Guid userId);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
using Bit.Core.Entities;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface ITaxRateRepository : IRepository<TaxRate, string>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<ICollection<TaxRate>> SearchAsync(int skip, int count);
|
||||
Task<ICollection<TaxRate>> GetAllActiveAsync();
|
||||
Task ArchiveAsync(TaxRate model);
|
||||
Task<ICollection<TaxRate>> GetByLocationAsync(TaxRate taxRate);
|
||||
public interface ITaxRateRepository : IRepository<TaxRate, string>
|
||||
{
|
||||
Task<ICollection<TaxRate>> SearchAsync(int skip, int count);
|
||||
Task<ICollection<TaxRate>> GetAllActiveAsync();
|
||||
Task ArchiveAsync(TaxRate model);
|
||||
Task<ICollection<TaxRate>> GetByLocationAsync(TaxRate taxRate);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface ITransactionRepository : IRepository<Transaction, Guid>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<ICollection<Transaction>> GetManyByUserIdAsync(Guid userId);
|
||||
Task<ICollection<Transaction>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||
Task<Transaction> GetByGatewayIdAsync(GatewayType gatewayType, string gatewayId);
|
||||
public interface ITransactionRepository : IRepository<Transaction, Guid>
|
||||
{
|
||||
Task<ICollection<Transaction>> GetManyByUserIdAsync(Guid userId);
|
||||
Task<ICollection<Transaction>> GetManyByOrganizationIdAsync(Guid organizationId);
|
||||
Task<Transaction> GetByGatewayIdAsync(GatewayType gatewayType, string gatewayId);
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,19 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Repositories;
|
||||
|
||||
public interface IUserRepository : IRepository<User, Guid>
|
||||
namespace Bit.Core.Repositories
|
||||
{
|
||||
Task<User> GetByEmailAsync(string email);
|
||||
Task<User> GetBySsoUserAsync(string externalId, Guid? organizationId);
|
||||
Task<UserKdfInformation> GetKdfInformationByEmailAsync(string email);
|
||||
Task<ICollection<User>> SearchAsync(string email, int skip, int take);
|
||||
Task<ICollection<User>> GetManyByPremiumAsync(bool premium);
|
||||
Task<string> GetPublicKeyAsync(Guid id);
|
||||
Task<DateTime> GetAccountRevisionDateAsync(Guid id);
|
||||
Task UpdateStorageAsync(Guid id);
|
||||
Task UpdateRenewalReminderDateAsync(Guid id, DateTime renewalReminderDate);
|
||||
Task<IEnumerable<User>> GetManyAsync(IEnumerable<Guid> ids);
|
||||
public interface IUserRepository : IRepository<User, Guid>
|
||||
{
|
||||
Task<User> GetByEmailAsync(string email);
|
||||
Task<User> GetBySsoUserAsync(string externalId, Guid? organizationId);
|
||||
Task<UserKdfInformation> GetKdfInformationByEmailAsync(string email);
|
||||
Task<ICollection<User>> SearchAsync(string email, int skip, int take);
|
||||
Task<ICollection<User>> GetManyByPremiumAsync(bool premium);
|
||||
Task<string> GetPublicKeyAsync(Guid id);
|
||||
Task<DateTime> GetAccountRevisionDateAsync(Guid id);
|
||||
Task UpdateStorageAsync(Guid id);
|
||||
Task UpdateRenewalReminderDateAsync(Guid id, DateTime renewalReminderDate);
|
||||
Task<IEnumerable<User>> GetManyAsync(IEnumerable<Guid> ids);
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,22 @@
|
||||
using Bit.Core.Models.Data;
|
||||
|
||||
namespace Bit.Core.Repositories.Noop;
|
||||
|
||||
public class InstallationDeviceRepository : IInstallationDeviceRepository
|
||||
namespace Bit.Core.Repositories.Noop
|
||||
{
|
||||
public Task UpsertAsync(InstallationDeviceEntity entity)
|
||||
public class InstallationDeviceRepository : IInstallationDeviceRepository
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
public Task UpsertAsync(InstallationDeviceEntity entity)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public Task UpsertManyAsync(IList<InstallationDeviceEntity> entities)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
public Task UpsertManyAsync(IList<InstallationDeviceEntity> entities)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public Task DeleteAsync(InstallationDeviceEntity entity)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
public Task DeleteAsync(InstallationDeviceEntity entity)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,30 @@
|
||||
namespace Bit.Core.Repositories.Noop;
|
||||
|
||||
public class MetaDataRepository : IMetaDataRepository
|
||||
namespace Bit.Core.Repositories.Noop
|
||||
{
|
||||
public Task DeleteAsync(string objectName, string id)
|
||||
public class MetaDataRepository : IMetaDataRepository
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
public Task DeleteAsync(string objectName, string id)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public Task<IDictionary<string, string>> GetAsync(string objectName, string id)
|
||||
{
|
||||
return Task.FromResult(null as IDictionary<string, string>);
|
||||
}
|
||||
public Task<IDictionary<string, string>> GetAsync(string objectName, string id)
|
||||
{
|
||||
return Task.FromResult(null as IDictionary<string, string>);
|
||||
}
|
||||
|
||||
public Task<string> GetAsync(string objectName, string id, string prop)
|
||||
{
|
||||
return Task.FromResult(null as string);
|
||||
}
|
||||
public Task<string> GetAsync(string objectName, string id, string prop)
|
||||
{
|
||||
return Task.FromResult(null as string);
|
||||
}
|
||||
|
||||
public Task UpsertAsync(string objectName, string id, IDictionary<string, string> dict)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
public Task UpsertAsync(string objectName, string id, IDictionary<string, string> dict)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public Task UpsertAsync(string objectName, string id, KeyValuePair<string, string> keyValuePair)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
public Task UpsertAsync(string objectName, string id, KeyValuePair<string, string> keyValuePair)
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,184 +4,185 @@ using Bit.Core.Settings;
|
||||
using Bit.Core.Utilities;
|
||||
using Microsoft.Azure.Cosmos.Table;
|
||||
|
||||
namespace Bit.Core.Repositories.TableStorage;
|
||||
|
||||
public class EventRepository : IEventRepository
|
||||
namespace Bit.Core.Repositories.TableStorage
|
||||
{
|
||||
private readonly CloudTable _table;
|
||||
|
||||
public EventRepository(GlobalSettings globalSettings)
|
||||
: this(globalSettings.Events.ConnectionString)
|
||||
{ }
|
||||
|
||||
public EventRepository(string storageConnectionString)
|
||||
public class EventRepository : IEventRepository
|
||||
{
|
||||
var storageAccount = CloudStorageAccount.Parse(storageConnectionString);
|
||||
var tableClient = storageAccount.CreateCloudTableClient();
|
||||
_table = tableClient.GetTableReference("event");
|
||||
}
|
||||
private readonly CloudTable _table;
|
||||
|
||||
public async Task<PagedResult<IEvent>> GetManyByUserAsync(Guid userId, DateTime startDate, DateTime endDate,
|
||||
PageOptions pageOptions)
|
||||
{
|
||||
return await GetManyAsync($"UserId={userId}", "Date={{0}}", startDate, endDate, pageOptions);
|
||||
}
|
||||
public EventRepository(GlobalSettings globalSettings)
|
||||
: this(globalSettings.Events.ConnectionString)
|
||||
{ }
|
||||
|
||||
public async Task<PagedResult<IEvent>> GetManyByOrganizationAsync(Guid organizationId,
|
||||
DateTime startDate, DateTime endDate, PageOptions pageOptions)
|
||||
{
|
||||
return await GetManyAsync($"OrganizationId={organizationId}", "Date={0}", startDate, endDate, pageOptions);
|
||||
}
|
||||
|
||||
public async Task<PagedResult<IEvent>> GetManyByOrganizationActingUserAsync(Guid organizationId, Guid actingUserId,
|
||||
DateTime startDate, DateTime endDate, PageOptions pageOptions)
|
||||
{
|
||||
return await GetManyAsync($"OrganizationId={organizationId}",
|
||||
$"ActingUserId={actingUserId}__Date={{0}}", startDate, endDate, pageOptions);
|
||||
}
|
||||
|
||||
public async Task<PagedResult<IEvent>> GetManyByProviderAsync(Guid providerId,
|
||||
DateTime startDate, DateTime endDate, PageOptions pageOptions)
|
||||
{
|
||||
return await GetManyAsync($"ProviderId={providerId}", "Date={0}", startDate, endDate, pageOptions);
|
||||
}
|
||||
|
||||
public async Task<PagedResult<IEvent>> GetManyByProviderActingUserAsync(Guid providerId, Guid actingUserId,
|
||||
DateTime startDate, DateTime endDate, PageOptions pageOptions)
|
||||
{
|
||||
return await GetManyAsync($"ProviderId={providerId}",
|
||||
$"ActingUserId={actingUserId}__Date={{0}}", startDate, endDate, pageOptions);
|
||||
}
|
||||
|
||||
public async Task<PagedResult<IEvent>> GetManyByCipherAsync(Cipher cipher, DateTime startDate, DateTime endDate,
|
||||
PageOptions pageOptions)
|
||||
{
|
||||
var partitionKey = cipher.OrganizationId.HasValue ?
|
||||
$"OrganizationId={cipher.OrganizationId}" : $"UserId={cipher.UserId}";
|
||||
return await GetManyAsync(partitionKey, $"CipherId={cipher.Id}__Date={{0}}", startDate, endDate, pageOptions);
|
||||
}
|
||||
|
||||
public async Task CreateAsync(IEvent e)
|
||||
{
|
||||
if (!(e is EventTableEntity entity))
|
||||
public EventRepository(string storageConnectionString)
|
||||
{
|
||||
throw new ArgumentException(nameof(e));
|
||||
var storageAccount = CloudStorageAccount.Parse(storageConnectionString);
|
||||
var tableClient = storageAccount.CreateCloudTableClient();
|
||||
_table = tableClient.GetTableReference("event");
|
||||
}
|
||||
|
||||
await CreateEntityAsync(entity);
|
||||
}
|
||||
|
||||
public async Task CreateManyAsync(IEnumerable<IEvent> e)
|
||||
{
|
||||
if (!e?.Any() ?? true)
|
||||
public async Task<PagedResult<IEvent>> GetManyByUserAsync(Guid userId, DateTime startDate, DateTime endDate,
|
||||
PageOptions pageOptions)
|
||||
{
|
||||
return;
|
||||
return await GetManyAsync($"UserId={userId}", "Date={{0}}", startDate, endDate, pageOptions);
|
||||
}
|
||||
|
||||
if (!e.Skip(1).Any())
|
||||
public async Task<PagedResult<IEvent>> GetManyByOrganizationAsync(Guid organizationId,
|
||||
DateTime startDate, DateTime endDate, PageOptions pageOptions)
|
||||
{
|
||||
await CreateAsync(e.First());
|
||||
return;
|
||||
return await GetManyAsync($"OrganizationId={organizationId}", "Date={0}", startDate, endDate, pageOptions);
|
||||
}
|
||||
|
||||
var entities = e.Where(ev => ev is EventTableEntity).Select(ev => ev as EventTableEntity);
|
||||
var entityGroups = entities.GroupBy(ent => ent.PartitionKey);
|
||||
foreach (var group in entityGroups)
|
||||
public async Task<PagedResult<IEvent>> GetManyByOrganizationActingUserAsync(Guid organizationId, Guid actingUserId,
|
||||
DateTime startDate, DateTime endDate, PageOptions pageOptions)
|
||||
{
|
||||
var groupEntities = group.ToList();
|
||||
if (groupEntities.Count == 1)
|
||||
return await GetManyAsync($"OrganizationId={organizationId}",
|
||||
$"ActingUserId={actingUserId}__Date={{0}}", startDate, endDate, pageOptions);
|
||||
}
|
||||
|
||||
public async Task<PagedResult<IEvent>> GetManyByProviderAsync(Guid providerId,
|
||||
DateTime startDate, DateTime endDate, PageOptions pageOptions)
|
||||
{
|
||||
return await GetManyAsync($"ProviderId={providerId}", "Date={0}", startDate, endDate, pageOptions);
|
||||
}
|
||||
|
||||
public async Task<PagedResult<IEvent>> GetManyByProviderActingUserAsync(Guid providerId, Guid actingUserId,
|
||||
DateTime startDate, DateTime endDate, PageOptions pageOptions)
|
||||
{
|
||||
return await GetManyAsync($"ProviderId={providerId}",
|
||||
$"ActingUserId={actingUserId}__Date={{0}}", startDate, endDate, pageOptions);
|
||||
}
|
||||
|
||||
public async Task<PagedResult<IEvent>> GetManyByCipherAsync(Cipher cipher, DateTime startDate, DateTime endDate,
|
||||
PageOptions pageOptions)
|
||||
{
|
||||
var partitionKey = cipher.OrganizationId.HasValue ?
|
||||
$"OrganizationId={cipher.OrganizationId}" : $"UserId={cipher.UserId}";
|
||||
return await GetManyAsync(partitionKey, $"CipherId={cipher.Id}__Date={{0}}", startDate, endDate, pageOptions);
|
||||
}
|
||||
|
||||
public async Task CreateAsync(IEvent e)
|
||||
{
|
||||
if (!(e is EventTableEntity entity))
|
||||
{
|
||||
await CreateEntityAsync(groupEntities.First());
|
||||
continue;
|
||||
throw new ArgumentException(nameof(e));
|
||||
}
|
||||
|
||||
// A batch insert can only contain 100 entities at a time
|
||||
var iterations = groupEntities.Count / 100;
|
||||
for (var i = 0; i <= iterations; i++)
|
||||
await CreateEntityAsync(entity);
|
||||
}
|
||||
|
||||
public async Task CreateManyAsync(IEnumerable<IEvent> e)
|
||||
{
|
||||
if (!e?.Any() ?? true)
|
||||
{
|
||||
var batch = new TableBatchOperation();
|
||||
var batchEntities = groupEntities.Skip(i * 100).Take(100);
|
||||
if (!batchEntities.Any())
|
||||
return;
|
||||
}
|
||||
|
||||
if (!e.Skip(1).Any())
|
||||
{
|
||||
await CreateAsync(e.First());
|
||||
return;
|
||||
}
|
||||
|
||||
var entities = e.Where(ev => ev is EventTableEntity).Select(ev => ev as EventTableEntity);
|
||||
var entityGroups = entities.GroupBy(ent => ent.PartitionKey);
|
||||
foreach (var group in entityGroups)
|
||||
{
|
||||
var groupEntities = group.ToList();
|
||||
if (groupEntities.Count == 1)
|
||||
{
|
||||
break;
|
||||
await CreateEntityAsync(groupEntities.First());
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var entity in batchEntities)
|
||||
// A batch insert can only contain 100 entities at a time
|
||||
var iterations = groupEntities.Count / 100;
|
||||
for (var i = 0; i <= iterations; i++)
|
||||
{
|
||||
batch.InsertOrReplace(entity);
|
||||
}
|
||||
var batch = new TableBatchOperation();
|
||||
var batchEntities = groupEntities.Skip(i * 100).Take(100);
|
||||
if (!batchEntities.Any())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
await _table.ExecuteBatchAsync(batch);
|
||||
foreach (var entity in batchEntities)
|
||||
{
|
||||
batch.InsertOrReplace(entity);
|
||||
}
|
||||
|
||||
await _table.ExecuteBatchAsync(batch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CreateEntityAsync(ITableEntity entity)
|
||||
{
|
||||
await _table.ExecuteAsync(TableOperation.InsertOrReplace(entity));
|
||||
}
|
||||
|
||||
public async Task<PagedResult<IEvent>> GetManyAsync(string partitionKey, string rowKey,
|
||||
DateTime startDate, DateTime endDate, PageOptions pageOptions)
|
||||
{
|
||||
var start = CoreHelpers.DateTimeToTableStorageKey(startDate);
|
||||
var end = CoreHelpers.DateTimeToTableStorageKey(endDate);
|
||||
var filter = MakeFilter(partitionKey, string.Format(rowKey, start), string.Format(rowKey, end));
|
||||
|
||||
var query = new TableQuery<EventTableEntity>().Where(filter).Take(pageOptions.PageSize);
|
||||
var result = new PagedResult<IEvent>();
|
||||
var continuationToken = DeserializeContinuationToken(pageOptions?.ContinuationToken);
|
||||
|
||||
var queryResults = await _table.ExecuteQuerySegmentedAsync(query, continuationToken);
|
||||
result.ContinuationToken = SerializeContinuationToken(queryResults.ContinuationToken);
|
||||
result.Data.AddRange(queryResults.Results);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private string MakeFilter(string partitionKey, string rowStart, string rowEnd)
|
||||
{
|
||||
var rowFilter = TableQuery.CombineFilters(
|
||||
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThanOrEqual, $"{rowStart}`"),
|
||||
TableOperators.And,
|
||||
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, $"{rowEnd}_"));
|
||||
|
||||
return TableQuery.CombineFilters(
|
||||
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey),
|
||||
TableOperators.And,
|
||||
rowFilter);
|
||||
}
|
||||
|
||||
private string SerializeContinuationToken(TableContinuationToken token)
|
||||
{
|
||||
if (token == null)
|
||||
public async Task CreateEntityAsync(ITableEntity entity)
|
||||
{
|
||||
return null;
|
||||
await _table.ExecuteAsync(TableOperation.InsertOrReplace(entity));
|
||||
}
|
||||
|
||||
return string.Format("{0}__{1}__{2}__{3}", (int)token.TargetLocation, token.NextTableName,
|
||||
token.NextPartitionKey, token.NextRowKey);
|
||||
}
|
||||
|
||||
private TableContinuationToken DeserializeContinuationToken(string token)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(token))
|
||||
public async Task<PagedResult<IEvent>> GetManyAsync(string partitionKey, string rowKey,
|
||||
DateTime startDate, DateTime endDate, PageOptions pageOptions)
|
||||
{
|
||||
return null;
|
||||
var start = CoreHelpers.DateTimeToTableStorageKey(startDate);
|
||||
var end = CoreHelpers.DateTimeToTableStorageKey(endDate);
|
||||
var filter = MakeFilter(partitionKey, string.Format(rowKey, start), string.Format(rowKey, end));
|
||||
|
||||
var query = new TableQuery<EventTableEntity>().Where(filter).Take(pageOptions.PageSize);
|
||||
var result = new PagedResult<IEvent>();
|
||||
var continuationToken = DeserializeContinuationToken(pageOptions?.ContinuationToken);
|
||||
|
||||
var queryResults = await _table.ExecuteQuerySegmentedAsync(query, continuationToken);
|
||||
result.ContinuationToken = SerializeContinuationToken(queryResults.ContinuationToken);
|
||||
result.Data.AddRange(queryResults.Results);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
var tokenParts = token.Split(new string[] { "__" }, StringSplitOptions.None);
|
||||
if (tokenParts.Length < 4 || !Enum.TryParse(tokenParts[0], out StorageLocation tLoc))
|
||||
private string MakeFilter(string partitionKey, string rowStart, string rowEnd)
|
||||
{
|
||||
return null;
|
||||
var rowFilter = TableQuery.CombineFilters(
|
||||
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.LessThanOrEqual, $"{rowStart}`"),
|
||||
TableOperators.And,
|
||||
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.GreaterThanOrEqual, $"{rowEnd}_"));
|
||||
|
||||
return TableQuery.CombineFilters(
|
||||
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey),
|
||||
TableOperators.And,
|
||||
rowFilter);
|
||||
}
|
||||
|
||||
return new TableContinuationToken
|
||||
private string SerializeContinuationToken(TableContinuationToken token)
|
||||
{
|
||||
TargetLocation = tLoc,
|
||||
NextTableName = string.IsNullOrWhiteSpace(tokenParts[1]) ? null : tokenParts[1],
|
||||
NextPartitionKey = string.IsNullOrWhiteSpace(tokenParts[2]) ? null : tokenParts[2],
|
||||
NextRowKey = string.IsNullOrWhiteSpace(tokenParts[3]) ? null : tokenParts[3]
|
||||
};
|
||||
if (token == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return string.Format("{0}__{1}__{2}__{3}", (int)token.TargetLocation, token.NextTableName,
|
||||
token.NextPartitionKey, token.NextRowKey);
|
||||
}
|
||||
|
||||
private TableContinuationToken DeserializeContinuationToken(string token)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(token))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var tokenParts = token.Split(new string[] { "__" }, StringSplitOptions.None);
|
||||
if (tokenParts.Length < 4 || !Enum.TryParse(tokenParts[0], out StorageLocation tLoc))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new TableContinuationToken
|
||||
{
|
||||
TargetLocation = tLoc,
|
||||
NextTableName = string.IsNullOrWhiteSpace(tokenParts[1]) ? null : tokenParts[1],
|
||||
NextPartitionKey = string.IsNullOrWhiteSpace(tokenParts[2]) ? null : tokenParts[2],
|
||||
NextRowKey = string.IsNullOrWhiteSpace(tokenParts[3]) ? null : tokenParts[3]
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,82 +3,83 @@ using Bit.Core.Models.Data;
|
||||
using Bit.Core.Settings;
|
||||
using Microsoft.Azure.Cosmos.Table;
|
||||
|
||||
namespace Bit.Core.Repositories.TableStorage;
|
||||
|
||||
public class InstallationDeviceRepository : IInstallationDeviceRepository
|
||||
namespace Bit.Core.Repositories.TableStorage
|
||||
{
|
||||
private readonly CloudTable _table;
|
||||
|
||||
public InstallationDeviceRepository(GlobalSettings globalSettings)
|
||||
: this(globalSettings.Events.ConnectionString)
|
||||
{ }
|
||||
|
||||
public InstallationDeviceRepository(string storageConnectionString)
|
||||
public class InstallationDeviceRepository : IInstallationDeviceRepository
|
||||
{
|
||||
var storageAccount = CloudStorageAccount.Parse(storageConnectionString);
|
||||
var tableClient = storageAccount.CreateCloudTableClient();
|
||||
_table = tableClient.GetTableReference("installationdevice");
|
||||
}
|
||||
private readonly CloudTable _table;
|
||||
|
||||
public async Task UpsertAsync(InstallationDeviceEntity entity)
|
||||
{
|
||||
await _table.ExecuteAsync(TableOperation.InsertOrReplace(entity));
|
||||
}
|
||||
public InstallationDeviceRepository(GlobalSettings globalSettings)
|
||||
: this(globalSettings.Events.ConnectionString)
|
||||
{ }
|
||||
|
||||
public async Task UpsertManyAsync(IList<InstallationDeviceEntity> entities)
|
||||
{
|
||||
if (!entities?.Any() ?? true)
|
||||
public InstallationDeviceRepository(string storageConnectionString)
|
||||
{
|
||||
return;
|
||||
var storageAccount = CloudStorageAccount.Parse(storageConnectionString);
|
||||
var tableClient = storageAccount.CreateCloudTableClient();
|
||||
_table = tableClient.GetTableReference("installationdevice");
|
||||
}
|
||||
|
||||
if (entities.Count == 1)
|
||||
public async Task UpsertAsync(InstallationDeviceEntity entity)
|
||||
{
|
||||
await UpsertAsync(entities.First());
|
||||
return;
|
||||
await _table.ExecuteAsync(TableOperation.InsertOrReplace(entity));
|
||||
}
|
||||
|
||||
var entityGroups = entities.GroupBy(ent => ent.PartitionKey);
|
||||
foreach (var group in entityGroups)
|
||||
public async Task UpsertManyAsync(IList<InstallationDeviceEntity> entities)
|
||||
{
|
||||
var groupEntities = group.ToList();
|
||||
if (groupEntities.Count == 1)
|
||||
if (!entities?.Any() ?? true)
|
||||
{
|
||||
await UpsertAsync(groupEntities.First());
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
|
||||
// A batch insert can only contain 100 entities at a time
|
||||
var iterations = groupEntities.Count / 100;
|
||||
for (var i = 0; i <= iterations; i++)
|
||||
if (entities.Count == 1)
|
||||
{
|
||||
var batch = new TableBatchOperation();
|
||||
var batchEntities = groupEntities.Skip(i * 100).Take(100);
|
||||
if (!batchEntities.Any())
|
||||
await UpsertAsync(entities.First());
|
||||
return;
|
||||
}
|
||||
|
||||
var entityGroups = entities.GroupBy(ent => ent.PartitionKey);
|
||||
foreach (var group in entityGroups)
|
||||
{
|
||||
var groupEntities = group.ToList();
|
||||
if (groupEntities.Count == 1)
|
||||
{
|
||||
break;
|
||||
await UpsertAsync(groupEntities.First());
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var entity in batchEntities)
|
||||
// A batch insert can only contain 100 entities at a time
|
||||
var iterations = groupEntities.Count / 100;
|
||||
for (var i = 0; i <= iterations; i++)
|
||||
{
|
||||
batch.InsertOrReplace(entity);
|
||||
}
|
||||
var batch = new TableBatchOperation();
|
||||
var batchEntities = groupEntities.Skip(i * 100).Take(100);
|
||||
if (!batchEntities.Any())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
await _table.ExecuteBatchAsync(batch);
|
||||
foreach (var entity in batchEntities)
|
||||
{
|
||||
batch.InsertOrReplace(entity);
|
||||
}
|
||||
|
||||
await _table.ExecuteBatchAsync(batch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(InstallationDeviceEntity entity)
|
||||
{
|
||||
try
|
||||
public async Task DeleteAsync(InstallationDeviceEntity entity)
|
||||
{
|
||||
entity.ETag = "*";
|
||||
await _table.ExecuteAsync(TableOperation.Delete(entity));
|
||||
}
|
||||
catch (StorageException e) when (e.RequestInformation.HttpStatusCode != (int)HttpStatusCode.NotFound)
|
||||
{
|
||||
throw;
|
||||
try
|
||||
{
|
||||
entity.ETag = "*";
|
||||
await _table.ExecuteAsync(TableOperation.Delete(entity));
|
||||
}
|
||||
catch (StorageException e) when (e.RequestInformation.HttpStatusCode != (int)HttpStatusCode.NotFound)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,91 +3,92 @@ using Bit.Core.Models.Data;
|
||||
using Bit.Core.Settings;
|
||||
using Microsoft.Azure.Cosmos.Table;
|
||||
|
||||
namespace Bit.Core.Repositories.TableStorage;
|
||||
|
||||
public class MetaDataRepository : IMetaDataRepository
|
||||
namespace Bit.Core.Repositories.TableStorage
|
||||
{
|
||||
private readonly CloudTable _table;
|
||||
|
||||
public MetaDataRepository(GlobalSettings globalSettings)
|
||||
: this(globalSettings.Events.ConnectionString)
|
||||
{ }
|
||||
|
||||
public MetaDataRepository(string storageConnectionString)
|
||||
public class MetaDataRepository : IMetaDataRepository
|
||||
{
|
||||
var storageAccount = CloudStorageAccount.Parse(storageConnectionString);
|
||||
var tableClient = storageAccount.CreateCloudTableClient();
|
||||
_table = tableClient.GetTableReference("metadata");
|
||||
}
|
||||
private readonly CloudTable _table;
|
||||
|
||||
public async Task<IDictionary<string, string>> GetAsync(string objectName, string id)
|
||||
{
|
||||
var query = new TableQuery<DictionaryEntity>().Where(
|
||||
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, $"{objectName}_{id}"));
|
||||
var queryResults = await _table.ExecuteQuerySegmentedAsync(query, null);
|
||||
return queryResults.Results.FirstOrDefault()?.ToDictionary(d => d.Key, d => d.Value.StringValue);
|
||||
}
|
||||
public MetaDataRepository(GlobalSettings globalSettings)
|
||||
: this(globalSettings.Events.ConnectionString)
|
||||
{ }
|
||||
|
||||
public async Task<string> GetAsync(string objectName, string id, string prop)
|
||||
{
|
||||
var dict = await GetAsync(objectName, id);
|
||||
if (dict != null && dict.ContainsKey(prop))
|
||||
public MetaDataRepository(string storageConnectionString)
|
||||
{
|
||||
return dict[prop];
|
||||
var storageAccount = CloudStorageAccount.Parse(storageConnectionString);
|
||||
var tableClient = storageAccount.CreateCloudTableClient();
|
||||
_table = tableClient.GetTableReference("metadata");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task UpsertAsync(string objectName, string id, KeyValuePair<string, string> keyValuePair)
|
||||
{
|
||||
var query = new TableQuery<DictionaryEntity>().Where(
|
||||
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, $"{objectName}_{id}"));
|
||||
var queryResults = await _table.ExecuteQuerySegmentedAsync(query, null);
|
||||
var entity = queryResults.Results.FirstOrDefault();
|
||||
if (entity == null)
|
||||
public async Task<IDictionary<string, string>> GetAsync(string objectName, string id)
|
||||
{
|
||||
entity = new DictionaryEntity
|
||||
var query = new TableQuery<DictionaryEntity>().Where(
|
||||
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, $"{objectName}_{id}"));
|
||||
var queryResults = await _table.ExecuteQuerySegmentedAsync(query, null);
|
||||
return queryResults.Results.FirstOrDefault()?.ToDictionary(d => d.Key, d => d.Value.StringValue);
|
||||
}
|
||||
|
||||
public async Task<string> GetAsync(string objectName, string id, string prop)
|
||||
{
|
||||
var dict = await GetAsync(objectName, id);
|
||||
if (dict != null && dict.ContainsKey(prop))
|
||||
{
|
||||
return dict[prop];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task UpsertAsync(string objectName, string id, KeyValuePair<string, string> keyValuePair)
|
||||
{
|
||||
var query = new TableQuery<DictionaryEntity>().Where(
|
||||
TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, $"{objectName}_{id}"));
|
||||
var queryResults = await _table.ExecuteQuerySegmentedAsync(query, null);
|
||||
var entity = queryResults.Results.FirstOrDefault();
|
||||
if (entity == null)
|
||||
{
|
||||
entity = new DictionaryEntity
|
||||
{
|
||||
PartitionKey = $"{objectName}_{id}",
|
||||
RowKey = string.Empty
|
||||
};
|
||||
}
|
||||
if (entity.ContainsKey(keyValuePair.Key))
|
||||
{
|
||||
entity.Remove(keyValuePair.Key);
|
||||
}
|
||||
entity.Add(keyValuePair.Key, keyValuePair.Value);
|
||||
await _table.ExecuteAsync(TableOperation.InsertOrReplace(entity));
|
||||
}
|
||||
|
||||
public async Task UpsertAsync(string objectName, string id, IDictionary<string, string> dict)
|
||||
{
|
||||
var entity = new DictionaryEntity
|
||||
{
|
||||
PartitionKey = $"{objectName}_{id}",
|
||||
RowKey = string.Empty
|
||||
};
|
||||
}
|
||||
if (entity.ContainsKey(keyValuePair.Key))
|
||||
{
|
||||
entity.Remove(keyValuePair.Key);
|
||||
}
|
||||
entity.Add(keyValuePair.Key, keyValuePair.Value);
|
||||
await _table.ExecuteAsync(TableOperation.InsertOrReplace(entity));
|
||||
}
|
||||
|
||||
public async Task UpsertAsync(string objectName, string id, IDictionary<string, string> dict)
|
||||
{
|
||||
var entity = new DictionaryEntity
|
||||
{
|
||||
PartitionKey = $"{objectName}_{id}",
|
||||
RowKey = string.Empty
|
||||
};
|
||||
foreach (var item in dict)
|
||||
{
|
||||
entity.Add(item.Key, item.Value);
|
||||
}
|
||||
await _table.ExecuteAsync(TableOperation.InsertOrReplace(entity));
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(string objectName, string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _table.ExecuteAsync(TableOperation.Delete(new DictionaryEntity
|
||||
foreach (var item in dict)
|
||||
{
|
||||
PartitionKey = $"{objectName}_{id}",
|
||||
RowKey = string.Empty,
|
||||
ETag = "*"
|
||||
}));
|
||||
entity.Add(item.Key, item.Value);
|
||||
}
|
||||
await _table.ExecuteAsync(TableOperation.InsertOrReplace(entity));
|
||||
}
|
||||
catch (StorageException e) when (e.RequestInformation.HttpStatusCode != (int)HttpStatusCode.NotFound)
|
||||
|
||||
public async Task DeleteAsync(string objectName, string id)
|
||||
{
|
||||
throw;
|
||||
try
|
||||
{
|
||||
await _table.ExecuteAsync(TableOperation.Delete(new DictionaryEntity
|
||||
{
|
||||
PartitionKey = $"{objectName}_{id}",
|
||||
RowKey = string.Empty,
|
||||
ETag = "*"
|
||||
}));
|
||||
}
|
||||
catch (StorageException e) when (e.RequestInformation.HttpStatusCode != (int)HttpStatusCode.NotFound)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user