This file contains 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
async function authorizeCharge() { | |
return true | |
} | |
const canAddCharge = (context) => { | |
return context.batteryLevel < context.batteryCapacity | |
} | |
const cantAddCharge = (context) => { | |
return context.batteryLevel === context.batteryCapacity |
This file contains 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 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( |
This file contains 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 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 |
This file contains 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
import get from 'lodash/get' | |
import { graphql } from 'graphql' | |
import Pool from 'pg-pool' | |
import { | |
createPostGraphileSchema, | |
withPostGraphileContext | |
} from 'postgraphile' | |
import config from './config' |
This file contains 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 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[]); |
This file contains 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 |
This file contains 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 table if not exists users_and_groups ( | |
id uuid default uuid_generate_v4() not null primary key, | |
name text not null | |
); | |
-- e.g. ('eac6...f6c9', 'alice') or ('0fdc...947f', 'E Corp') | |
create table if not exists items ( | |
id uuid default uuid_generate_v4() not null primary key, | |
value text, | |
public boolean default false |
This file contains 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.acl_read && regexp_split_to_array(current_setting('jwt.claims.roles'), ',')::uuid[] | |
or items.acl_write && regexp_split_to_array(current_setting('jwt.claims.roles'), ',')::uuid[] | |
) | |
with check ( |
This file contains 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 table if not exists items ( | |
id uuid default uuid_generate_v4() not null primary key, | |
value text, | |
acl_read uuid[] default array[]::uuid[], | |
acl_write uuid[] default array[]::uuid[] | |
); | |
-- e.g. ('f386...5e99', 'I row and therefore I am', {'eac6...f6c9'}, {'0fdc...947f'}) | |
create index read_permissions_index on items using gin(acl_read); | |
create index write_permissions_index on items using gin(acl_write); |
This file contains 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
// ==UserScript== | |
// @name No Alerts | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match *://*/* | |
// @grant none | |
// ==/UserScript== |
NewerOlder