Skip to content

Instantly share code, notes, and snippets.

@vahanNasibyan
Created December 13, 2018 14:27
Show Gist options
  • Save vahanNasibyan/dce87e34982d4efa26fbd7ad9391d7ed to your computer and use it in GitHub Desktop.
Save vahanNasibyan/dce87e34982d4efa26fbd7ad9391d7ed to your computer and use it in GitHub Desktop.
fix permissions for subaccounts
with qa as (
Select "Permissions".id as permission_id
from "public"."permission_user" as "PermissionMap"
LEFT JOIN "public"."permission" AS "Permissions"
ON "Permissions"."id" = "PermissionMap"."permission_id"
WHERE "PermissionMap"."user_id" = 124 and "Permissions".id not in
(50, 51, 52, 53, 54, 55, 56, 57, 2, 3, 4, 5, 44, 45, 46, 47, 48, 49, 43, 42, 6, 7, 8, 9, 10, 11, 12, 28, 29, 30, 31, 32, 33, 34, 35, 13, 14, 17, 18, 16, 15, 19, 20, 21, 27, 36, 37, 38, 39, 40, 41, 25, 22, 23, 26, 24, 111, 112)
), users_t as (select id as user_id from "user" where permission_group_id = 324 and role_id !=3)
update permission_group
set permissions = permissions || (select to_jsonb(array_agg(permission_id)) from qa) where permission_group.id = 324
insert into permission_user (user_id, permission_id) (select user_id, permission_id from users_t, qa)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment