1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-05 14:23:30 +01:00
bitwarden-server/util/Migrator/DbScripts/2021-09-21_01_SplitManageCollectionsJson.sql
Matt Gibson 7802c2b969
⚠️ Do not specify database in migration files (#1628)
* Do not specify database in migration files

* Rename migrations to force them to re-run

* Use new migration files

* Rename EF migrations
2021-10-11 10:20:21 -05:00

65 lines
2.3 KiB
Transact-SQL

-- Split Manage Assigned Collections into edit and delete
UPDATE [dbo].[OrganizationUser]
SET [Permissions] =
JSON_MODIFY(
JSON_MODIFY(
[Permissions],
'$.editAssignedCollections',
CAST(ISNULL(
ISNULL(
JSON_VALUE([Permissions], '$.editAssignedCollections'),
JSON_VALUE([Permissions], '$.manageAssignedCollections')
),
0) AS BIT)
),
'$.deleteAssignedCollections',
CAST(ISNULL(
ISNULL(
JSON_VALUE([Permissions], '$.deleteAssignedCollections'),
JSON_VALUE([Permissions], '$.manageAssignedCollections')),
0) AS BIT)
)
WHERE [Permissions] IS NOT NULL
AND ISJSON([Permissions]) > 0
AND (
JSON_VALUE([Permissions], '$.editAssignedCollections') IS NULL
OR JSON_VALUE([Permissions], '$.deleteAssignedCollections') IS NULL
)
-- Split Manage All Collections into create, edit, and delete
UPDATE [dbo].[OrganizationUser]
SET [Permissions] =
JSON_MODIFY(
JSON_MODIFY(
JSON_MODIFY(
[Permissions],
'$.createNewCollections',
CAST(ISNULL(
ISNULL(
JSON_VALUE([Permissions], '$.createNewCollections'),
JSON_VALUE([Permissions], '$.manageAllCollections')),
0) AS BIT)
),
'$.editAnyCollection',
CAST(ISNULL(
ISNULL(
JSON_VALUE([Permissions], '$.editAnyCollection'),
JSON_VALUE([Permissions], '$.manageAllCollections')),
0) AS BIT)
),
'$.deleteAnyCollection',
CAST(ISNULL(
ISNULL(
JSON_VALUE([Permissions], '$.deleteAnyCollection'),
JSON_VALUE([Permissions], '$.manageAllCollections')),
0) AS BIT)
)
WHERE [Permissions] IS NOT NULL
AND ISJSON([Permissions]) > 0
AND (
JSON_VALUE([Permissions], '$.createNewCollections') IS NULL
OR JSON_VALUE([Permissions], '$.editAnyCollection') IS NULL
OR JSON_VALUE([Permissions], '$.deleteAnyCollection') IS NULL
)