Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-19150] Add ArchivedDate Column to Cipher Table for Archive Vault Items #5489

Merged
merged 5 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Api/Vault/Models/Response/CipherResponseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public CipherMiniResponseModel(Cipher cipher, IGlobalSettings globalSettings, bo
DeletedDate = cipher.DeletedDate;
Reprompt = cipher.Reprompt.GetValueOrDefault(CipherRepromptType.None);
Key = cipher.Key;
ArchivedDate = cipher.ArchivedDate;
}

public Guid Id { get; set; }
Expand All @@ -93,6 +94,7 @@ public CipherMiniResponseModel(Cipher cipher, IGlobalSettings globalSettings, bo
public DateTime? DeletedDate { get; set; }
public CipherRepromptType Reprompt { get; set; }
public string Key { get; set; }
public DateTime? ArchivedDate { get; set; }
}

public class CipherResponseModel : CipherMiniResponseModel
Expand Down
1 change: 1 addition & 0 deletions src/Core/Vault/Entities/Cipher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Cipher : ITableObject<Guid>, ICloneable
public DateTime? DeletedDate { get; set; }
public Enums.CipherRepromptType? Reprompt { get; set; }
public string Key { get; set; }
public DateTime? ArchivedDate { get; set; }

public void SetNewId()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ from cg in cg_g.DefaultIfEmpty()
Manage = cu == null ? (cg != null && cg.Manage == true) : cu.Manage == true,
OrganizationUseTotp = o.UseTotp,
c.Reprompt,
c.Key
c.Key,
c.ArchivedDate
};

var query2 = from c in dbContext.Ciphers
Expand All @@ -91,7 +92,8 @@ from cg in cg_g.DefaultIfEmpty()
Manage = true,
OrganizationUseTotp = false,
c.Reprompt,
c.Key
c.Key,
c.ArchivedDate
};

var union = query.Union(query2).Select(c => new CipherDetails
Expand All @@ -112,7 +114,8 @@ from cg in cg_g.DefaultIfEmpty()
ViewPassword = c.ViewPassword,
Manage = c.Manage,
OrganizationUseTotp = c.OrganizationUseTotp,
Key = c.Key
Key = c.Key,
ArchivedDate = c.ArchivedDate
});
return union;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@
ViewPassword = true,
Manage = true,
OrganizationUseTotp = false,
Key = c.Key
Key = c.Key,
ArchivedDate = c.ArchivedDate,

Check warning on line 483 in src/Infrastructure.EntityFramework/Vault/Repositories/CipherRepository.cs

View check run for this annotation

Codecov / codecov/patch

src/Infrastructure.EntityFramework/Vault/Repositories/CipherRepository.cs#L482-L483

Added lines #L482 - L483 were not covered by tests
};
}
var ciphers = await cipherDetailsView.ToListAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
FolderId = (_ignoreFolders || !_userId.HasValue || c.Folders == null || !c.Folders.ToLowerInvariant().Contains(_userId.Value.ToString())) ?
null :
CoreHelpers.LoadClassFromJsonData<Dictionary<Guid, Guid>>(c.Folders)[_userId.Value],
ArchivedDate = c.ArchivedDate,

Check warning on line 37 in src/Infrastructure.EntityFramework/Vault/Repositories/Queries/CipherDetailsQuery.cs

View check run for this annotation

Codecov / codecov/patch

src/Infrastructure.EntityFramework/Vault/Repositories/Queries/CipherDetailsQuery.cs#L37

Added line #L37 was not covered by tests
};
return query;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Sql/Vault/dbo/Functions/CipherDetails.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ SELECT
END [FolderId],
C.[DeletedDate],
C.[Reprompt],
C.[Key]
C.[Key],
C.[ArchivedDate]
FROM
[dbo].[Cipher] C
[dbo].[Cipher] C
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
@OrganizationUseTotp BIT, -- not used
@DeletedDate DATETIME2(7),
@Reprompt TINYINT,
@Key VARCHAR(MAX) = NULL
@Key VARCHAR(MAX) = NULL,
@ArchivedDate DATETIME2(7) = NULL
AS
BEGIN
SET NOCOUNT ON
Expand All @@ -38,7 +39,8 @@ BEGIN
[RevisionDate],
[DeletedDate],
[Reprompt],
[Key]
[Key],
[ArchivedDate]
)
VALUES
(
Expand All @@ -53,7 +55,8 @@ BEGIN
@RevisionDate,
@DeletedDate,
@Reprompt,
@Key
@Key,
@ArchivedDate
)

IF @OrganizationId IS NOT NULL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
@DeletedDate DATETIME2(7),
@Reprompt TINYINT,
@Key VARCHAR(MAX) = NULL,
@CollectionIds AS [dbo].[GuidIdArray] READONLY
@CollectionIds AS [dbo].[GuidIdArray] READONLY,
@ArchivedDate DATETIME2(7) = NULL
AS
BEGIN
SET NOCOUNT ON

EXEC [dbo].[CipherDetails_Create] @Id, @UserId, @OrganizationId, @Type, @Data, @Favorites, @Folders,
@Attachments, @CreationDate, @RevisionDate, @FolderId, @Favorite, @Edit, @ViewPassword, @Manage,
@OrganizationUseTotp, @DeletedDate, @Reprompt, @Key
@OrganizationUseTotp, @DeletedDate, @Reprompt, @Key, @ArchivedDate

DECLARE @UpdateCollectionsSuccess INT
EXEC @UpdateCollectionsSuccess = [dbo].[Cipher_UpdateCollections] @Id, @UserId, @OrganizationId, @CollectionIds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
@OrganizationUseTotp BIT, -- not used
@DeletedDate DATETIME2(2),
@Reprompt TINYINT,
@Key VARCHAR(MAX) = NULL
@Key VARCHAR(MAX) = NULL,
@ArchivedDate DATETIME2(7) = NULL
AS
BEGIN
SET NOCOUNT ON
Expand Down Expand Up @@ -55,7 +56,8 @@ BEGIN
[CreationDate] = @CreationDate,
[RevisionDate] = @RevisionDate,
[DeletedDate] = @DeletedDate,
[Key] = @Key
[Key] = @Key,
[ArchivedDate] = @ArchivedDate
WHERE
[Id] = @Id

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
@RevisionDate DATETIME2(7),
@DeletedDate DATETIME2(7),
@Reprompt TINYINT,
@Key VARCHAR(MAX) = NULL
@Key VARCHAR(MAX) = NULL,
@ArchivedDate DATETIME2(7) = NULL
AS
BEGIN
SET NOCOUNT ON
Expand All @@ -30,7 +31,8 @@ BEGIN
[RevisionDate],
[DeletedDate],
[Reprompt],
[Key]
[Key],
[ArchivedDate]
)
VALUES
(
Expand All @@ -46,7 +48,8 @@ BEGIN
@RevisionDate,
@DeletedDate,
@Reprompt,
@Key
@Key,
@ArchivedDate
)

IF @OrganizationId IS NOT NULL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
@DeletedDate DATETIME2(7),
@Reprompt TINYINT,
@Key VARCHAR(MAX) = NULL,
@CollectionIds AS [dbo].[GuidIdArray] READONLY
@CollectionIds AS [dbo].[GuidIdArray] READONLY,
@ArchivedDate DATETIME2(7) = NULL
AS
BEGIN
SET NOCOUNT ON

EXEC [dbo].[Cipher_Create] @Id, @UserId, @OrganizationId, @Type, @Data, @Favorites, @Folders,
@Attachments, @CreationDate, @RevisionDate, @DeletedDate, @Reprompt, @Key
@Attachments, @CreationDate, @RevisionDate, @DeletedDate, @Reprompt, @Key, @ArchivedDate

DECLARE @UpdateCollectionsSuccess INT
EXEC @UpdateCollectionsSuccess = [dbo].[Cipher_UpdateCollections] @Id, @UserId, @OrganizationId, @CollectionIds
END
END
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
@RevisionDate DATETIME2(7),
@DeletedDate DATETIME2(7),
@Reprompt TINYINT,
@Key VARCHAR(MAX) = NULL
@Key VARCHAR(MAX) = NULL,
@ArchivedDate DATETIME2(7) = NULL
AS
BEGIN
SET NOCOUNT ON
Expand All @@ -30,7 +31,8 @@ BEGIN
[RevisionDate] = @RevisionDate,
[DeletedDate] = @DeletedDate,
[Reprompt] = @Reprompt,
[Key] = @Key
[Key] = @Key,
[ArchivedDate] = @ArchivedDate
WHERE
[Id] = @Id

Expand All @@ -42,4 +44,4 @@ BEGIN
BEGIN
EXEC [dbo].[User_BumpAccountRevisionDate] @UserId
END
END
END
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
@DeletedDate DATETIME2(7),
@Reprompt TINYINT,
@Key VARCHAR(MAX) = NULL,
@CollectionIds AS [dbo].[GuidIdArray] READONLY
@CollectionIds AS [dbo].[GuidIdArray] READONLY,
@ArchivedDate DATETIME2(7) = NULL
AS
BEGIN
SET NOCOUNT ON
Expand All @@ -37,8 +38,7 @@ BEGIN
[Data] = @Data,
[Attachments] = @Attachments,
[RevisionDate] = @RevisionDate,
[DeletedDate] = @DeletedDate,
[Key] = @Key
[DeletedDate] = @DeletedDate, [Key] = @Key, [ArchivedDate] = @ArchivedDate
-- No need to update CreationDate, Favorites, Folders, or Type since that data will not change
WHERE
[Id] = @Id
Expand All @@ -54,4 +54,4 @@ BEGIN
EXEC [dbo].[User_BumpAccountRevisionDateByCipherId] @Id, @OrganizationId

SELECT 0 -- 0 = Success
END
END
9 changes: 9 additions & 0 deletions src/Sql/Vault/dbo/Tables/Cipher.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ CREATE TABLE [dbo].[Cipher] (
[DeletedDate] DATETIME2 (7) NULL,
[Reprompt] TINYINT NULL,
[Key] VARCHAR(MAX) NULL,
[ArchivedDate] DATETIME2
(
7
) NULL,
CONSTRAINT [PK_Cipher] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_Cipher_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]),
CONSTRAINT [FK_Cipher_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id])
Expand All @@ -34,3 +38,8 @@ GO
CREATE NONCLUSTERED INDEX [IX_Cipher_DeletedDate]
ON [dbo].[Cipher]([DeletedDate] ASC);

GO
CREATE
NONCLUSTERED INDEX [IX_Cipher_ArchivedDate]
ON [dbo].[Cipher]([ArchivedDate] ASC);

Loading
Loading