mirror of
https://github.com/bitwarden/server.git
synced 2025-07-18 16:11:28 -05:00
group user assignment apis
This commit is contained in:
@ -190,5 +190,12 @@
|
||||
<Build Include="dbo\Stored Procedures\Collection_UpdateWithGroups.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_CreateWithGroups.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_ReadWithGroupsById.sql" />
|
||||
<Build Include="dbo\Views\GroupUserUserDetailsView.sql" />
|
||||
<Build Include="dbo\Stored Procedures\GroupUserUserDetails_ReadByGroupId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\GroupUser_ReadGroupIdsByOrganizationUserId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\GroupUser_UpdateGroups.sql" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<RefactorLog Include="Sql.refactorlog" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -0,0 +1,13 @@
|
||||
CREATE PROCEDURE [dbo].[GroupUserUserDetails_ReadByGroupId]
|
||||
@GroupId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[GroupUserUserDetailsView]
|
||||
WHERE
|
||||
[GroupId] = @GroupId
|
||||
END
|
@ -0,0 +1,13 @@
|
||||
CREATE PROCEDURE [dbo].[GroupUser_ReadGroupIdsByOrganizationUserId]
|
||||
@OrganizationUserId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
[GroupId]
|
||||
FROM
|
||||
[dbo].[GroupUser]
|
||||
WHERE
|
||||
[OrganizationUserId] = @OrganizationUserId
|
||||
END
|
44
src/Sql/dbo/Stored Procedures/GroupUser_UpdateGroups.sql
Normal file
44
src/Sql/dbo/Stored Procedures/GroupUser_UpdateGroups.sql
Normal file
@ -0,0 +1,44 @@
|
||||
CREATE PROCEDURE [dbo].[GroupUser_UpdateGroups]
|
||||
@OrganizationUserId UNIQUEIDENTIFIER,
|
||||
@GroupIds AS [dbo].[GuidIdArray] READONLY
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DECLARE @OrgId UNIQUEIDENTIFIER = (
|
||||
SELECT TOP 1
|
||||
[OrganizationId]
|
||||
FROM
|
||||
[dbo].[OrganizationUser]
|
||||
WHERE
|
||||
[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
|
||||
)
|
||||
WHEN NOT MATCHED BY SOURCE
|
||||
AND [Target].[OrganizationUserId] = @OrganizationUserId
|
||||
AND [Target].[GroupId] IN (SELECT [Id] FROM [AvailableGroupsCTE]) THEN
|
||||
DELETE
|
||||
;
|
||||
END
|
@ -1,8 +1,8 @@
|
||||
CREATE TABLE [dbo].[GroupUser] (
|
||||
[GroupId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[UserId] UNIQUEIDENTIFIER NOT NULL,
|
||||
CONSTRAINT [PK_GroupUser] PRIMARY KEY CLUSTERED ([GroupId] ASC, [UserId] ASC),
|
||||
[OrganizationUserId] UNIQUEIDENTIFIER NOT NULL,
|
||||
CONSTRAINT [PK_GroupUser] PRIMARY KEY CLUSTERED ([GroupId] ASC, [OrganizationUserId] ASC),
|
||||
CONSTRAINT [FK_GroupUser_Group] FOREIGN KEY ([GroupId]) REFERENCES [dbo].[Group] ([Id]) ON DELETE CASCADE,
|
||||
CONSTRAINT [FK_GroupUser_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id])
|
||||
CONSTRAINT [FK_GroupUser_OrganizationUser] FOREIGN KEY ([OrganizationUserId]) REFERENCES [dbo].[OrganizationUser] ([Id])
|
||||
);
|
||||
|
||||
|
17
src/Sql/dbo/Views/GroupUserUserDetailsView.sql
Normal file
17
src/Sql/dbo/Views/GroupUserUserDetailsView.sql
Normal file
@ -0,0 +1,17 @@
|
||||
CREATE VIEW [dbo].[GroupUserUserDetailsView]
|
||||
AS
|
||||
SELECT
|
||||
OU.[Id] AS [OrganizationUserId],
|
||||
OU.[OrganizationId],
|
||||
OU.[AccessAll],
|
||||
GU.[GroupId],
|
||||
U.[Name],
|
||||
ISNULL(U.[Email], OU.[Email]) Email,
|
||||
OU.[Status],
|
||||
OU.[Type]
|
||||
FROM
|
||||
[dbo].[OrganizationUser] OU
|
||||
INNER JOIN
|
||||
[dbo].[GroupUser] GU ON GU.[OrganizationUserId] = OU.[Id]
|
||||
INNER JOIN
|
||||
[dbo].[User] U ON U.[Id] = OU.[UserId]
|
Reference in New Issue
Block a user