Skip to content

Instantly share code, notes, and snippets.

@cazzer
Last active July 28, 2018 00:29
Show Gist options
  • Save cazzer/bc0b866da4c1dca81249dfe3cc6658c9 to your computer and use it in GitHub Desktop.
Save cazzer/bc0b866da4c1dca81249dfe3cc6658c9 to your computer and use it in GitHub Desktop.
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