mirror of
https://github.com/bitwarden/server.git
synced 2025-01-28 22:51:22 +01:00
bd297fb7a2
* SqlServer split manage collection permission * Clarify names * Test claims generation * Test permission serialization * Simplify claims building * Use new collections permissions * Throw on use of deprecated permissions * Lower case all claims * Remove todos * Clean nonexistent project from test solution * JsonIgnore for both system and newtonsoft json * Make migrations more robust to multiple runs * remove duplicate usings * Remove obsolete permissions * Test solutions separately to detect failures * Handle dos line endings * Fix collections create/update permissions * Change restore cipher to edit permissions * Improve formatting * Simplify map * Refactor test
43 lines
1.6 KiB
Plaintext
43 lines
1.6 KiB
Plaintext
CREATE OR REPLACE FUNCTION updatePermissionsJson(permissions jsonb) returns jsonb LANGUAGE plpgsql AS $$
|
|
DECLARE manageAllCollections jsonb := COALESCE(jsonb_extract_path(permissions, 'manageAllCollections'), 'false');
|
|
DECLARE manageAssignedCollections jsonb := COALESCE(jsonb_extract_path(permissions, 'manageAssignedCollections'), 'false');
|
|
|
|
DECLARE createNewCollections jsonb := COALESCE(jsonb_extract_path(permissions, 'createNewCollections'), manageAllCollections);
|
|
DECLARE editAnyCollection jsonb := COALESCE(jsonb_extract_path(permissions, 'editAnyCollection'), manageAllCollections);
|
|
DECLARE deleteAnyCollection jsonb := COALESCE(jsonb_extract_path(permissions, 'deleteAnyCollection'), manageAllCollections);
|
|
|
|
DECLARE editAssignedCollections jsonb := COALESCE(jsonb_extract_path(permissions, 'editAssignedCollections'), manageAssignedCollections);
|
|
DECLARE deleteAssignedCollections jsonb := COALESCE(jsonb_extract_path(permissions, 'deleteAssignedCollections'), manageAssignedCollections);
|
|
|
|
BEGIN
|
|
RETURN
|
|
jsonb_set(
|
|
jsonb_set(
|
|
jsonb_set(
|
|
jsonb_set(
|
|
jsonb_set(
|
|
permissions,
|
|
'{createNewCollections}',
|
|
createNewCollections
|
|
),
|
|
'{editAnyCollection}',
|
|
editAnyCollection
|
|
),
|
|
'{deleteAnyCollection}',
|
|
deleteAnyCollection
|
|
),
|
|
'{editAssignedCollections}',
|
|
editAssignedCollections
|
|
),
|
|
'{deleteAssignedCollections}',
|
|
deleteAssignedCollections
|
|
);
|
|
END
|
|
$$;
|
|
|
|
UPDATE public."OrganizationUser"
|
|
SET "Permissions" = updatePermissionsJson("Permissions"::jsonb)::text
|
|
WHERE "Permissions" IS NOT NULL;
|
|
|
|
DROP FUNCTION updatePermissionsJson(jsonb);
|