1
0
mirror of https://github.com/bitwarden/server.git synced 2025-02-23 03:01:23 +01:00

handle distinct selections from app code

This commit is contained in:
Kyle Spearrin 2017-04-17 13:11:39 -04:00
parent 4d298b9cf8
commit c7c5ae8f9a
6 changed files with 20 additions and 17 deletions

View File

@ -57,7 +57,8 @@ namespace Bit.Core.Repositories.SqlServer
new { UserId = userId },
commandType: CommandType.StoredProcedure);
return results.ToList();
// Return distinct Id results
return results.GroupBy(c => c.Id).Select(g => g.First()).ToList();
}
}
@ -70,7 +71,8 @@ namespace Bit.Core.Repositories.SqlServer
new { UserId = userId },
commandType: CommandType.StoredProcedure);
return results.ToList();
// Return distinct Id results
return results.GroupBy(c => c.Id).Select(g => g.First()).ToList();
}
}
@ -87,7 +89,8 @@ namespace Bit.Core.Repositories.SqlServer
},
commandType: CommandType.StoredProcedure);
return results.ToList();
// Return distinct Id results
return results.GroupBy(c => c.Id).Select(g => g.First()).ToList();
}
}

View File

@ -5,18 +5,18 @@ AS
BEGIN
SET NOCOUNT ON
SELECT DISTINCT
SELECT TOP 1
C.*
FROM
[dbo].[CipherDetails](@UserId) C
LEFT JOIN
[dbo].[SubvaultCipher] SC ON SC.[CipherId] = C.[Id]
[dbo].[SubvaultCipher] SC ON C.[UserId] IS NULL AND SC.[CipherId] = C.[Id]
LEFT JOIN
[dbo].[SubvaultUser] SU ON SU.[SubvaultId] = SC.[SubvaultId]
LEFT JOIN
[dbo].[OrganizationUser] OU ON OU.[Id] = SU.[OrganizationUserId]
LEFT JOIN
[dbo].[Organization] O ON O.[Id] = C.[OrganizationId]
[dbo].[Organization] O ON C.[UserId] IS NULL AND O.[Id] = C.[OrganizationId]
WHERE
C.Id = @Id
AND (

View File

@ -5,18 +5,18 @@ AS
BEGIN
SET NOCOUNT ON
SELECT DISTINCT
SELECT
C.*
FROM
[dbo].[CipherDetails](@UserId) C
LEFT JOIN
[dbo].[SubvaultCipher] SC ON SC.[CipherId] = C.[Id]
[dbo].[SubvaultCipher] SC ON C.[UserId] IS NULL AND SC.[CipherId] = C.[Id]
LEFT JOIN
[dbo].[SubvaultUser] SU ON SU.[SubvaultId] = SC.[SubvaultId]
LEFT JOIN
[dbo].[OrganizationUser] OU ON OU.[Id] = SU.[OrganizationUserId]
LEFT JOIN
[dbo].[Organization] O ON O.[Id] = C.[OrganizationId]
[dbo].[Organization] O ON C.[UserId] IS NULL AND O.[Id] = C.[OrganizationId]
WHERE
C.[Type] = @Type
AND (

View File

@ -4,7 +4,7 @@ AS
BEGIN
SET NOCOUNT ON
SELECT DISTINCT
SELECT
C.*
FROM
[dbo].[CipherDetails](@UserId) C
@ -15,7 +15,7 @@ BEGIN
LEFT JOIN
[dbo].[OrganizationUser] OU ON OU.[Id] = SU.[OrganizationUserId]
LEFT JOIN
[dbo].[Organization] O ON O.[Id] = C.[OrganizationId]
[dbo].[Organization] O ON C.[UserId] IS NULL AND O.[Id] = C.[OrganizationId]
WHERE
C.[UserId] = @UserId
OR (

View File

@ -4,18 +4,18 @@ AS
BEGIN
SET NOCOUNT ON
SELECT DISTINCT
SELECT
C.*
FROM
[dbo].[CipherDetails](@UserId) C
INNER JOIN
[dbo].[SubvaultCipher] SC ON SC.[CipherId] = C.[Id]
[dbo].[SubvaultCipher] SC ON C.[UserId] IS NULL AND SC.[CipherId] = C.[Id]
INNER JOIN
[dbo].[SubvaultUser] SU ON SU.[SubvaultId] = SC.[SubvaultId]
INNER JOIN
[dbo].[OrganizationUser] OU ON OU.[Id] = SU.[OrganizationUserId]
INNER JOIN
[dbo].[Organization] O ON O.[Id] = C.[OrganizationId]
[dbo].[Organization] O ON C.[UserId] IS NULL AND O.[Id] = C.[OrganizationId]
WHERE
OU.[UserId] = @UserId
AND OU.[Status] = 2 -- 2 = Confirmed

View File

@ -5,7 +5,7 @@ AS
BEGIN
SET NOCOUNT ON
SELECT DISTINCT
SELECT TOP 1
C.*,
CASE
WHEN C.[OrganizationId] IS NULL THEN 1
@ -14,13 +14,13 @@ BEGIN
FROM
[dbo].[CipherDetails](@UserId) C
LEFT JOIN
[dbo].[SubvaultCipher] SC ON SC.[CipherId] = C.[Id]
[dbo].[SubvaultCipher] SC ON C.[UserId] IS NULL AND SC.[CipherId] = C.[Id]
LEFT JOIN
[dbo].[SubvaultUser] SU ON SU.[SubvaultId] = SC.[SubvaultId]
LEFT JOIN
[dbo].[OrganizationUser] OU ON OU.[Id] = SU.[OrganizationUserId]
LEFT JOIN
[dbo].[Organization] O ON O.[Id] = C.[OrganizationId]
[dbo].[Organization] O ON C.[UserId] IS NULL AND O.[Id] = C.[OrganizationId]
WHERE
C.Id = @Id
AND (