diff --git a/debian/TODO-deps.md b/debian/TODO-deps.md deleted file mode 100644 index 14a57f48c..000000000 --- a/debian/TODO-deps.md +++ /dev/null @@ -1,52 +0,0 @@ -# TODO list to build debian "official" package - - It feels for free to modify, fix or take some task or all. - -## debian/control - -* Fill description field -* Add Vcs-Browser -* Add Vcs-Git -* Add Uploaders field - -## debian/copyright - -* Add more contributers - -## Dependencies packages - -Some libraries dependencies aren't Debian package. Below is the list was built by [cabal-debian](https://wiki.debian.org/Haskell/CollabMaint/GettingStarted). These libraries are necessary to build Postgrest the right way. - -* libghc-base64-string-dev -* libghc-base64-string-prof -* libghc-bcrypt-dev -* libghc-bcrypt-prof -* libghc-hasql-dev -* libghc-hasql-prof -* libghc-hasql-backend-dev -* libghc-hasql-backend-prof -* libghc-hasql-postgres-dev -* libghc-hasql-postgres-prof -* libghc-string-conversions-dev -* libghc-string-conversions-prof -* libghc-wai-cors-dev -* libghc-wai-cors-prof -* libghc-wai-middleware-static-dev -* libghc-wai-middleware-static-prof -* libghc-hasql-dev -* libghc-hasql-backend-dev -* libghc-hasql-postgres-dev -* libghc-heredoc-dev -* libghc-hspec-wai-dev -* libghc-hspec-wai-json-dev -* libghc-http-media-dev -* libghc-packdeps-dev -* libghc-base64-string-doc -* libghc-bcrypt-doc -* libghc-hasql-doc -* libghc-hasql-backend-doc -* libghc-hasql-postgres-doc -* libghc-string-conversions-doc -* libghc-wai-cors-doc -* libghc-wai-middleware-static-doc - diff --git a/debian/changelog b/debian/changelog deleted file mode 100644 index 50b595b31..000000000 --- a/debian/changelog +++ /dev/null @@ -1,5 +0,0 @@ -haskell-postgrest (0.2.11.1-1) UNRELEASED; urgency=low - - * Initial release - - -- Debian Haskell Group Wed, 30 Sep 2015 18:52:46 +0000 diff --git a/debian/compat b/debian/compat deleted file mode 100644 index ec635144f..000000000 --- a/debian/compat +++ /dev/null @@ -1 +0,0 @@ -9 diff --git a/debian/control b/debian/control deleted file mode 100644 index 26b5a8bfc..000000000 --- a/debian/control +++ /dev/null @@ -1,196 +0,0 @@ -Source: haskell-postgrest -Maintainer: Debian Haskell Group -Priority: extra -Section: haskell -Build-Depends: debhelper (>= 9), - haskell-devscripts (>= 0.8), - cdbs, - ghc, - ghc-prof, - libghc-http-dev, - libghc-http-prof, - libghc-missingh-dev, - libghc-missingh-prof, - libghc-ranged-sets-dev, - libghc-ranged-sets-prof, - libghc-aeson-dev, - libghc-aeson-prof, - libghc-base64-string-dev, - libghc-base64-string-prof, - libghc-bcrypt-dev, - libghc-bcrypt-prof, - libghc-blaze-builder-dev, - libghc-blaze-builder-prof, - libghc-case-insensitive-dev, - libghc-case-insensitive-prof, - libghc-cassava-dev, - libghc-cassava-prof, - libghc-convertible-dev, - libghc-convertible-prof, - libghc-hasql-dev, - libghc-hasql-prof, - libghc-hasql-backend-dev, - libghc-hasql-backend-prof, - libghc-hasql-postgres-dev, - libghc-hasql-postgres-prof, - libghc-http-types-dev, - libghc-http-types-prof, - libghc-jwt-dev, - libghc-jwt-prof, - libghc-mtl-dev, - libghc-mtl-prof, - libghc-network-dev, - libghc-network-prof, - libghc-network-uri-dev, - libghc-network-uri-prof, - libghc-optparse-applicative-dev, - libghc-optparse-applicative-prof, - libghc-regex-base-dev, - libghc-regex-base-prof, - libghc-regex-tdfa-dev, - libghc-regex-tdfa-prof, - libghc-resource-pool-dev, - libghc-resource-pool-prof, - libghc-scientific-dev, - libghc-scientific-prof, - libghc-split-dev, - libghc-split-prof, - libghc-string-conversions-dev, - libghc-string-conversions-prof, - libghc-stringsearch-dev, - libghc-stringsearch-prof, - libghc-text-dev, - libghc-text-prof, - libghc-unordered-containers-dev, - libghc-unordered-containers-prof, - libghc-vector-dev, - libghc-vector-prof, - libghc-wai-dev, - libghc-wai-prof, - libghc-wai-cors-dev, - libghc-wai-cors-prof, - libghc-wai-extra-dev, - libghc-wai-extra-prof, - libghc-wai-middleware-static-dev, - libghc-wai-middleware-static-prof, - libghc-warp-dev, - libghc-warp-prof, - libghc-aeson-dev (>= 0.8), - libghc-bcrypt-dev (>= 0.0.6), - libghc-hasql-dev (>= 0.7.3), - libghc-hasql-dev (<< 0.8), - libghc-hasql-backend-dev (>= 0.4.1), - libghc-hasql-backend-dev (<< 0.5), - libghc-hasql-postgres-dev (>= 0.10.4), - libghc-hasql-postgres-dev (<< 0.11), - libghc-network-dev (>= 2.6), - libghc-network-uri-dev (>= 2.6), - libghc-optparse-applicative-dev (>= 0.11), - libghc-optparse-applicative-dev (<< 0.12), - libghc-wai-dev (>= 3.0.1), - libghc-wai-middleware-static-dev (>= 0.6.0), - libghc-warp-dev (>= 3.0.2), - libghc-quickcheck2-dev, - libghc-heredoc-dev, - libghc-hlint-dev, - libghc-hspec-dev (>= 2.1), - libghc-hspec-dev (<< 2.2), - libghc-hspec-wai-dev, - libghc-hspec-wai-json-dev, - libghc-http-media-dev, - libghc-packdeps-dev, -Build-Depends-Indep: ghc-doc, - libghc-http-doc, - libghc-missingh-doc, - libghc-ranged-sets-doc, - libghc-aeson-doc, - libghc-base64-string-doc, - libghc-bcrypt-doc, - libghc-blaze-builder-doc, - libghc-case-insensitive-doc, - libghc-cassava-doc, - libghc-convertible-doc, - libghc-hasql-doc, - libghc-hasql-backend-doc, - libghc-hasql-postgres-doc, - libghc-http-types-doc, - libghc-jwt-doc, - libghc-mtl-doc, - libghc-network-doc, - libghc-network-uri-doc, - libghc-optparse-applicative-doc, - libghc-regex-base-doc, - libghc-regex-tdfa-doc, - libghc-resource-pool-doc, - libghc-scientific-doc, - libghc-split-doc, - libghc-string-conversions-doc, - libghc-stringsearch-doc, - libghc-text-doc, - libghc-unordered-containers-doc, - libghc-vector-doc, - libghc-wai-doc, - libghc-wai-cors-doc, - libghc-wai-extra-doc, - libghc-wai-middleware-static-doc, - libghc-warp-doc, -Standards-Version: 3.9.6 -Homepage: https://github.com/begriffs/postgrest -Description: REST API for any Postgres database - Reads the schema of a PostgreSQL database and creates RESTful routes - for the tables and views, supporting all HTTP verbs that security - permits. - -Package: libghc-postgrest-dev -Architecture: any -Depends: ${haskell:Depends}, - ${misc:Depends}, - ${shlibs:Depends}, -Recommends: ${haskell:Recommends}, -Suggests: ${haskell:Suggests}, -Conflicts: ${haskell:Conflicts}, -Provides: ${haskell:Provides}, -Description: ${haskell:ShortDescription}${haskell:ShortBlurb} - ${haskell:LongDescription} - . - ${haskell:Blurb} - -Package: libghc-postgrest-prof -Architecture: any -Depends: ${haskell:Depends}, - ${misc:Depends}, -Recommends: ${haskell:Recommends}, -Suggests: ${haskell:Suggests}, -Conflicts: ${haskell:Conflicts}, -Provides: ${haskell:Provides}, -Description: ${haskell:ShortDescription}${haskell:ShortBlurb} - ${haskell:LongDescription} - . - ${haskell:Blurb} - -Package: libghc-postgrest-doc -Architecture: all -Section: doc -Depends: ${haskell:Depends}, - ${misc:Depends}, -Recommends: ${haskell:Recommends}, -Suggests: ${haskell:Suggests}, -Conflicts: ${haskell:Conflicts}, -Description: ${haskell:ShortDescription}${haskell:ShortBlurb} - ${haskell:LongDescription} - . - ${haskell:Blurb} - -Package: haskell-postgrest-utils -Architecture: any -Section: misc -Depends: ${haskell:Depends}, - ${misc:Depends}, -Recommends: ${haskell:Recommends}, -Suggests: ${haskell:Suggests}, -Conflicts: ${haskell:Conflicts}, -Provides: ${haskell:Provides}, -Description: ${haskell:ShortDescription}${haskell:ShortBlurb} - ${haskell:LongDescription} - . - ${haskell:Blurb} diff --git a/debian/copyright b/debian/copyright deleted file mode 100644 index e96677b1b..000000000 --- a/debian/copyright +++ /dev/null @@ -1,32 +0,0 @@ -Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: postgrest -Upstream-Contact: Joe Nelson -Source: https://hackage.haskell.org/package/postgrest - -Files: * -Copyright: 2014-2015 Joe Nelson -License: Expat - -Files: debian/* -Copyright: 2015 Fernando Ike -License: Expat - -License: Expat - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - . - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - . - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/debian/haskell-postgrest-utils.install b/debian/haskell-postgrest-utils.install deleted file mode 100644 index 1b438b40a..000000000 --- a/debian/haskell-postgrest-utils.install +++ /dev/null @@ -1 +0,0 @@ -dist-ghc/build/postgrest/postgrest usr/bin diff --git a/debian/postgrest-wrapper b/debian/postgrest-wrapper deleted file mode 100755 index 4abdf5a41..000000000 --- a/debian/postgrest-wrapper +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -d=$(dirname $0) -if [ -f /etc/default/postgrest ]; then - . /etc/default/postgrest -fi -POSTGREST_LOG=${POSTGREST_LOG:-/var/log/postgrest/postgrest.log} - -exec $d/postgrest "$@" >>$POSTGREST_LOG 2>&1 & diff --git a/debian/postgrest.default b/debian/postgrest.default deleted file mode 100644 index c2393494c..000000000 --- a/debian/postgrest.default +++ /dev/null @@ -1,29 +0,0 @@ -# run service as -#POSTGREST_USER=postgrest - -# log file -#POSTGREST_LOG=/var/log/postgrest/postgrest.log - -# database host -#POSTGREST_DBHOST=localhost - -# database host -#POSTGREST_DBPORT=5432 - -# database to use -#POSTGREST_DBNAME=app - -# database user -#POSTGREST_DBUSER=authenticator - -# database password -#POSTGREST_DBPASS= - -# database pool -#POSTGREST_POOL=10 - -# jwt secret -#POSTGREST_JWT_SECRET=secret - -# default schema -#POSTGREST_SCHEMA=public diff --git a/debian/postgrest.init.d b/debian/postgrest.init.d deleted file mode 100755 index a9091740e..000000000 --- a/debian/postgrest.init.d +++ /dev/null @@ -1,99 +0,0 @@ -#!/bin/sh -### BEGIN INIT INFO -# Provides: postgrest -# Required-Start: $local_fs $network postgresql -# Required-Stop: $local_fs $network -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Description: PostgreSQL REST API daemon -### END INIT INFO - -. /lib/lsb/init-functions -if test -f /etc/default/postgrest; then - . /etc/default/postgrest -fi -POSTGREST=/usr/local/bin/postgrest -CONNECTION_STRING="postgres://" -POSTGREST_OPTS="" -POSTGREST_USER=${POSTGREST_USER:-postgrest} -POSTGREST_PORT=${POSTGREST_PORT:-3000} -POSTGREST_DBUSER=${POSTGREST_DBUSER:-authenticator} -#POSTGREST_DBPASS=${POSTGREST_DBPASS:-authenticator} -POSTGREST_DBHOST=${POSTGREST_DBHOST:-localhost} -POSTGREST_DBPORT=${POSTGREST_DBPORT:-5432} -POSTGREST_DBNAME=${POSTGREST_DBNAME:-app} -POSTGREST_DBPOOL=${POSTGREST_DBPOOL:-10} -POSTGREST_ANON=${POSTGREST_ANON:-anonymous} -POSTGREST_JWT_SECRET=${POSTGREST_JWT_SECRET:-secret} -POSTGREST_SCHEMA=${POSTGREST_SCHEMA:-public} - -CONNECTION_STRING="$CONNECTION_STRING$POSTGREST_DBUSER" -if [ -n "$POSTGREST_DBPASS" ]; then - CONNECTION_STRING="$CONNECTION_STRING:$POSTGREST_DBPASS" -fi -CONNECTION_STRING="$CONNECTION_STRING@$POSTGREST_DBHOST:$POSTGREST_DBPORT/$POSTGREST_DBNAME" - -if [ -n "$POSTGREST_PORT" ]; then - POSTGREST_OPTS="$POSTGREST_OPTS --port $POSTGREST_PORT" -fi - -if [ -n "$POSTGREST_POOL" ]; then - POSTGREST_OPTS="$POSTGREST_OPTS --pool $POSTGREST_POOL" -fi -if [ -n "$POSTGREST_JWT_SECRET" ]; then - #export POSTGREST_JWT_SECRET="$POSTGREST_JWT_SECRET" - POSTGREST_OPTS="$POSTGREST_OPTS --jwt-secret $POSTGREST_JWT_SECRET" -fi -if [ -n "$POSTGREST_SCHEMA" ]; then - POSTGREST_OPTS="$POSTGREST_OPTS --schema $POSTGREST_SCHEMA" -fi -if [ -n "$POSTGREST_ANON" ]; then - POSTGREST_OPTS="$POSTGREST_OPTS --anonymous $POSTGREST_ANON" -fi - -#export CONNECTION_STRING="$CONNECTION_STRING" - -START_PARAMS="$CONNECTION_STRING $POSTGREST_OPTS" - -start() -{ - log_daemon_msg "Starting PostgreSQL REST API daemon" "postgrest" || true - if start-stop-daemon --start --quiet --oknodo --chuid ${POSTGREST_USER} --startas /usr/local/bin/postgrest-wrapper --exec $POSTGREST -- $START_PARAMS; then - log_end_msg 0 || true - else - log_end_msg 1 || true - fi -} - -stop() -{ - log_daemon_msg "Stopping PostgreSQL REST API daemon" "postgrest" || true - if start-stop-daemon --stop --quiet --oknodo --exec $POSTGREST; then - log_end_msg 0 || true - else - log_end_msg 1 || true - fi -} - -status() -{ - status_of_proc $POSTGREST postgrest && exit 0 || exit $? -} - -case "$1" in -start) - start - ;; -stop) - stop - ;; -restart) - stop - start - ;; -status) - status - ;; -*) - echo "Usage: $0 {start|stop|restart|status}" -esac diff --git a/debian/rules b/debian/rules deleted file mode 100755 index 1ac1fcabe..000000000 --- a/debian/rules +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/make -f - -DEB_ENABLE_TESTS = yes -DEB_CABAL_PACKAGE = postgrest -DEB_DEFAULT_COMPILER = ghc - -include /usr/share/cdbs/1/rules/debhelper.mk -include /usr/share/cdbs/1/class/hlibrary.mk - -build/haskell-postgrest-utils:: build-ghc-stamp diff --git a/debian/source/format b/debian/source/format deleted file mode 100644 index 163aaf8d8..000000000 --- a/debian/source/format +++ /dev/null @@ -1 +0,0 @@ -3.0 (quilt) diff --git a/debian/watch b/debian/watch deleted file mode 100644 index 7da44ba9b..000000000 --- a/debian/watch +++ /dev/null @@ -1,2 +0,0 @@ -version=3 -http://hackage.haskell.org/package/postgrest/distro-monitor .*-([0-9\.]+)\.(?:zip|tgz|tbz|txz|(?:tar\.(?:gz|bz2|xz))) diff --git a/docs/README.md b/docs/README.md deleted file mode 100644 index e56775c50..000000000 --- a/docs/README.md +++ /dev/null @@ -1,3 +0,0 @@ -The docs have moved to their own repo: - -[begriffs/postgrest-docs](https://github.com/begriffs/postgrest-docs) diff --git a/schema-templates/blog.sql b/schema-templates/blog.sql deleted file mode 100644 index 7d4078b59..000000000 --- a/schema-templates/blog.sql +++ /dev/null @@ -1,380 +0,0 @@ -------------------------------------------------------------------------------- --- Adapted from https://github.com/robconery/pg-auth - -begin; - --- comment out the role creation statements if --- you want to run this script more than once -create role anon; -create role author; -create role authenticator noinherit; -grant anon, author to authenticator; - -create extension if not exists pgcrypto; - --- We put things inside the basic_auth schema to hide --- them from public view. Certain public procs/views will --- refer to helpers and tables inside. -create schema if not exists basic_auth; - -------------------------------------------------------------------------------- --- Utility functions - -create or replace function -basic_auth.clearance_for_role(u name) returns void as -$$ -declare - ok boolean; -begin - select exists ( - select rolname - from pg_authid - where pg_has_role(current_user, oid, 'member') - and rolname = u - ) into ok; - if not ok then - raise invalid_password using message = - 'current user not member of role ' || u; - end if; -end -$$ LANGUAGE plpgsql; - -------------------------------------------------------------------------------- --- Users storage and constraints - -create table if not exists -basic_auth.users ( - email text primary key check ( email ~* '^.+@.+\..+$' ), - pass text not null check (length(pass) < 512), - role name not null check (length(role) < 512), - verified boolean not null default false - -- If you like add more columns, or a json column -); - -create or replace function -basic_auth.check_role_exists() returns trigger - language plpgsql - as $$ -begin - if not exists (select 1 from pg_roles as r where r.rolname = new.role) then - raise foreign_key_violation using message = - 'unknown database role: ' || new.role; - return null; - end if; - return new; -end -$$; - -drop trigger if exists ensure_user_role_exists on basic_auth.users; -create constraint trigger ensure_user_role_exists - after insert or update on basic_auth.users - for each row - execute procedure basic_auth.check_role_exists(); - -create or replace function -basic_auth.encrypt_pass() returns trigger - language plpgsql - as $$ -begin - if tg_op = 'INSERT' or new.pass <> old.pass then - new.pass = crypt(new.pass, gen_salt('bf')); - end if; - return new; -end -$$; - -drop trigger if exists encrypt_pass on basic_auth.users; -create trigger encrypt_pass - before insert or update on basic_auth.users - for each row - execute procedure basic_auth.encrypt_pass(); - -create or replace function -basic_auth.send_validation() returns trigger - language plpgsql - as $$ -declare - tok uuid; -begin - select gen_random_uuid() into tok; - insert into basic_auth.tokens (token, token_type, email) - values (tok, 'validation', new.email); - perform pg_notify('validate', - json_build_object( - 'email', new.email, - 'token', tok, - 'token_type', 'validation' - )::text - ); - return new; -end -$$; - -drop trigger if exists send_validation on basic_auth.users; -create trigger send_validation - after insert on basic_auth.users - for each row - execute procedure basic_auth.send_validation(); - -------------------------------------------------------------------------------- --- Email Validation and Password Reset - -drop type if exists token_type_enum cascade; -create type token_type_enum as enum ('validation', 'reset'); - -create table if not exists -basic_auth.tokens ( - token uuid primary key, - token_type token_type_enum not null, - email text not null references basic_auth.users (email) - on delete cascade on update cascade, - created_at timestamptz not null default current_date -); - -------------------------------------------------------------------------------- --- Login helper - -create or replace function -basic_auth.user_role(email text, pass text) returns name - language plpgsql - as $$ -begin - return ( - select role from basic_auth.users - where users.email = user_role.email - and users.pass = crypt(user_role.pass, users.pass) - ); -end; -$$; - -create or replace function -basic_auth.current_email() returns text - language plpgsql - as $$ -begin - return current_setting('postgrest.claims.email'); -exception - -- handle unrecognized configuration parameter error - when undefined_object then return ''; -end; -$$; - - -------------------------------------------------------------------------------- --- Public functions (in current schema, not basic_auth) - -create or replace function -request_password_reset(email text) returns void - language plpgsql - as $$ -declare - tok uuid; -begin - delete from basic_auth.tokens - where token_type = 'reset' - and tokens.email = request_password_reset.email; - - select gen_random_uuid() into tok; - insert into basic_auth.tokens (token, token_type, email) - values (tok, 'reset', request_password_reset.email); - perform pg_notify('reset', - json_build_object( - 'email', request_password_reset.email, - 'token', tok, - 'token_type', 'reset' - )::text - ); -end; -$$; - -create or replace function -reset_password(email text, token uuid, pass text) - returns void - language plpgsql - as $$ -declare - tok uuid; -begin - if exists(select 1 from basic_auth.tokens - where tokens.email = reset_password.email - and tokens.token = reset_password.token - and token_type = 'reset') then - update basic_auth.users set pass=reset_password.pass - where users.email = reset_password.email; - - delete from basic_auth.tokens - where tokens.email = reset_password.email - and tokens.token = reset_password.token - and token_type = 'reset'; - else - raise invalid_password using message = - 'invalid user or token'; - end if; - delete from basic_auth.tokens - where token_type = 'reset' - and tokens.email = reset_password.email; - - select gen_random_uuid() into tok; - insert into basic_auth.tokens (token, token_type, email) - values (tok, 'reset', reset_password.email); - perform pg_notify('reset', - json_build_object( - 'email', reset_password.email, - 'token', tok - )::text - ); -end; -$$; - -drop type if exists basic_auth.jwt_claims cascade; -create type -basic_auth.jwt_claims AS (role text, email text); - -create or replace function -login(email text, pass text) returns basic_auth.jwt_claims - language plpgsql - as $$ -declare - _role name; - result basic_auth.jwt_claims; -begin - select basic_auth.user_role(email, pass) into _role; - if _role is null then - raise invalid_password using message = 'invalid user or password'; - end if; - -- TODO; check verified flag if you care whether users - -- have validated their emails - select _role as role, login.email as email into result; - return result; -end; -$$; - -create or replace function -signup(email text, pass text) returns void -as $$ - insert into basic_auth.users (email, pass, role) values - (signup.email, signup.pass, 'author'); -$$ language sql; - -------------------------------------------------------------------------------- --- User management - -create or replace view users as -select actual.role as role, - '***'::text as pass, - actual.email as email, - actual.verified as verified -from basic_auth.users as actual, - (select rolname - from pg_authid - where pg_has_role(current_user, oid, 'member') - ) as member_of -where actual.role = member_of.rolname - and ( - actual.role <> 'author' - or email = basic_auth.current_email() - ); - -create or replace function -update_users() returns trigger -language plpgsql -AS $$ -begin - if tg_op = 'INSERT' then - perform basic_auth.clearance_for_role(new.role); - - insert into basic_auth.users - (role, pass, email, verified) values - (coalesce(new.role, 'author'), new.pass, - new.email, coalesce(new.verified, false)); - return new; - elsif tg_op = 'UPDATE' then - -- no need to check clearance for old.role because - -- an ineligible row would not even available to update (http 404) - perform basic_auth.clearance_for_role(new.role); - - update basic_auth.users set - email = new.email, - role = new.role, - pass = new.pass, - verified = coalesce(new.verified, old.verified, false) - where email = old.email; - return new; - elsif tg_op = 'DELETE' then - -- no need to check clearance for old.role (see previous case) - - delete from basic_auth.users - where basic_auth.email = old.email; - return null; - end if; -end -$$; - -drop trigger if exists update_users on users; -create trigger update_users - instead of insert or update or delete on - users for each row execute procedure update_users(); - -------------------------------------------------------------------------------- --- Blogging stuff! - -create table if not exists -posts ( - id bigserial primary key, - title text not null, - body text not null, - author text not null references basic_auth.users (email) - on delete restrict on update cascade - default basic_auth.current_email(), - created_at timestamptz not null default current_date -); - -create table if not exists -comments ( - id bigserial primary key, - body text not null, - author text not null references basic_auth.users (email) - on delete restrict on update cascade - default basic_auth.current_email(), - post bigint not null references posts (id) - on delete cascade on update cascade, - created_at timestamptz not null default current_date -); - -------------------------------------------------------------------------------- --- Permissions - -grant insert on table basic_auth.users, basic_auth.tokens to anon; -grant select on table pg_authid, basic_auth.users, posts, comments to anon; -grant execute on function - login(text,text), - request_password_reset(text), - reset_password(text,uuid,text), - signup(text, text) - to anon; - -grant select, insert, update, delete - on basic_auth.tokens, basic_auth.users to anon, author; -grant select, insert, update, delete - on table users, posts, comments to author; -grant usage, select on sequence posts_id_seq, comments_id_seq to author; - -grant usage on schema public, basic_auth to anon, author; - -ALTER TABLE posts ENABLE ROW LEVEL SECURITY; -drop policy if exists authors_eigenedit on posts; -create policy authors_eigenedit on posts - using (true) - with check ( - author = basic_auth.current_email() - ); - -ALTER TABLE comments ENABLE ROW LEVEL SECURITY; -drop policy if exists authors_eigenedit on comments; -create policy authors_eigenedit on comments - using (true) - with check ( - author = basic_auth.current_email() - ); - -commit;