mirror of
https://github.com/bitwarden/server
synced 2025-12-26 05:03:18 +00:00
[PM-22104] Migrate default collection when org user is removed (#6135)
* migrate default collection to a shared collection when users are removed * remove redundant logic * fix test * fix tests * fix test * clean up * add migrations * run dotnet format * clean up, refactor duplicate logic to sproc, wip integration test * fix sql * add migration for new sproc * integration test wip * integration test wip * integration test wip * integration test wip * fix integration test LINQ expression * fix using wrong Id * wip integration test for DeleteManyAsync * fix LINQ * only set DefaultUserEmail when it is null in sproc * check for null * spelling, separate create and update request models * fix test * fix child class * refactor sproc * clean up * more cleanup * fix tests * fix user email * remove unneccesary test * add DefaultUserCollectionEmail to EF query * fix test * fix EF logic to match sprocs * clean up logic * cleanup
This commit is contained in:
@@ -146,7 +146,7 @@ public class CollectionsController : Controller
|
||||
}
|
||||
|
||||
[HttpPost("")]
|
||||
public async Task<CollectionResponseModel> Post(Guid orgId, [FromBody] CollectionRequestModel model)
|
||||
public async Task<CollectionResponseModel> Post(Guid orgId, [FromBody] CreateCollectionRequestModel model)
|
||||
{
|
||||
var collection = model.ToCollection(orgId);
|
||||
|
||||
@@ -174,7 +174,7 @@ public class CollectionsController : Controller
|
||||
|
||||
[HttpPut("{id}")]
|
||||
[HttpPost("{id}")]
|
||||
public async Task<CollectionResponseModel> Put(Guid orgId, Guid id, [FromBody] CollectionRequestModel model)
|
||||
public async Task<CollectionResponseModel> Put(Guid orgId, Guid id, [FromBody] UpdateCollectionRequestModel model)
|
||||
{
|
||||
var collection = await _collectionRepository.GetByIdAsync(id);
|
||||
var authorized = (await _authorizationService.AuthorizeAsync(User, collection, BulkCollectionOperations.Update)).Succeeded;
|
||||
|
||||
@@ -7,7 +7,7 @@ using Bit.Core.Utilities;
|
||||
|
||||
namespace Bit.Api.Models.Request;
|
||||
|
||||
public class CollectionRequestModel
|
||||
public class CreateCollectionRequestModel
|
||||
{
|
||||
[Required]
|
||||
[EncryptedString]
|
||||
@@ -40,7 +40,7 @@ public class CollectionBulkDeleteRequestModel
|
||||
public IEnumerable<Guid> Ids { get; set; }
|
||||
}
|
||||
|
||||
public class CollectionWithIdRequestModel : CollectionRequestModel
|
||||
public class CollectionWithIdRequestModel : CreateCollectionRequestModel
|
||||
{
|
||||
public Guid? Id { get; set; }
|
||||
|
||||
@@ -50,3 +50,21 @@ public class CollectionWithIdRequestModel : CollectionRequestModel
|
||||
return base.ToCollection(existingCollection);
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateCollectionRequestModel : CreateCollectionRequestModel
|
||||
{
|
||||
[EncryptedString]
|
||||
[EncryptedStringLength(1000)]
|
||||
public new string Name { get; set; }
|
||||
|
||||
public override Collection ToCollection(Collection existingCollection)
|
||||
{
|
||||
if (string.IsNullOrEmpty(existingCollection.DefaultUserCollectionEmail) && !string.IsNullOrWhiteSpace(Name))
|
||||
{
|
||||
existingCollection.Name = Name;
|
||||
}
|
||||
existingCollection.ExternalId = ExternalId;
|
||||
return existingCollection;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ public class CollectionDetailsResponseModel : CollectionResponseModel
|
||||
ReadOnly = collectionDetails.ReadOnly;
|
||||
HidePasswords = collectionDetails.HidePasswords;
|
||||
Manage = collectionDetails.Manage;
|
||||
DefaultUserCollectionEmail = collectionDetails.DefaultUserCollectionEmail;
|
||||
}
|
||||
|
||||
public bool ReadOnly { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user