Skip to content

Instantly share code, notes, and snippets.

View cazzer's full-sized avatar
🦆

Caleb cazzer

🦆
View GitHub Profile
create view items_view
with (security_barrier)
as
select items.*
from items
join permissions on item_id = items.id
and user_or_group_id =
any(regexp_split_to_array(current_setting('jwt.claims.roles'), ',')::uuid[]);
@cazzer
cazzer / postgraphile-lambda.js
Last active November 12, 2018 00:52
A Lambda which serves GraphQL requests using Postgraphile
import get from 'lodash/get'
import { graphql } from 'graphql'
import Pool from 'pg-pool'
import {
createPostGraphileSchema,
withPostGraphileContext
} from 'postgraphile'
import config from './config'
create or replace function insert_permission()
returns trigger
as $$
begin
insert into permissions (item_id, user_or_group_id, role) values (
new.id,
current_setting('user_id')::uuid[]
);
return new;
end
create role application_user;
grant all on all table in schema public to application_user;
create policy thing_owner
on things
as permissive
for all
to application_user
using (
exists(
@cazzer
cazzer / machine.js
Last active April 15, 2020 21:47
Generated by XState Viz: https://xstate.js.org/viz
async function authorizeCharge() {
return true
}
const canAddCharge = (context) => {
return context.batteryLevel < context.batteryCapacity
}
const cantAddCharge = (context) => {
return context.batteryLevel === context.batteryCapacity