parent
fafc3722cd
commit
f7a56a0bed
26 changed files with 174 additions and 174 deletions
@ -1,7 +1,7 @@ |
||||
COMPOSE_FILE=docker-compose.dev.yml |
||||
COMPOSE_PROJECT_NAME=candymat |
||||
COMPOSE_PROJECT_NAME=kandimat |
||||
|
||||
# Backend vars |
||||
POSTGRES_PASSWORD=postgres!dev |
||||
DATABASE_URL=postgres://candymat_postgraphile:postgres!dev@postgres:5432/candymat_db |
||||
DATABASE_URL=postgres://kandimat_postgraphile:postgres!dev@postgres:5432/kandimat_db |
||||
JWT_SECRET=asdfasdfasdf |
||||
|
@ -1,4 +1,4 @@ |
||||
[submodule "candymat-user-app"] |
||||
path = candymat-user-app |
||||
url = git@git.verdigado.com:Netzbegruenung/candymat-user-app.git |
||||
branch = develop-candymat |
||||
path = kandimat-user-app |
||||
url = git@git.verdigado.com:NB-Public/kandimat-user-app.git |
||||
branch = main |
||||
|
@ -1,5 +1,5 @@ |
||||
# Postgres database setup |
||||
POSTGRES_USER=candymat_postgraphile |
||||
POSTGRES_USER=kandimat_postgraphile |
||||
# Password is handled by docker-compose |
||||
POSTGRES_DB=candymat_db |
||||
POSTGRES_SCHEMA=candymat_data |
||||
POSTGRES_DB=kandimat_db |
||||
POSTGRES_SCHEMA=kandimat_data |
||||
|
@ -1,28 +1,28 @@ |
||||
\connect candymat_db |
||||
\connect kandimat_db |
||||
|
||||
-- Create schema for candymat_data |
||||
create SCHEMA candymat_data; |
||||
create SCHEMA candymat_data_privat; |
||||
-- Create schema for kandimat_data |
||||
create SCHEMA kandimat_data; |
||||
create SCHEMA kandimat_data_privat; |
||||
|
||||
-- create roles |
||||
create role candymat_person; |
||||
create role candymat_anonymous; |
||||
create role candymat_editor; |
||||
create role candymat_candidate; |
||||
create role kandimat_person; |
||||
create role kandimat_anonymous; |
||||
create role kandimat_editor; |
||||
create role kandimat_candidate; |
||||
|
||||
grant candymat_editor to candymat_postgraphile; |
||||
grant candymat_candidate to candymat_postgraphile; |
||||
grant candymat_person to candymat_postgraphile, candymat_candidate, candymat_editor; |
||||
grant candymat_anonymous to candymat_postgraphile; |
||||
grant kandimat_editor to kandimat_postgraphile; |
||||
grant kandimat_candidate to kandimat_postgraphile; |
||||
grant kandimat_person to kandimat_postgraphile, kandimat_candidate, kandimat_editor; |
||||
grant kandimat_anonymous to kandimat_postgraphile; |
||||
|
||||
create type candymat_data.role as enum ( |
||||
'candymat_editor', |
||||
'candymat_candidate', |
||||
'candymat_person' |
||||
create type kandimat_data.role as enum ( |
||||
'kandimat_editor', |
||||
'kandimat_candidate', |
||||
'kandimat_person' |
||||
); |
||||
|
||||
-- set table wide permissions |
||||
grant usage on schema candymat_data to candymat_anonymous, candymat_person; |
||||
grant usage on schema kandimat_data to kandimat_anonymous, kandimat_person; |
||||
|
||||
-- make functions non executeable w/o further checks |
||||
alter default privileges revoke execute on functions from public; |
||||
|
@ -1,43 +1,43 @@ |
||||
-- create table for users |
||||
create table candymat_data.person |
||||
create table kandimat_data.person |
||||
( |
||||
row_id serial primary key, |
||||
first_name character varying(200) check (first_name <> ''), |
||||
last_name character varying(200) check (last_name <> ''), |
||||
about character varying(2000), |
||||
created_at timestamp default now(), |
||||
role candymat_data.role not null default 'candymat_person' |
||||
role kandimat_data.role not null default 'kandimat_person' |
||||
); |
||||
grant select, update, delete on table candymat_data.person to candymat_person; |
||||
grant select, update, delete on table kandimat_data.person to kandimat_person; |
||||
-- the following is only necessary as long as anonymous should be able to view candidates and editors |
||||
grant select on table candymat_data.person to candymat_anonymous; |
||||
grant select on table kandimat_data.person to kandimat_anonymous; |
||||
|
||||
-- create table for accounts |
||||
create table candymat_data_privat.person_account |
||||
create table kandimat_data_privat.person_account |
||||
( |
||||
person_row_id integer primary key references candymat_data.person (row_id) on delete cascade, |
||||
person_row_id integer primary key references kandimat_data.person (row_id) on delete cascade, |
||||
email character varying(320) not null unique check (email ~* '^.+@.+\..+$'), |
||||
password_hash character varying(256) not null |
||||
); |
||||
|
||||
alter table candymat_data.person |
||||
alter table kandimat_data.person |
||||
enable row level security; |
||||
create policy update_person on candymat_data.person for update to candymat_person |
||||
create policy update_person on kandimat_data.person for update to kandimat_person |
||||
with check (row_id = nullif(current_setting('jwt.claims.person_row_id', true), '')::integer); |
||||
create policy delete_person on candymat_data.person for delete to candymat_person |
||||
create policy delete_person on kandimat_data.person for delete to kandimat_person |
||||
using (row_id = nullif(current_setting('jwt.claims.person_row_id', true), '')::integer); |
||||
|
||||
-- The following enables viewing candidates and editors information for every person. |
||||
-- This may be changed to only enable registered (and verified) persons. |
||||
create policy select_person_public |
||||
on candymat_data.person |
||||
on kandimat_data.person |
||||
for select |
||||
to candymat_anonymous, candymat_person -- maybe change to candymat_person only in the future |
||||
using (role in ('candymat_editor', 'candymat_candidate')); |
||||
to kandimat_anonymous, kandimat_person -- maybe change to kandimat_person only in the future |
||||
using (role in ('kandimat_editor', 'kandimat_candidate')); |
||||
|
||||
-- Editors can see all registered persons in order to elevate their privileges |
||||
create policy select_person_editor |
||||
on candymat_data.person |
||||
on kandimat_data.person |
||||
for select |
||||
to candymat_editor |
||||
to kandimat_editor |
||||
using (true); |
||||
|
@ -1,51 +1,51 @@ |
||||
-- create table for categories |
||||
create table candymat_data.category |
||||
create table kandimat_data.category |
||||
( |
||||
row_id serial primary key, |
||||
title character varying(300) UNIQUE NOT NULL check ( title <> '' ), |
||||
description character varying(15000) |
||||
); |
||||
grant select on table candymat_data.category to candymat_person; |
||||
-- the following line is only necessary as long as the candymat should be publicly accessible |
||||
grant select on table candymat_data.category to candymat_anonymous; |
||||
grant insert, update, delete on table candymat_data.category to candymat_editor; |
||||
grant usage on sequence candymat_data.category_row_id_seq to candymat_editor; |
||||
grant select on table kandimat_data.category to kandimat_person; |
||||
-- the following line is only necessary as long as the kandimat should be publicly accessible |
||||
grant select on table kandimat_data.category to kandimat_anonymous; |
||||
grant insert, update, delete on table kandimat_data.category to kandimat_editor; |
||||
grant usage on sequence kandimat_data.category_row_id_seq to kandimat_editor; |
||||
|
||||
-- create table for questions |
||||
create table candymat_data.question |
||||
create table kandimat_data.question |
||||
( |
||||
row_id serial primary key, |
||||
category_row_id integer REFERENCES candymat_data.category (row_id) ON UPDATE CASCADE ON DELETE SET NULL, |
||||
category_row_id integer REFERENCES kandimat_data.category (row_id) ON UPDATE CASCADE ON DELETE SET NULL, |
||||
title character varying(3000) UNIQUE NOT NULL check ( title <> '' ), |
||||
description character varying(15000) |
||||
); |
||||
grant select on table candymat_data.question to candymat_person; |
||||
-- the following line is only necessary as long as the candymat should be publicly accessible |
||||
grant select on table candymat_data.question to candymat_anonymous; |
||||
grant insert, update, delete on table candymat_data.question to candymat_editor; |
||||
grant usage on sequence candymat_data.question_row_id_seq to candymat_editor; |
||||
grant select on table kandimat_data.question to kandimat_person; |
||||
-- the following line is only necessary as long as the kandimat should be publicly accessible |
||||
grant select on table kandimat_data.question to kandimat_anonymous; |
||||
grant insert, update, delete on table kandimat_data.question to kandimat_editor; |
||||
grant usage on sequence kandimat_data.question_row_id_seq to kandimat_editor; |
||||
|
||||
-- create table for answers |
||||
create table candymat_data.answer |
||||
create table kandimat_data.answer |
||||
( |
||||
question_row_id integer REFERENCES candymat_data.question (row_id) ON UPDATE CASCADE ON DELETE CASCADE, |
||||
person_row_id integer REFERENCES candymat_data.person (row_id) ON UPDATE CASCADE ON DELETE CASCADE, |
||||
question_row_id integer REFERENCES kandimat_data.question (row_id) ON UPDATE CASCADE ON DELETE CASCADE, |
||||
person_row_id integer REFERENCES kandimat_data.person (row_id) ON UPDATE CASCADE ON DELETE CASCADE, |
||||
position integer NOT NULL check (position between 0 and 3), |
||||
text character varying(15000), |
||||
created_at timestamp default now(), |
||||
primary key (question_row_id, person_row_id) |
||||
); |
||||
grant select on table candymat_data.answer to candymat_person; |
||||
-- the following line is only necessary as long as the candymat should be publicly accessible |
||||
grant select on table candymat_data.answer to candymat_anonymous; |
||||
grant insert, update, delete on table candymat_data.answer to candymat_candidate; |
||||
grant select on table kandimat_data.answer to kandimat_person; |
||||
-- the following line is only necessary as long as the kandimat should be publicly accessible |
||||
grant select on table kandimat_data.answer to kandimat_anonymous; |
||||
grant insert, update, delete on table kandimat_data.answer to kandimat_candidate; |
||||
|
||||
alter table candymat_data.answer |
||||
alter table kandimat_data.answer |
||||
enable row level security; |
||||
create policy change_answer on candymat_data.answer to candymat_candidate |
||||
create policy change_answer on kandimat_data.answer to kandimat_candidate |
||||
using (person_row_id = nullif(current_setting('jwt.claims.person_row_id', true), '')::integer); |
||||
create policy select_answer |
||||
on candymat_data.answer |
||||
on kandimat_data.answer |
||||
for select |
||||
to candymat_anonymous, candymat_person -- maybe change to candymat_person only in the future |
||||
to kandimat_anonymous, kandimat_person -- maybe change to kandimat_person only in the future |
||||
using (true); |
||||
|
@ -1,40 +1,40 @@ |
||||
select candymat_data.register_person( |
||||
select kandimat_data.register_person( |
||||
'Erika', |
||||
'Mustermann', |
||||
'erika@mustermann.de', |
||||
'password' |
||||
); |
||||
select candymat_data.change_role( |
||||
select kandimat_data.change_role( |
||||
1, |
||||
'candymat_editor' |
||||
'kandimat_editor' |
||||
); |
||||
select candymat_data.register_person( |
||||
select kandimat_data.register_person( |
||||
'Max', |
||||
'Mustermann', |
||||
'max@mustermann.de', |
||||
'password' |
||||
); |
||||
select candymat_data.change_role( |
||||
select kandimat_data.change_role( |
||||
2, |
||||
'candymat_candidate' |
||||
'kandimat_candidate' |
||||
); |
||||
select candymat_data.register_person( |
||||
select kandimat_data.register_person( |
||||
'Tricia', |
||||
'McMillan', |
||||
'trillian@universe.com', |
||||
'password' |
||||
); |
||||
select candymat_data.change_role( |
||||
select kandimat_data.change_role( |
||||
3, |
||||
'candymat_candidate' |
||||
'kandimat_candidate' |
||||
); |
||||
select candymat_data.register_person( |
||||
select kandimat_data.register_person( |
||||
'Happy', |
||||
'User', |
||||
'happy@user.de', |
||||
'password' |
||||
); |
||||
select candymat_data.change_role( |
||||
select kandimat_data.change_role( |
||||
4, |
||||
'candymat_person' |
||||
'kandimat_person' |
||||
); |
||||
|
@ -1,9 +1,9 @@ |
||||
insert into candymat_data.category (title, description) values |
||||
insert into kandimat_data.category (title, description) values |
||||
('Umwelt', 'Themen rund um Naturschutz usw.'); |
||||
insert into candymat_data.category (title, description) values |
||||
insert into kandimat_data.category (title, description) values |
||||
('Sonstiges', ''); |
||||
|
||||
insert into candymat_data.question (category_row_id, title, description) values |
||||
insert into kandimat_data.question (category_row_id, title, description) values |
||||
(1, 'Was sagen Sie zur 10H Regel?', 'In Bayern dürfen Windräder nur ...'); |
||||
insert into candymat_data.question (category_row_id, title, description) values |
||||
insert into kandimat_data.question (category_row_id, title, description) values |
||||
(2, 'Umgehungsstraße XY?', 'Zur Entlastung der Hauptstraße ...'); |
||||
|
@ -1,9 +1,9 @@ |
||||
insert into candymat_data.answer (question_row_id, person_row_id, position, text) |
||||
insert into kandimat_data.answer (question_row_id, person_row_id, position, text) |
||||
values (1, 2, 2, 'bin dagegen'); |
||||
insert into candymat_data.answer (question_row_id, person_row_id, position, text) |
||||
insert into kandimat_data.answer (question_row_id, person_row_id, position, text) |
||||
values (2, 2, 0, 'bin dafür'); |
||||
|
||||
insert into candymat_data.answer (question_row_id, person_row_id, position, text) |
||||
insert into kandimat_data.answer (question_row_id, person_row_id, position, text) |
||||
values (1, 3, 1, 'mir egal'); |
||||
insert into candymat_data.answer (question_row_id, person_row_id, position, text) |
||||
insert into kandimat_data.answer (question_row_id, person_row_id, position, text) |
||||
values (2, 3, 3, 'keine lust mehr'); |
||||
|
@ -1 +0,0 @@ |
||||
Subproject commit d7f669bc9978b0f0284bfc6d17552a75fbc13a7c |
@ -0,0 +1 @@ |
||||
Subproject commit dc1602b6e87c80d3c37f92bc87f02c98865895d3 |
Loading…
Reference in new issue