1
0
mirror of https://github.com/bitwarden/server synced 2026-01-09 12:03:21 +00:00

allow user delete if they are not the only owner

This commit is contained in:
Kyle Spearrin
2017-10-25 11:36:54 -04:00
parent 461be7a14f
commit 8ba3e27a7d
7 changed files with 33 additions and 25 deletions

View File

@@ -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