Skip to content

Commit dee3638

Browse files
update sql
1 parent 7dd8c66 commit dee3638

2 files changed

Lines changed: 56 additions & 28 deletions

File tree

src/Sql/dbo/Stored Procedures/CollectionCipher_ReadUserIdsByCollectionIds.sql

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,44 @@ BEGIN
55
SET NOCOUNT ON
66

77
-- Users with direct collection access
8-
SELECT DISTINCT OU.[UserId]
9-
FROM [dbo].[CollectionUser] CU
10-
INNER JOIN [dbo].[OrganizationUser] OU ON OU.[Id] = CU.[OrganizationUserId]
11-
WHERE CU.[CollectionId] IN (SELECT [Id] FROM @CollectionIds)
8+
SELECT DISTINCT
9+
OU.[UserId]
10+
FROM
11+
[dbo].[CollectionUser] CU
12+
INNER JOIN
13+
[dbo].[OrganizationUser] OU ON OU.[Id] = CU.[OrganizationUserId]
14+
WHERE
15+
CU.[CollectionId] IN (SELECT [Id] FROM @CollectionIds)
1216
AND OU.[Status] = 2 -- Confirmed
1317

1418
UNION
1519

1620
-- Users with group-based collection access
17-
SELECT DISTINCT OU.[UserId]
18-
FROM [dbo].[CollectionGroup] CG
19-
INNER JOIN [dbo].[GroupUser] GU ON GU.[GroupId] = CG.[GroupId]
20-
INNER JOIN [dbo].[OrganizationUser] OU ON OU.[Id] = GU.[OrganizationUserId]
21-
WHERE CG.[CollectionId] IN (SELECT [Id] FROM @CollectionIds)
21+
SELECT DISTINCT
22+
OU.[UserId]
23+
FROM
24+
[dbo].[CollectionGroup] CG
25+
INNER JOIN
26+
[dbo].[GroupUser] GU ON GU.[GroupId] = CG.[GroupId]
27+
INNER JOIN
28+
[dbo].[OrganizationUser] OU ON OU.[Id] = GU.[OrganizationUserId]
29+
WHERE
30+
CG.[CollectionId] IN (SELECT [Id] FROM @CollectionIds)
2231
AND OU.[Status] = 2 -- Confirmed
2332

2433
UNION
2534

2635
-- Users with org-level access (owners/admins with AllowAdminAccessToAllCollectionItems enabled)
27-
SELECT DISTINCT OU.[UserId]
28-
FROM [dbo].[OrganizationUser] OU
29-
INNER JOIN [dbo].[CollectionCipher] CC ON CC.[CollectionId] IN (SELECT [Id] FROM @CollectionIds)
30-
INNER JOIN [dbo].[Collection] COL ON COL.[Id] = CC.[CollectionId]
31-
INNER JOIN [dbo].[Organization] O ON O.[Id] = COL.[OrganizationId]
36+
SELECT DISTINCT
37+
OU.[UserId]
38+
FROM
39+
[dbo].[OrganizationUser] OU
40+
INNER JOIN
41+
[dbo].[CollectionCipher] CC ON CC.[CollectionId] IN (SELECT [Id] FROM @CollectionIds)
42+
INNER JOIN
43+
[dbo].[Collection] COL ON COL.[Id] = CC.[CollectionId]
44+
INNER JOIN
45+
[dbo].[Organization] O ON O.[Id] = COL.[OrganizationId]
3246
WHERE OU.[OrganizationId] = COL.[OrganizationId]
3347
AND OU.[Status] = 2 -- Confirmed
3448
AND OU.[Type] IN (0, 1) -- Owner/Admin

util/Migrator/DbScripts/2026-04-29_00_CollectionCipher_ReadUserIdsByCollectionIds.sql

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,44 @@ BEGIN
55
SET NOCOUNT ON
66

77
-- Users with direct collection access
8-
SELECT DISTINCT OU.[UserId]
9-
FROM [dbo].[CollectionUser] CU
10-
INNER JOIN [dbo].[OrganizationUser] OU ON OU.[Id] = CU.[OrganizationUserId]
11-
WHERE CU.[CollectionId] IN (SELECT [Id] FROM @CollectionIds)
8+
SELECT DISTINCT
9+
OU.[UserId]
10+
FROM
11+
[dbo].[CollectionUser] CU
12+
INNER JOIN
13+
[dbo].[OrganizationUser] OU ON OU.[Id] = CU.[OrganizationUserId]
14+
WHERE
15+
CU.[CollectionId] IN (SELECT [Id] FROM @CollectionIds)
1216
AND OU.[Status] = 2 -- Confirmed
1317

1418
UNION
1519

1620
-- Users with group-based collection access
17-
SELECT DISTINCT OU.[UserId]
18-
FROM [dbo].[CollectionGroup] CG
19-
INNER JOIN [dbo].[GroupUser] GU ON GU.[GroupId] = CG.[GroupId]
20-
INNER JOIN [dbo].[OrganizationUser] OU ON OU.[Id] = GU.[OrganizationUserId]
21-
WHERE CG.[CollectionId] IN (SELECT [Id] FROM @CollectionIds)
21+
SELECT DISTINCT
22+
OU.[UserId]
23+
FROM
24+
[dbo].[CollectionGroup] CG
25+
INNER JOIN
26+
[dbo].[GroupUser] GU ON GU.[GroupId] = CG.[GroupId]
27+
INNER JOIN
28+
[dbo].[OrganizationUser] OU ON OU.[Id] = GU.[OrganizationUserId]
29+
WHERE
30+
CG.[CollectionId] IN (SELECT [Id] FROM @CollectionIds)
2231
AND OU.[Status] = 2 -- Confirmed
2332

2433
UNION
2534

2635
-- Users with org-level access (owners/admins with AllowAdminAccessToAllCollectionItems enabled)
27-
SELECT DISTINCT OU.[UserId]
28-
FROM [dbo].[OrganizationUser] OU
29-
INNER JOIN [dbo].[CollectionCipher] CC ON CC.[CollectionId] IN (SELECT [Id] FROM @CollectionIds)
30-
INNER JOIN [dbo].[Collection] COL ON COL.[Id] = CC.[CollectionId]
31-
INNER JOIN [dbo].[Organization] O ON O.[Id] = COL.[OrganizationId]
36+
SELECT DISTINCT
37+
OU.[UserId]
38+
FROM
39+
[dbo].[OrganizationUser] OU
40+
INNER JOIN
41+
[dbo].[CollectionCipher] CC ON CC.[CollectionId] IN (SELECT [Id] FROM @CollectionIds)
42+
INNER JOIN
43+
[dbo].[Collection] COL ON COL.[Id] = CC.[CollectionId]
44+
INNER JOIN
45+
[dbo].[Organization] O ON O.[Id] = COL.[OrganizationId]
3246
WHERE OU.[OrganizationId] = COL.[OrganizationId]
3347
AND OU.[Status] = 2 -- Confirmed
3448
AND OU.[Type] IN (0, 1) -- Owner/Admin

0 commit comments

Comments
 (0)