Skip to content

Commit 5b8b394

Browse files
allow for archived ciphers to be shared into an organization (#6626)
1 parent 71be386 commit 5b8b394

File tree

3 files changed

+0
-132
lines changed

3 files changed

+0
-132
lines changed

src/Api/Vault/Controllers/CiphersController.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -757,11 +757,6 @@ public async Task<CipherResponseModel> PutShare(Guid id, [FromBody] CipherShareR
757757
}
758758
}
759759

760-
if (cipher.ArchivedDate.HasValue)
761-
{
762-
throw new BadRequestException("Cannot move an archived item to an organization.");
763-
}
764-
765760
ValidateClientVersionForFido2CredentialSupport(cipher);
766761

767762
var original = cipher.Clone();
@@ -1271,11 +1266,6 @@ public async Task<ListResponseModel<CipherMiniResponseModel>> PutShareMany([From
12711266
_logger.LogError("Cipher was not encrypted for the current user. CipherId: {CipherId}, CurrentUser: {CurrentUserId}, EncryptedFor: {EncryptedFor}", cipher.Id, userId, cipher.EncryptedFor);
12721267
throw new BadRequestException("Cipher was not encrypted for the current user. Please try again.");
12731268
}
1274-
1275-
if (cipher.ArchivedDate.HasValue)
1276-
{
1277-
throw new BadRequestException("Cannot move archived items to an organization.");
1278-
}
12791269
}
12801270

12811271
var shareCiphers = new List<(CipherDetails, DateTime?)>();
@@ -1288,11 +1278,6 @@ public async Task<ListResponseModel<CipherMiniResponseModel>> PutShareMany([From
12881278

12891279
ValidateClientVersionForFido2CredentialSupport(existingCipher);
12901280

1291-
if (existingCipher.ArchivedDate.HasValue)
1292-
{
1293-
throw new BadRequestException("Cannot move archived items to an organization.");
1294-
}
1295-
12961281
shareCiphers.Add((cipher.ToCipherDetails(existingCipher), cipher.LastKnownRevisionDate));
12971282
}
12981283

src/Core/Vault/Services/Implementations/CipherService.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -990,11 +990,6 @@ private async Task ValidateCipherCanBeShared(
990990
throw new BadRequestException("One or more ciphers do not belong to you.");
991991
}
992992

993-
if (cipher.ArchivedDate.HasValue)
994-
{
995-
throw new BadRequestException("Cipher cannot be shared with organization because it is archived.");
996-
}
997-
998993
var attachments = cipher.GetAttachments();
999994
var hasAttachments = attachments?.Any() ?? false;
1000995
var org = await _organizationRepository.GetByIdAsync(organizationId);

test/Api.Test/Vault/Controllers/CiphersControllerTests.cs

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,118 +1790,6 @@ await Assert.ThrowsAsync<NotFoundException>(
17901790
);
17911791
}
17921792

1793-
[Theory, BitAutoData]
1794-
public async Task PutShareMany_ArchivedCipher_ThrowsBadRequestException(
1795-
Guid organizationId,
1796-
Guid userId,
1797-
CipherWithIdRequestModel request,
1798-
SutProvider<CiphersController> sutProvider)
1799-
{
1800-
request.EncryptedFor = userId;
1801-
request.OrganizationId = organizationId.ToString();
1802-
request.ArchivedDate = DateTime.UtcNow;
1803-
var model = new CipherBulkShareRequestModel
1804-
{
1805-
Ciphers = [request],
1806-
CollectionIds = [Guid.NewGuid().ToString()]
1807-
};
1808-
1809-
sutProvider.GetDependency<ICurrentContext>()
1810-
.OrganizationUser(organizationId)
1811-
.Returns(Task.FromResult(true));
1812-
sutProvider.GetDependency<IUserService>()
1813-
.GetProperUserId(default)
1814-
.ReturnsForAnyArgs(userId);
1815-
1816-
var exception = await Assert.ThrowsAsync<BadRequestException>(
1817-
() => sutProvider.Sut.PutShareMany(model)
1818-
);
1819-
1820-
Assert.Equal("Cannot move archived items to an organization.", exception.Message);
1821-
}
1822-
1823-
[Theory, BitAutoData]
1824-
public async Task PutShareMany_ExistingCipherArchived_ThrowsBadRequestException(
1825-
Guid organizationId,
1826-
Guid userId,
1827-
CipherWithIdRequestModel request,
1828-
SutProvider<CiphersController> sutProvider)
1829-
{
1830-
// Request model does not have ArchivedDate (only the existing cipher does)
1831-
request.EncryptedFor = userId;
1832-
request.OrganizationId = organizationId.ToString();
1833-
request.ArchivedDate = null;
1834-
1835-
var model = new CipherBulkShareRequestModel
1836-
{
1837-
Ciphers = [request],
1838-
CollectionIds = [Guid.NewGuid().ToString()]
1839-
};
1840-
1841-
// The existing cipher from the repository IS archived
1842-
var existingCipher = new CipherDetails
1843-
{
1844-
Id = request.Id!.Value,
1845-
UserId = userId,
1846-
Type = CipherType.Login,
1847-
Data = JsonSerializer.Serialize(new CipherLoginData()),
1848-
ArchivedDate = DateTime.UtcNow
1849-
};
1850-
1851-
sutProvider.GetDependency<ICurrentContext>()
1852-
.OrganizationUser(organizationId)
1853-
.Returns(Task.FromResult(true));
1854-
sutProvider.GetDependency<IUserService>()
1855-
.GetProperUserId(default)
1856-
.ReturnsForAnyArgs(userId);
1857-
sutProvider.GetDependency<ICipherRepository>()
1858-
.GetManyByUserIdAsync(userId, withOrganizations: false)
1859-
.Returns(Task.FromResult((ICollection<CipherDetails>)[existingCipher]));
1860-
1861-
var exception = await Assert.ThrowsAsync<BadRequestException>(
1862-
() => sutProvider.Sut.PutShareMany(model)
1863-
);
1864-
1865-
Assert.Equal("Cannot move archived items to an organization.", exception.Message);
1866-
}
1867-
1868-
[Theory, BitAutoData]
1869-
public async Task PutShare_ArchivedCipher_ThrowsBadRequestException(
1870-
Guid cipherId,
1871-
Guid organizationId,
1872-
User user,
1873-
CipherShareRequestModel model,
1874-
SutProvider<CiphersController> sutProvider)
1875-
{
1876-
model.Cipher.OrganizationId = organizationId.ToString();
1877-
model.Cipher.EncryptedFor = user.Id;
1878-
1879-
var cipher = new Cipher
1880-
{
1881-
Id = cipherId,
1882-
UserId = user.Id,
1883-
ArchivedDate = DateTime.UtcNow.AddDays(-1),
1884-
Type = CipherType.Login,
1885-
Data = JsonSerializer.Serialize(new CipherLoginData())
1886-
};
1887-
1888-
sutProvider.GetDependency<IUserService>()
1889-
.GetUserByPrincipalAsync(Arg.Any<ClaimsPrincipal>())
1890-
.Returns(user);
1891-
sutProvider.GetDependency<ICipherRepository>()
1892-
.GetByIdAsync(cipherId)
1893-
.Returns(cipher);
1894-
sutProvider.GetDependency<ICurrentContext>()
1895-
.OrganizationUser(organizationId)
1896-
.Returns(Task.FromResult(true));
1897-
1898-
var exception = await Assert.ThrowsAsync<BadRequestException>(
1899-
() => sutProvider.Sut.PutShare(cipherId, model)
1900-
);
1901-
1902-
Assert.Equal("Cannot move an archived item to an organization.", exception.Message);
1903-
}
1904-
19051793
[Theory, BitAutoData]
19061794
public async Task PostPurge_WhenUserNotFound_ThrowsUnauthorizedAccessException(
19071795
SecretVerificationRequestModel model,

0 commit comments

Comments
 (0)