mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 16:12:49 -05:00
renaming subvault => collection
This commit is contained in:
@ -16,8 +16,8 @@ namespace Bit.Core.Services
|
||||
private readonly IUserRepository _userRepository;
|
||||
private readonly IOrganizationRepository _organizationRepository;
|
||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||
private readonly ISubvaultUserRepository _subvaultUserRepository;
|
||||
private readonly ISubvaultCipherRepository _subvaultCipherRepository;
|
||||
private readonly ICollectionUserRepository _collectionUserRepository;
|
||||
private readonly ICollectionCipherRepository _collectionCipherRepository;
|
||||
private readonly IPushService _pushService;
|
||||
|
||||
public CipherService(
|
||||
@ -26,8 +26,8 @@ namespace Bit.Core.Services
|
||||
IUserRepository userRepository,
|
||||
IOrganizationRepository organizationRepository,
|
||||
IOrganizationUserRepository organizationUserRepository,
|
||||
ISubvaultUserRepository subvaultUserRepository,
|
||||
ISubvaultCipherRepository subvaultCipherRepository,
|
||||
ICollectionUserRepository collectionUserRepository,
|
||||
ICollectionCipherRepository collectionCipherRepository,
|
||||
IPushService pushService)
|
||||
{
|
||||
_cipherRepository = cipherRepository;
|
||||
@ -35,8 +35,8 @@ namespace Bit.Core.Services
|
||||
_userRepository = userRepository;
|
||||
_organizationRepository = organizationRepository;
|
||||
_organizationUserRepository = organizationUserRepository;
|
||||
_subvaultUserRepository = subvaultUserRepository;
|
||||
_subvaultCipherRepository = subvaultCipherRepository;
|
||||
_collectionUserRepository = collectionUserRepository;
|
||||
_collectionCipherRepository = collectionCipherRepository;
|
||||
_pushService = pushService;
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ namespace Bit.Core.Services
|
||||
await _pushService.PushSyncFolderDeleteAsync(folder);
|
||||
}
|
||||
|
||||
public async Task ShareAsync(Cipher cipher, Guid organizationId, IEnumerable<Guid> subvaultIds, Guid sharingUserId)
|
||||
public async Task ShareAsync(Cipher cipher, Guid organizationId, IEnumerable<Guid> collectionIds, Guid sharingUserId)
|
||||
{
|
||||
if(cipher.Id == default(Guid))
|
||||
{
|
||||
@ -122,17 +122,17 @@ namespace Bit.Core.Services
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
// Sproc will not save this UserId on the cipher. It is used limit scope of the subvaultIds.
|
||||
// Sproc will not save this UserId on the cipher. It is used limit scope of the collectionIds.
|
||||
cipher.UserId = sharingUserId;
|
||||
cipher.OrganizationId = organizationId;
|
||||
cipher.RevisionDate = DateTime.UtcNow;
|
||||
await _cipherRepository.ReplaceAsync(cipher, subvaultIds);
|
||||
await _cipherRepository.ReplaceAsync(cipher, collectionIds);
|
||||
|
||||
// push
|
||||
await _pushService.PushSyncCipherUpdateAsync(cipher);
|
||||
}
|
||||
|
||||
public async Task SaveSubvaultsAsync(Cipher cipher, IEnumerable<Guid> subvaultIds, Guid savingUserId, bool orgAdmin)
|
||||
public async Task SaveCollectionsAsync(Cipher cipher, IEnumerable<Guid> collectionIds, Guid savingUserId, bool orgAdmin)
|
||||
{
|
||||
if(cipher.Id == default(Guid))
|
||||
{
|
||||
@ -144,15 +144,15 @@ namespace Bit.Core.Services
|
||||
throw new BadRequestException("Cipher must belong to an organization.");
|
||||
}
|
||||
|
||||
// The sprocs will validate that all subvaults belong to this org/user and that they have proper write permissions.
|
||||
// The sprocs will validate that all collections belong to this org/user and that they have proper write permissions.
|
||||
if(orgAdmin)
|
||||
{
|
||||
await _subvaultCipherRepository.UpdateSubvaultsForAdminAsync(cipher.Id, cipher.OrganizationId.Value,
|
||||
subvaultIds);
|
||||
await _collectionCipherRepository.UpdateCollectionsForAdminAsync(cipher.Id, cipher.OrganizationId.Value,
|
||||
collectionIds);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _subvaultCipherRepository.UpdateSubvaultsAsync(cipher.Id, savingUserId, subvaultIds);
|
||||
await _collectionCipherRepository.UpdateCollectionsAsync(cipher.Id, savingUserId, collectionIds);
|
||||
}
|
||||
|
||||
// push
|
||||
@ -213,7 +213,7 @@ namespace Bit.Core.Services
|
||||
return true;
|
||||
}
|
||||
|
||||
return await _subvaultUserRepository.GetCanEditByUserIdCipherIdAsync(userId, cipher.Id);
|
||||
return await _collectionUserRepository.GetCanEditByUserIdCipherIdAsync(userId, cipher.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ namespace Bit.Core.Services
|
||||
{
|
||||
private readonly IOrganizationRepository _organizationRepository;
|
||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||
private readonly ISubvaultRepository _subvaultRepository;
|
||||
private readonly ISubvaultUserRepository _subvaultUserRepository;
|
||||
private readonly ICollectionRepository _collectionRepository;
|
||||
private readonly ICollectionUserRepository _collectionUserRepository;
|
||||
private readonly IUserRepository _userRepository;
|
||||
private readonly IDataProtector _dataProtector;
|
||||
private readonly IMailService _mailService;
|
||||
@ -28,8 +28,8 @@ namespace Bit.Core.Services
|
||||
public OrganizationService(
|
||||
IOrganizationRepository organizationRepository,
|
||||
IOrganizationUserRepository organizationUserRepository,
|
||||
ISubvaultRepository subvaultRepository,
|
||||
ISubvaultUserRepository subvaultUserRepository,
|
||||
ICollectionRepository collectionRepository,
|
||||
ICollectionUserRepository collectionUserRepository,
|
||||
IUserRepository userRepository,
|
||||
IDataProtectionProvider dataProtectionProvider,
|
||||
IMailService mailService,
|
||||
@ -37,8 +37,8 @@ namespace Bit.Core.Services
|
||||
{
|
||||
_organizationRepository = organizationRepository;
|
||||
_organizationUserRepository = organizationUserRepository;
|
||||
_subvaultRepository = subvaultRepository;
|
||||
_subvaultUserRepository = subvaultUserRepository;
|
||||
_collectionRepository = collectionRepository;
|
||||
_collectionUserRepository = collectionUserRepository;
|
||||
_userRepository = userRepository;
|
||||
_dataProtector = dataProtectionProvider.CreateProtector("OrganizationServiceDataProtector");
|
||||
_mailService = mailService;
|
||||
@ -269,15 +269,15 @@ namespace Bit.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
if(newPlan.MaxSubvaults.HasValue &&
|
||||
(!organization.MaxSubvaults.HasValue || organization.MaxSubvaults.Value > newPlan.MaxSubvaults.Value))
|
||||
if(newPlan.MaxCollections.HasValue &&
|
||||
(!organization.MaxCollections.HasValue || organization.MaxCollections.Value > newPlan.MaxCollections.Value))
|
||||
{
|
||||
var subvaultCount = await _subvaultRepository.GetCountByOrganizationIdAsync(organization.Id);
|
||||
if(subvaultCount > newPlan.MaxSubvaults.Value)
|
||||
var collectionCount = await _collectionRepository.GetCountByOrganizationIdAsync(organization.Id);
|
||||
if(collectionCount > newPlan.MaxCollections.Value)
|
||||
{
|
||||
throw new BadRequestException($"Your organization currently has {subvaultCount} subvaults. " +
|
||||
$"Your new plan allows for a maximum of ({newPlan.MaxSubvaults.Value}) subvaults. " +
|
||||
"Remove some subvaults.");
|
||||
throw new BadRequestException($"Your organization currently has {collectionCount} collections. " +
|
||||
$"Your new plan allows for a maximum of ({newPlan.MaxCollections.Value}) collections. " +
|
||||
"Remove some collections.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -551,7 +551,7 @@ namespace Bit.Core.Services
|
||||
BusinessName = signup.BusinessName,
|
||||
PlanType = plan.Type,
|
||||
Seats = (short)(plan.BaseSeats + signup.AdditionalSeats),
|
||||
MaxSubvaults = plan.MaxSubvaults,
|
||||
MaxCollections = plan.MaxCollections,
|
||||
Plan = plan.Name,
|
||||
StripeCustomerId = customer?.Id,
|
||||
StripeSubscriptionId = subscription?.Id,
|
||||
@ -570,7 +570,7 @@ namespace Bit.Core.Services
|
||||
Key = signup.OwnerKey,
|
||||
Type = OrganizationUserType.Owner,
|
||||
Status = OrganizationUserStatusType.Confirmed,
|
||||
AccessAllSubvaults = true,
|
||||
AccessAllCollections = true,
|
||||
CreationDate = DateTime.UtcNow,
|
||||
RevisionDate = DateTime.UtcNow
|
||||
};
|
||||
@ -672,7 +672,7 @@ namespace Bit.Core.Services
|
||||
}
|
||||
|
||||
public async Task<OrganizationUser> InviteUserAsync(Guid organizationId, Guid invitingUserId, string email,
|
||||
OrganizationUserType type, bool accessAllSubvaults, IEnumerable<SubvaultUser> subvaults)
|
||||
OrganizationUserType type, bool accessAllCollections, IEnumerable<CollectionUser> collections)
|
||||
{
|
||||
var organization = await _organizationRepository.GetByIdAsync(organizationId);
|
||||
if(organization == null)
|
||||
@ -705,15 +705,15 @@ namespace Bit.Core.Services
|
||||
Key = null,
|
||||
Type = type,
|
||||
Status = OrganizationUserStatusType.Invited,
|
||||
AccessAllSubvaults = accessAllSubvaults,
|
||||
AccessAllCollections = accessAllCollections,
|
||||
CreationDate = DateTime.UtcNow,
|
||||
RevisionDate = DateTime.UtcNow
|
||||
};
|
||||
|
||||
await _organizationUserRepository.CreateAsync(orgUser);
|
||||
if(!orgUser.AccessAllSubvaults && subvaults.Any())
|
||||
if(!orgUser.AccessAllCollections && collections.Any())
|
||||
{
|
||||
await SaveUserSubvaultsAsync(orgUser, subvaults, true);
|
||||
await SaveUserCollectionsAsync(orgUser, collections, true);
|
||||
}
|
||||
await SendInviteAsync(orgUser);
|
||||
|
||||
@ -820,7 +820,7 @@ namespace Bit.Core.Services
|
||||
return orgUser;
|
||||
}
|
||||
|
||||
public async Task SaveUserAsync(OrganizationUser user, Guid savingUserId, IEnumerable<SubvaultUser> subvaults)
|
||||
public async Task SaveUserAsync(OrganizationUser user, Guid savingUserId, IEnumerable<CollectionUser> collections)
|
||||
{
|
||||
if(user.Id.Equals(default(Guid)))
|
||||
{
|
||||
@ -835,12 +835,12 @@ namespace Bit.Core.Services
|
||||
|
||||
await _organizationUserRepository.ReplaceAsync(user);
|
||||
|
||||
if(user.AccessAllSubvaults)
|
||||
if(user.AccessAllCollections)
|
||||
{
|
||||
// We don't need any subvaults if we're flagged to have all access.
|
||||
subvaults = new List<SubvaultUser>();
|
||||
// We don't need any collections if we're flagged to have all access.
|
||||
collections = new List<CollectionUser>();
|
||||
}
|
||||
await SaveUserSubvaultsAsync(user, subvaults, false);
|
||||
await SaveUserCollectionsAsync(user, collections, false);
|
||||
}
|
||||
|
||||
public async Task DeleteUserAsync(Guid organizationId, Guid organizationUserId, Guid deletingUserId)
|
||||
@ -889,38 +889,38 @@ namespace Bit.Core.Services
|
||||
return owners.Where(o => o.Status == Enums.OrganizationUserStatusType.Confirmed);
|
||||
}
|
||||
|
||||
private async Task SaveUserSubvaultsAsync(OrganizationUser user, IEnumerable<SubvaultUser> subvaults, bool newUser)
|
||||
private async Task SaveUserCollectionsAsync(OrganizationUser user, IEnumerable<CollectionUser> collections, bool newUser)
|
||||
{
|
||||
if(subvaults == null)
|
||||
if(collections == null)
|
||||
{
|
||||
subvaults = new List<SubvaultUser>();
|
||||
collections = new List<CollectionUser>();
|
||||
}
|
||||
|
||||
var orgSubvaults = await _subvaultRepository.GetManyByOrganizationIdAsync(user.OrganizationId);
|
||||
var currentUserSubvaults = newUser ? null : await _subvaultUserRepository.GetManyByOrganizationUserIdAsync(user.Id);
|
||||
var orgCollections = await _collectionRepository.GetManyByOrganizationIdAsync(user.OrganizationId);
|
||||
var currentUserCollections = newUser ? null : await _collectionUserRepository.GetManyByOrganizationUserIdAsync(user.Id);
|
||||
|
||||
// Let's make sure all these belong to this user and organization.
|
||||
var filteredSubvaults = subvaults.Where(s => orgSubvaults.Any(os => os.Id == s.SubvaultId));
|
||||
foreach(var subvault in filteredSubvaults)
|
||||
var filteredCollections = collections.Where(s => orgCollections.Any(os => os.Id == s.CollectionId));
|
||||
foreach(var collection in filteredCollections)
|
||||
{
|
||||
var existingSubvaultUser = currentUserSubvaults?.FirstOrDefault(cs => cs.SubvaultId == subvault.SubvaultId);
|
||||
if(existingSubvaultUser != null)
|
||||
var existingCollectionUser = currentUserCollections?.FirstOrDefault(cs => cs.CollectionId == collection.CollectionId);
|
||||
if(existingCollectionUser != null)
|
||||
{
|
||||
subvault.Id = existingSubvaultUser.Id;
|
||||
subvault.CreationDate = existingSubvaultUser.CreationDate;
|
||||
collection.Id = existingCollectionUser.Id;
|
||||
collection.CreationDate = existingCollectionUser.CreationDate;
|
||||
}
|
||||
|
||||
subvault.OrganizationUserId = user.Id;
|
||||
await _subvaultUserRepository.UpsertAsync(subvault);
|
||||
collection.OrganizationUserId = user.Id;
|
||||
await _collectionUserRepository.UpsertAsync(collection);
|
||||
}
|
||||
|
||||
if(!newUser)
|
||||
{
|
||||
var subvaultsToDelete = currentUserSubvaults.Where(cs =>
|
||||
!filteredSubvaults.Any(s => s.SubvaultId == cs.SubvaultId));
|
||||
foreach(var subvault in subvaultsToDelete)
|
||||
var collectionsToDelete = currentUserCollections.Where(cs =>
|
||||
!filteredCollections.Any(s => s.CollectionId == cs.CollectionId));
|
||||
foreach(var collection in collectionsToDelete)
|
||||
{
|
||||
await _subvaultUserRepository.DeleteAsync(subvault);
|
||||
await _collectionUserRepository.DeleteAsync(collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,56 +6,56 @@ using Bit.Core.Repositories;
|
||||
|
||||
namespace Bit.Core.Services
|
||||
{
|
||||
public class SubvaultService : ISubvaultService
|
||||
public class CollectionService : ICollectionService
|
||||
{
|
||||
private readonly IOrganizationRepository _organizationRepository;
|
||||
private readonly IOrganizationUserRepository _organizationUserRepository;
|
||||
private readonly ISubvaultRepository _subvaultRepository;
|
||||
private readonly ISubvaultUserRepository _subvaultUserRepository;
|
||||
private readonly ICollectionRepository _collectionRepository;
|
||||
private readonly ICollectionUserRepository _collectionUserRepository;
|
||||
private readonly IUserRepository _userRepository;
|
||||
private readonly IMailService _mailService;
|
||||
|
||||
public SubvaultService(
|
||||
public CollectionService(
|
||||
IOrganizationRepository organizationRepository,
|
||||
IOrganizationUserRepository organizationUserRepository,
|
||||
ISubvaultRepository subvaultRepository,
|
||||
ISubvaultUserRepository subvaultUserRepository,
|
||||
ICollectionRepository collectionRepository,
|
||||
ICollectionUserRepository collectionUserRepository,
|
||||
IUserRepository userRepository,
|
||||
IMailService mailService)
|
||||
{
|
||||
_organizationRepository = organizationRepository;
|
||||
_organizationUserRepository = organizationUserRepository;
|
||||
_subvaultRepository = subvaultRepository;
|
||||
_subvaultUserRepository = subvaultUserRepository;
|
||||
_collectionRepository = collectionRepository;
|
||||
_collectionUserRepository = collectionUserRepository;
|
||||
_userRepository = userRepository;
|
||||
_mailService = mailService;
|
||||
}
|
||||
|
||||
public async Task SaveAsync(Subvault subvault)
|
||||
public async Task SaveAsync(Collection collection)
|
||||
{
|
||||
if(subvault.Id == default(Guid))
|
||||
if(collection.Id == default(Guid))
|
||||
{
|
||||
var org = await _organizationRepository.GetByIdAsync(subvault.OrganizationId);
|
||||
var org = await _organizationRepository.GetByIdAsync(collection.OrganizationId);
|
||||
if(org == null)
|
||||
{
|
||||
throw new BadRequestException("Org not found");
|
||||
}
|
||||
|
||||
if(org.MaxSubvaults.HasValue)
|
||||
if(org.MaxCollections.HasValue)
|
||||
{
|
||||
var subvaultCount = await _subvaultRepository.GetCountByOrganizationIdAsync(org.Id);
|
||||
if(org.MaxSubvaults.Value <= subvaultCount)
|
||||
var collectionCount = await _collectionRepository.GetCountByOrganizationIdAsync(org.Id);
|
||||
if(org.MaxCollections.Value <= collectionCount)
|
||||
{
|
||||
throw new BadRequestException("You have reached the maximum number of subvaults " +
|
||||
$"({org.MaxSubvaults.Value}) for this organization.");
|
||||
throw new BadRequestException("You have reached the maximum number of collections " +
|
||||
$"({org.MaxCollections.Value}) for this organization.");
|
||||
}
|
||||
}
|
||||
|
||||
await _subvaultRepository.CreateAsync(subvault);
|
||||
await _collectionRepository.CreateAsync(collection);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _subvaultRepository.ReplaceAsync(subvault);
|
||||
await _collectionRepository.ReplaceAsync(collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user