1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 15:42:48 -05:00

Merge branch 'master' of https://github.com/bitwarden/server into feature/hide-passwords

# Conflicts:
#	src/Sql/dbo/Stored Procedures/CollectionUser_UpdateUsers.sql
#	src/Sql/dbo/Stored Procedures/OrganizationUser_UpdateWithCollections.sql
This commit is contained in:
hinton
2020-05-22 21:42:29 +02:00
11 changed files with 559 additions and 141 deletions

View File

@ -188,12 +188,10 @@ namespace Bit.Api
app.UseSwagger(config =>
{
config.RouteTemplate = "specs/{documentName}/swagger.json";
var host = globalSettings.BaseServiceUri.Api.Replace("https://", string.Empty)
.Replace("http://", string.Empty);
config.PreSerializeFilters.Add((swaggerDoc, httpReq) =>
swaggerDoc.Servers = new List<OpenApiServer>
{
new OpenApiServer { Url = $"{httpReq.Scheme}://{host}" }
new OpenApiServer { Url = globalSettings.BaseServiceUri.Api }
});
});
app.UseSwaggerUI(config =>

View File

@ -14,40 +14,61 @@ BEGIN
[Id] = @CollectionId
)
;WITH [AvailableUsersCTE] AS(
SELECT
Id
FROM
[dbo].[OrganizationUser]
WHERE
OrganizationId = @OrgId
)
MERGE
[dbo].[CollectionUser] AS [Target]
USING
@Users AS [Source]
ON
-- Update
UPDATE
[Target]
SET
[Target].[ReadOnly] = [Source].[ReadOnly],
[Target].[HidePasswords] = [Source].[HidePasswords]
FROM
[dbo].[CollectionUser] [Target]
INNER JOIN
@Users [Source] ON [Source].[Id] = [Target].[OrganizationUserId]
WHERE
[Target].[CollectionId] = @CollectionId
AND [Target].[OrganizationUserId] = [Source].[Id]
WHEN NOT MATCHED BY TARGET
AND [Source].[Id] IN (SELECT [Id] FROM [AvailableUsersCTE]) THEN
INSERT VALUES
(
@CollectionId,
[Source].[Id],
[Source].[ReadOnly],
[Source].[HidePasswords]
AND (
[Target].[ReadOnly] != [Source].[ReadOnly]
OR [Target].[HidePasswords] != [Source].[HidePasswords]
)
-- Insert
INSERT INTO
[dbo].[CollectionUser]
SELECT
@CollectionId,
[Source].[Id],
[Source].[ReadOnly],
[Source].[HidePasswords]
FROM
@Users [Source]
INNER JOIN
[dbo].[OrganizationUser] OU ON [Source].[Id] = OU.[Id] AND OU.[OrganizationId] = @OrgId
WHERE
NOT EXISTS (
SELECT
1
FROM
[dbo].[CollectionUser]
WHERE
[CollectionId] = @CollectionId
AND [OrganizationUserId] = [Source].[Id]
)
-- Delete
DELETE
CU
FROM
[dbo].[CollectionUser] CU
WHERE
CU.[CollectionId] = @CollectionId
AND NOT EXISTS (
SELECT
1
FROM
@Users
WHERE
[Id] = CU.[OrganizationUserId]
)
WHEN MATCHED AND (
[Target].[ReadOnly] != [Source].[ReadOnly]
OR [Target].[HidePasswords] != [Source].[HidePasswords]
) THEN
UPDATE SET [Target].[ReadOnly] = [Source].[ReadOnly],
[Target].[HidePasswords] = [Source].[HidePasswords]
WHEN NOT MATCHED BY SOURCE
AND [Target].[CollectionId] = @CollectionId THEN
DELETE
;
EXEC [dbo].[User_BumpAccountRevisionDateByCollectionId] @CollectionId, @OrgId
END

View File

@ -14,33 +14,42 @@ BEGIN
[Id] = @OrganizationUserId
)
;WITH [AvailableGroupsCTE] AS(
SELECT
[Id]
FROM
[dbo].[Group]
WHERE
[OrganizationId] = @OrgId
)
MERGE
[dbo].[GroupUser] AS [Target]
USING
@GroupIds AS [Source]
ON
[Target].[GroupId] = [Source].[Id]
AND [Target].[OrganizationUserId] = @OrganizationUserId
WHEN NOT MATCHED BY TARGET
AND [Source].[Id] IN (SELECT [Id] FROM [AvailableGroupsCTE]) THEN
INSERT VALUES
(
[Source].[Id],
@OrganizationUserId
-- Insert
INSERT INTO
[dbo].[GroupUser]
SELECT
[Source].[Id],
@OrganizationUserId
FROM
@GroupIds [Source]
INNER JOIN
[dbo].[Group] G ON G.[Id] = [Source].[Id] AND G.[OrganizationId] = @OrgId
WHERE
NOT EXISTS (
SELECT
1
FROM
[dbo].[GroupUser]
WHERE
[OrganizationUserId] = @OrganizationUserId
AND [GroupId] = [Source].[Id]
)
-- Delete
DELETE
GU
FROM
[dbo].[GroupUser] GU
WHERE
GU.[OrganizationUserId] = @OrganizationUserId
AND NOT EXISTS (
SELECT
1
FROM
@GroupIds
WHERE
[Id] = GU.[GroupId]
)
WHEN NOT MATCHED BY SOURCE
AND [Target].[OrganizationUserId] = @OrganizationUserId
AND [Target].[GroupId] IN (SELECT [Id] FROM [AvailableGroupsCTE]) THEN
DELETE
;
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationUserId] @OrganizationUserId
END

View File

@ -14,33 +14,42 @@ BEGIN
[Id] = @GroupId
)
;WITH [AvailableUsersCTE] AS(
SELECT
[Id]
FROM
[dbo].[OrganizationUser]
WHERE
[OrganizationId] = @OrgId
)
MERGE
[dbo].[GroupUser] AS [Target]
USING
-- Insert
INSERT INTO
[dbo].[GroupUser]
SELECT
@GroupId,
[Source].[Id]
FROM
@OrganizationUserIds AS [Source]
ON
[Target].[GroupId] = @GroupId
AND [Target].[OrganizationUserId] = [Source].[Id]
WHEN NOT MATCHED BY TARGET
AND [Source].[Id] IN (SELECT [Id] FROM [AvailableUsersCTE]) THEN
INSERT VALUES
(
@GroupId,
[Source].[Id]
INNER JOIN
[dbo].[OrganizationUser] OU ON [Source].[Id] = OU.[Id] AND OU.[OrganizationId] = @OrgId
WHERE
NOT EXISTS (
SELECT
1
FROM
[dbo].[GroupUser]
WHERE
[GroupId] = @GroupId
AND [OrganizationUserId] = [Source].[Id]
)
-- Delete
DELETE
GU
FROM
[dbo].[GroupUser] GU
WHERE
GU.[GroupId] = @GroupId
AND NOT EXISTS (
SELECT
1
FROM
@OrganizationUserIds
WHERE
[Id] = GU.[OrganizationUserId]
)
WHEN NOT MATCHED BY SOURCE
AND [Target].[GroupId] = @GroupId
AND [Target].[OrganizationUserId] IN (SELECT [Id] FROM [AvailableUsersCTE]) THEN
DELETE
;
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrgId
END

View File

@ -17,38 +17,59 @@ BEGIN
EXEC [dbo].[OrganizationUser_Update] @Id, @OrganizationId, @UserId, @Email, @Key, @Status, @Type, @AccessAll, @ExternalId, @CreationDate, @RevisionDate
;WITH [AvailableCollectionsCTE] AS(
SELECT
Id
FROM
[dbo].[Collection]
WHERE
OrganizationId = @OrganizationId
)
MERGE
-- Update
UPDATE
[Target]
SET
[Target].[ReadOnly] = [Source].[ReadOnly],
[Target].[HidePasswords] = [Source].[HidePasswords]
FROM
[dbo].[CollectionUser] AS [Target]
USING
@Collections AS [Source]
ON
[Target].[CollectionId] = [Source].[Id]
AND [Target].[OrganizationUserId] = @Id
WHEN NOT MATCHED BY TARGET
AND [Source].[Id] IN (SELECT [Id] FROM [AvailableCollectionsCTE]) THEN
INSERT VALUES
(
[Source].[Id],
@Id,
[Source].[ReadOnly],
[Source].[HidePasswords]
INNER JOIN
@Collections AS [Source] ON [Source].[Id] = [Target].[CollectionId]
WHERE
[Target].[OrganizationUserId] = @Id
AND (
[Target].[ReadOnly] != [Source].[ReadOnly]
OR [Target].[HidePasswords] != [Source].[HidePasswords]
)
-- Insert
INSERT INTO
[dbo].[CollectionUser]
SELECT
[Source].[Id],
@Id,
[Source].[ReadOnly],
[Source].[HidePasswords]
FROM
@Collections AS [Source]
INNER JOIN
[dbo].[Collection] C ON C.[Id] = [Source].[Id] AND C.[OrganizationId] = @OrganizationId
WHERE
NOT EXISTS (
SELECT
1
FROM
[dbo].[CollectionUser]
WHERE
[CollectionId] = [Source].[Id]
AND [OrganizationUserId] = @Id
)
-- Delete
DELETE
CU
FROM
[dbo].[CollectionUser] CU
WHERE
CU.[OrganizationUserId] = @Id
AND NOT EXISTS (
SELECT
1
FROM
@Collections
WHERE
[Id] = CU.[CollectionId]
)
WHEN MATCHED AND (
[Target].[ReadOnly] != [Source].[ReadOnly]
OR [Target].[HidePasswords] != [Source].[HidePasswords]
) THEN
UPDATE SET [Target].[ReadOnly] = [Source].[ReadOnly],
[Target].[HidePasswords] = [Source].[HidePasswords]
WHEN NOT MATCHED BY SOURCE
AND [Target].[OrganizationUserId] = @Id THEN
DELETE
;
END

View File

@ -11,7 +11,7 @@ BEGIN
U.[AccountRevisionDate] = GETUTCDATE()
FROM
[dbo].[User] U
LEFT JOIN
INNER JOIN
[dbo].[OrganizationUser] OU ON OU.[UserId] = U.[Id]
LEFT JOIN
[dbo].[CollectionCipher] CC ON CC.[CipherId] = @CipherId
@ -24,16 +24,12 @@ BEGIN
LEFT JOIN
[dbo].[CollectionGroup] CG ON G.[AccessAll] = 0 AND CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = CC.[CollectionId]
WHERE
OU.[Status] = 2 -- 2 = Confirmed
OU.[OrganizationId] = @OrganizationId
AND OU.[Status] = 2 -- 2 = Confirmed
AND (
CU.[CollectionId] IS NOT NULL
OR CG.[CollectionId] IS NOT NULL
OR (
OU.[OrganizationId] = @OrganizationId
AND (
OU.[AccessAll] = 1
OR G.[AccessAll] = 1
)
)
OR OU.[AccessAll] = 1
OR G.[AccessAll] = 1
)
END

View File

@ -11,7 +11,7 @@ BEGIN
U.[AccountRevisionDate] = GETUTCDATE()
FROM
[dbo].[User] U
LEFT JOIN
INNER JOIN
[dbo].[OrganizationUser] OU ON OU.[UserId] = U.[Id]
LEFT JOIN
[dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = @CollectionId
@ -22,16 +22,12 @@ BEGIN
LEFT JOIN
[dbo].[CollectionGroup] CG ON G.[AccessAll] = 0 AND CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = @CollectionId
WHERE
OU.[Status] = 2 -- 2 = Confirmed
OU.[OrganizationId] = @OrganizationId
AND OU.[Status] = 2 -- 2 = Confirmed
AND (
CU.[CollectionId] IS NOT NULL
OR CG.[CollectionId] IS NOT NULL
OR (
OU.[OrganizationId] = @OrganizationId
AND (
OU.[AccessAll] = 1
OR G.[AccessAll] = 1
)
)
OR OU.[AccessAll] = 1
OR G.[AccessAll] = 1
)
END