diff --git a/src/Sql/dbo/Vault/Stored Procedures/Cipher/Cipher_CreateWithCollections.sql b/src/Sql/dbo/Vault/Stored Procedures/Cipher/Cipher_CreateWithCollections.sql index 2a53a2d095..123ebd4e5e 100644 --- a/src/Sql/dbo/Vault/Stored Procedures/Cipher/Cipher_CreateWithCollections.sql +++ b/src/Sql/dbo/Vault/Stored Procedures/Cipher/Cipher_CreateWithCollections.sql @@ -20,7 +20,7 @@ BEGIN SET NOCOUNT ON EXEC [dbo].[Cipher_Create] @Id, @UserId, @OrganizationId, @Type, @Data, @Favorites, @Folders, - @Attachments, @CreationDate, @RevisionDate, @DeletedDate, @Reprompt, @Key, @ArchivedDate + @Attachments, @CreationDate, @RevisionDate, @DeletedDate, @Reprompt, @Key, @ArchivedDate, @Archives DECLARE @UpdateCollectionsSuccess INT EXEC @UpdateCollectionsSuccess = [dbo].[Cipher_UpdateCollections] @Id, @UserId, @OrganizationId, @CollectionIds diff --git a/src/Sql/dbo/Vault/Stored Procedures/Cipher/Cipher_Update.sql b/src/Sql/dbo/Vault/Stored Procedures/Cipher/Cipher_Update.sql index 912badc906..5147754ce4 100644 --- a/src/Sql/dbo/Vault/Stored Procedures/Cipher/Cipher_Update.sql +++ b/src/Sql/dbo/Vault/Stored Procedures/Cipher/Cipher_Update.sql @@ -12,7 +12,8 @@ @DeletedDate DATETIME2(7), @Reprompt TINYINT, @Key VARCHAR(MAX) = NULL, - @ArchivedDate DATETIME2(7) = NULL + @ArchivedDate DATETIME2(7) = NULL, + @Archives NVARCHAR(MAX) = NULL AS BEGIN SET NOCOUNT ON @@ -32,7 +33,8 @@ BEGIN [DeletedDate] = @DeletedDate, [Reprompt] = @Reprompt, [Key] = @Key, - [ArchivedDate] = @ArchivedDate + [ArchivedDate] = @ArchivedDate, + [Archives] = @Archives WHERE [Id] = @Id diff --git a/test/Core.Test/Vault/Commands/ArchiveCiphersCommandTest.cs b/test/Core.Test/Vault/Commands/ArchiveCiphersCommandTest.cs index 624db7941d..d1782197d2 100644 --- a/test/Core.Test/Vault/Commands/ArchiveCiphersCommandTest.cs +++ b/test/Core.Test/Vault/Commands/ArchiveCiphersCommandTest.cs @@ -46,4 +46,36 @@ public class ArchiveCiphersCommandTest await sutProvider.GetDependency().Received(pushNotificationsCalls) .PushSyncCiphersAsync(user.Id); } + + [Theory] + [BitAutoData] + public async Task ArchiveAsync_SetsArchivedDateOnReturnedCiphers( + SutProvider sutProvider, + CipherDetails cipher, + User user) + { + // Arrange: make it archivable + cipher.Edit = true; + cipher.OrganizationId = null; + cipher.ArchivedDate = null; + + sutProvider.GetDependency() + .GetManyByUserIdAsync(user.Id) + .Returns(new List { cipher }); + + var repoRevisionDate = DateTime.UtcNow; + + sutProvider.GetDependency() + .ArchiveAsync(Arg.Any>(), user.Id) + .Returns(repoRevisionDate); + + // Act + var result = await sutProvider.Sut.ArchiveManyAsync(new[] { cipher.Id }, user.Id); + + // Assert + var archivedCipher = Assert.Single(result); + Assert.Equal(repoRevisionDate, archivedCipher.RevisionDate); + Assert.Equal(repoRevisionDate, archivedCipher.ArchivedDate); + } + } diff --git a/test/Core.Test/Vault/Commands/UnarchiveCiphersCommandTest.cs b/test/Core.Test/Vault/Commands/UnarchiveCiphersCommandTest.cs index 0a41f1cce8..70eb010c37 100644 --- a/test/Core.Test/Vault/Commands/UnarchiveCiphersCommandTest.cs +++ b/test/Core.Test/Vault/Commands/UnarchiveCiphersCommandTest.cs @@ -46,4 +46,35 @@ public class UnarchiveCiphersCommandTest await sutProvider.GetDependency().Received(pushNotificationsCalls) .PushSyncCiphersAsync(user.Id); } + + [Theory] + [BitAutoData] + public async Task UnarchiveAsync_ClearsArchivedDateOnReturnedCiphers( + SutProvider sutProvider, + CipherDetails cipher, + User user) + { + // Arrange: make it unarchivable + cipher.Edit = true; + cipher.OrganizationId = null; + cipher.ArchivedDate = DateTime.UtcNow; + + sutProvider.GetDependency() + .GetManyByUserIdAsync(user.Id) + .Returns(new List { cipher }); + + var repoRevisionDate = DateTime.UtcNow.AddMinutes(1); + + sutProvider.GetDependency() + .UnarchiveAsync(Arg.Any>(), user.Id) + .Returns(repoRevisionDate); + + // Act + var result = await sutProvider.Sut.UnarchiveManyAsync(new[] { cipher.Id }, user.Id); + + // Assert + var unarchivedCipher = Assert.Single(result); + Assert.Equal(repoRevisionDate, unarchivedCipher.RevisionDate); + Assert.Null(unarchivedCipher.ArchivedDate); + } } diff --git a/util/Migrator/DbScripts/2025-12-02_AddCipherArchives.sql b/util/Migrator/DbScripts/2025-12-02_AddCipherArchives.sql index 681c25d3b1..d144fe39f3 100644 --- a/util/Migrator/DbScripts/2025-12-02_AddCipherArchives.sql +++ b/util/Migrator/DbScripts/2025-12-02_AddCipherArchives.sql @@ -363,7 +363,7 @@ BEGIN SET NOCOUNT ON EXEC [dbo].[Cipher_Create] @Id, @UserId, @OrganizationId, @Type, @Data, @Favorites, @Folders, - @Attachments, @CreationDate, @RevisionDate, @DeletedDate, @Reprompt, @Key, @ArchivedDate + @Attachments, @CreationDate, @RevisionDate, @DeletedDate, @Reprompt, @Key, @ArchivedDate, @Archives DECLARE @UpdateCollectionsSuccess INT EXEC @UpdateCollectionsSuccess = [dbo].[Cipher_UpdateCollections] @Id, @UserId, @OrganizationId, @CollectionIds