mirror of
https://github.com/bitwarden/server.git
synced 2025-07-06 18:42:49 -05:00
allow user delete if they are not the only owner
This commit is contained in:
@ -114,7 +114,7 @@
|
||||
<Build Include="dbo\Stored Procedures\OrganizationUser_ReadCountByFreeOrganizationAdminUser.sql" />
|
||||
<Build Include="dbo\Stored Procedures\User_ReadAccountRevisionDateById.sql" />
|
||||
<Build Include="dbo\Stored Procedures\OrganizationUser_ReadCountByOrganizationId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\OrganizationUser_ReadCountByOrganizationOwnerUser.sql" />
|
||||
<Build Include="dbo\Stored Procedures\OrganizationUser_ReadCountByOnlyOwner.sql" />
|
||||
<Build Include="dbo\Stored Procedures\OrganizationUser_Update.sql" />
|
||||
<Build Include="dbo\Stored Procedures\OrganizationUserOrganizationDetails_ReadByUserIdStatus.sql" />
|
||||
<Build Include="dbo\Stored Procedures\OrganizationUserUserDetails_ReadByOrganizationId.sql" />
|
||||
|
@ -0,0 +1,25 @@
|
||||
CREATE PROCEDURE [dbo].[OrganizationUser_ReadCountByOnlyOwner]
|
||||
@UserId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
;WITH [OwnerCountCTE] AS
|
||||
(
|
||||
SELECT
|
||||
OU.[UserId],
|
||||
COUNT(1) OVER (PARTITION BY OU.[OrganizationId]) [ConfirmedOwnerCount]
|
||||
FROM
|
||||
[dbo].[OrganizationUser] OU
|
||||
WHERE
|
||||
OU.[Type] = 0 -- 0 = Owner
|
||||
AND OU.[Status] = 2 -- 2 = Confirmed
|
||||
)
|
||||
SELECT
|
||||
COUNT(1)
|
||||
FROM
|
||||
[OwnerCountCTE] OC
|
||||
WHERE
|
||||
OC.[UserId] = @UserId
|
||||
AND OC.[ConfirmedOwnerCount] = 1
|
||||
END
|
@ -1,15 +0,0 @@
|
||||
CREATE PROCEDURE [dbo].[OrganizationUser_ReadCountByOrganizationOwnerUser]
|
||||
@UserId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
COUNT(1)
|
||||
FROM
|
||||
[dbo].[OrganizationUser] OU
|
||||
WHERE
|
||||
OU.[UserId] = @UserId
|
||||
AND OU.[Type] = 0
|
||||
AND OU.[Status] = 2 -- 2 = Confirmed
|
||||
END
|
@ -64,7 +64,6 @@ BEGIN
|
||||
[dbo].[OrganizationUser]
|
||||
WHERE
|
||||
[UserId] = @Id
|
||||
AND [Type] != 0 -- 0 = owner
|
||||
|
||||
-- Finally, delete the user
|
||||
DELETE
|
||||
|
Reference in New Issue
Block a user