Last active
July 28, 2018 00:29
-
-
Save cazzer/bc0b866da4c1dca81249dfe3cc6658c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create policy item_owner | |
on items | |
as permissive | |
for all | |
to application_user | |
using ( | |
items.public = true | |
or exists( | |
select item_id | |
from permissions | |
where ( | |
permissions.user_or_group_id = | |
any(regexp_split_to_array(current_setting('jwt.claims.role'), ',')::uuid[]) | |
and permissions.item_id = items.id | |
) | |
) | |
) | |
with check (exists( | |
select item_id | |
from permissions | |
where ( | |
permissions.user_or_group_id = | |
any(regexp_split_to_array(current_setting('jwt.claims.role'), ',')::uuid[]) | |
and permissions.item_id = items.id | |
and permissions.role = 'write' | |
) | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment