From 13ef3cb6d3f25bcf4d3413b69cccc6f3117effd4 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Wed, 7 Jul 2021 23:23:25 +0000 Subject: role permissions table --- apioforum/db.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/apioforum/db.py b/apioforum/db.py index 7dd635e..10b2c24 100644 --- a/apioforum/db.py +++ b/apioforum/db.py @@ -117,7 +117,32 @@ CREATE VIEW most_recent_posts AS CREATE VIEW number_of_posts AS SELECT thread, count(*) AS num_replies FROM posts GROUP BY thread; """, - +# 0 = inherit, 1 = allow, -1 = deny +""" +CREATE TABLE roles ( + id INTEGER PRIMARY KEY, + name TEXT NOT NULL, + forum INTEGER NOT NULL REFERENCES forums(id), + + p_create_threads INT NOT NULL DEFAULT 0, + p_reply_threads INT NOT NULL DEFAULT 0, + p_view_threads INT NOT NULL DEFAULT 0, + p_manage_threads INT NOT NULL DEFAULT 0, + p_vote INT NOT NULL DEFAULT 0, + p_create_polls INT NOT NULL DEFAULT 0, + p_approve INT NOT NULL DEFAULT 0, + p_create_subforums INT NOT NULL DEFAULT 0, + +); + +INSERT INTO roles (name,forum) SELECT 'approved',id FROM forums; +INSERT INTO roles (name,forum) SELECT 'other',id FROM forums; + +CREATE TRIGGER default_roles AFTER INSERT ON forums BEGIN + INSERT INTO roles (role,forum) VALUES ('approved',new.id); + INSERT INTO roles (role,forum) VALUES ('other',new.id); +END; +""", ] def init_db(): -- cgit v1.2.3