From 53ea53189116b63123f4a62ad443c34a6e9ac11f Mon Sep 17 00:00:00 2001 From: jaasen-livefront Date: Mon, 17 Nov 2025 15:01:12 -0800 Subject: [PATCH] fix type error in UserCipherDetailsQuery --- .../Queries/UserCipherDetailsQuery.cs | 13 ++-- .../dbo/Vault/Functions/UserCipherDetails.sql | 12 +-- .../Cipher/CipherDetails_ReadByIdUserId.sql | 76 ++++++++++--------- 3 files changed, 52 insertions(+), 49 deletions(-) diff --git a/src/Infrastructure.EntityFramework/Repositories/Queries/UserCipherDetailsQuery.cs b/src/Infrastructure.EntityFramework/Repositories/Queries/UserCipherDetailsQuery.cs index 2b684d96b8..14b8d441e5 100644 --- a/src/Infrastructure.EntityFramework/Repositories/Queries/UserCipherDetailsQuery.cs +++ b/src/Infrastructure.EntityFramework/Repositories/Queries/UserCipherDetailsQuery.cs @@ -23,7 +23,7 @@ public class UserCipherDetailsQuery : IQuery throw new InvalidOperationException("UserCipherDetailsQuery requires a non-null userId."); } - var userId = _userId; + var userId = _userId.Value; var query = from c in dbContext.Ciphers join ou in dbContext.OrganizationUsers @@ -64,8 +64,8 @@ public class UserCipherDetailsQuery : IQuery from cg in cg_g.DefaultIfEmpty() from ca in caGroup.DefaultIfEmpty() - - where (cu == null ? (Guid?)null : cu.CollectionId) != null || (cg == null ? (Guid?)null : cg.CollectionId) != null + where (cu == null ? (Guid?)null : cu.CollectionId) != null + || (cg == null ? (Guid?)null : cg.CollectionId) != null select new { @@ -93,10 +93,11 @@ public class UserCipherDetailsQuery : IQuery where c.UserId == _userId join ca in dbContext.CipherArchives - on new { CipherId = c.Id, UserId = userId } - equals new { Id = ca.CipherId, userId = ca.UserId } + on c.Id equals ca.CipherId into caGroup - from ca in caGroup.DefaultIfEmpty() + from ca in caGroup + .Where(a => a.UserId == userId) + .DefaultIfEmpty() select new { diff --git a/src/Sql/dbo/Vault/Functions/UserCipherDetails.sql b/src/Sql/dbo/Vault/Functions/UserCipherDetails.sql index 23cfcd78f4..a8619ff868 100644 --- a/src/Sql/dbo/Vault/Functions/UserCipherDetails.sql +++ b/src/Sql/dbo/Vault/Functions/UserCipherDetails.sql @@ -24,16 +24,16 @@ SELECT C.FolderId, C.DeletedDate, C.Reprompt, - C.Key, + C.[Key], CASE WHEN COALESCE(CU.[ReadOnly], CG.[ReadOnly], 0) = 0 THEN 1 ELSE 0 END [Edit], CASE - WHEN COALESCE(CU.[HidePasswords], CG.[HidePasswords], 0) = 0 - THEN 1 - ELSE 0 + WHEN COALESCE(CU.[HidePasswords], CG.[HidePasswords], 0) = 0 + THEN 1 + ELSE 0 END [ViewPassword], CASE WHEN COALESCE(CU.[Manage], CG.[Manage], 0) = 1 @@ -80,7 +80,7 @@ SELECT C.FolderId, C.DeletedDate, C.Reprompt, - C.Key, + C.[Key], 1 [Edit], 1 [ViewPassword], 1 [Manage], @@ -88,4 +88,4 @@ SELECT FROM [dbo].[CipherDetails](@UserId) AS C WHERE - C.[UserId] = @UserId \ No newline at end of file + C.[UserId] = @UserId; \ No newline at end of file diff --git a/src/Sql/dbo/Vault/Stored Procedures/Cipher/CipherDetails_ReadByIdUserId.sql b/src/Sql/dbo/Vault/Stored Procedures/Cipher/CipherDetails_ReadByIdUserId.sql index 2646159b62..e1e028a69e 100644 --- a/src/Sql/dbo/Vault/Stored Procedures/Cipher/CipherDetails_ReadByIdUserId.sql +++ b/src/Sql/dbo/Vault/Stored Procedures/Cipher/CipherDetails_ReadByIdUserId.sql @@ -3,45 +3,47 @@ @UserId UNIQUEIDENTIFIER AS BEGIN - SET NOCOUNT ON + SET NOCOUNT ON; -SELECT - [Id], - [UserId], - [OrganizationId], - [Type], - [Data], - [Attachments], - [CreationDate], - [RevisionDate], - [Favorite], - [FolderId], - [DeletedDate], - [Reprompt], - [Key], - [OrganizationUseTotp], - [ArchivedDate], - MAX ([Edit]) AS [Edit], - MAX ([ViewPassword]) AS [ViewPassword], - MAX ([Manage]) AS [Manage] + SELECT + ucd.Id, + ucd.UserId, + ucd.OrganizationId, + ucd.Type, + ucd.Data, + ucd.Attachments, + ucd.CreationDate, + ucd.RevisionDate, + ucd.Favorite, + ucd.FolderId, + ucd.DeletedDate, + ucd.Reprompt, + ucd.[Key], + ucd.OrganizationUseTotp, + MAX(ca.ArchivedDate) AS ArchivedDate, + MAX(ucd.Edit) AS Edit, + MAX(ucd.ViewPassword) AS ViewPassword, + MAX(ucd.Manage) AS Manage FROM - [dbo].[UserCipherDetails](@UserId) + [dbo].[UserCipherDetails](@UserId) AS ucd + LEFT JOIN [dbo].[CipherArchive] AS ca + ON ca.CipherId = ucd.Id + AND ca.UserId = @UserId WHERE - [Id] = @Id + ucd.Id = @Id GROUP BY - [Id], - [UserId], - [OrganizationId], - [Type], - [Data], - [Attachments], - [CreationDate], - [RevisionDate], - [Favorite], - [FolderId], - [DeletedDate], - [Reprompt], - [Key], - [OrganizationUseTotp], - [ArchivedDate] + ucd.Id, + ucd.UserId, + ucd.OrganizationId, + ucd.Type, + ucd.Data, + ucd.Attachments, + ucd.CreationDate, + ucd.RevisionDate, + ucd.Favorite, + ucd.FolderId, + ucd.DeletedDate, + ucd.Reprompt, + ucd.[Key], + ucd.OrganizationUseTotp; END