From 338d67854d5eca63b6596fb309589755012c4ca2 Mon Sep 17 00:00:00 2001 From: citrons Date: Fri, 16 Jul 2021 09:46:44 +0000 Subject: committing what I have so that ubq can work on it --- apioforum/db.py | 12 +----- apioforum/forum.py | 10 ++--- apioforum/roles.py | 40 ++++------------- apioforum/static/style.css | 2 + apioforum/templates/edit_permissions.html | 71 +++++++++++++------------------ 5 files changed, 46 insertions(+), 89 deletions(-) diff --git a/apioforum/db.py b/apioforum/db.py index b5cba39..5ffd5d9 100644 --- a/apioforum/db.py +++ b/apioforum/db.py @@ -123,8 +123,6 @@ CREATE TABLE role_config ( forum NOT NULL REFERENCES forums(id), id INTEGER PRIMARY KEY, - inherit INT NOT NULL DEFAULT 0, - p_create_threads INT NOT NULL DEFAULT 1, p_reply_threads INT NOT NULL DEFAULT 1, p_view_threads INT NOT NULL DEFAULT 1, @@ -135,14 +133,8 @@ CREATE TABLE role_config ( p_create_subforum INT NOT NULL DEFAULT 0 ); -INSERT INTO role_config (role,forum) SELECT "approved",id FROM forums; -INSERT INTO role_config (role,forum) SELECT "other",id FROM forums; -""", -""" -CREATE TRIGGER default_role_config AFTER INSERT ON forums BEGIN - INSERT INTO role_config (role,forum) VALUES ("approved",new.id); - INSERT INTO role_config (role,forum) VALUES ("other",new.id); -END; +INSERT INTO role_config (role,forum) VALUES ("approved",1); +INSERT INTO role_config (role,forum) VALUES ("other",1); """ ] diff --git a/apioforum/forum.py b/apioforum/forum.py index 69d7650..4b7522c 100644 --- a/apioforum/forum.py +++ b/apioforum/forum.py @@ -126,20 +126,16 @@ def edit_roles(forum_id): role_configs = db.execute( "SELECT * FROM role_config WHERE forum = ? ORDER BY ID ASC", (forum_id,)).fetchall() - overridden = {} - for c in role_configs: - overridden[c['id']] = overridden_perms(forum_id,c['role']) return render_template("edit_permissions.html", forum=forum, role_configs=role_configs, other_roles=["the","test","placeholder"], - overridden=overridden ) -@bp.route("//roles/new/",methods=["POST"]) -def add_role(forum_id,role_name): - db.execute +@bp.route("//roles/new",methods=["POST"]) +def add_role(forum_id): + return "placeholder" @bp.route("/search") def search(): diff --git a/apioforum/roles.py b/apioforum/roles.py index f364b04..71efcbd 100644 --- a/apioforum/roles.py +++ b/apioforum/roles.py @@ -14,35 +14,13 @@ permissions = [ def get_role_config(forum_id, role): db = get_db() - return db.execute(""" - SELECT * FROM role_config - WHERE forum = ? AND role = ?; - """, (forum_id,role)).fetchone() -def overridden_perms(forum_id, role): - db = get_db() - p = {} - for perm in permissions: - p[perm] = False - ancestors = db.execute(""" - WITH RECURSIVE fs AS - (SELECT * FROM forums WHERE id = ? - UNION ALL - SELECT forums.* FROM forums, fs WHERE fs.parent=forums.id) - SELECT * FROM fs; - """,(forum_id,)).fetchall()[1:] - for ancestor in ancestors: - config = get_role_config(ancestor['id'], role) - if config and config['inherit']: - for perm in permissions: - p[perm] = p[perm] or not config[perm] - return p - -def forum_perms(forum_id, role): - role_config = get_role_config(forum_id, role) - if not role_config: - role_config = get_role_config(forum_id, "other") - p = {} - overridden = overridden_perms(forum_id, role) - for perm in permissions: - p[perm] = role_config[perm] and not overridden[perm] + fid = forum_id + the = None + while the == None and fid != None: + the = db.execute(""" + SELECT * FROM role_config + WHERE forum = ? AND role = ?; + """, (fid,role)).fetchone() + fid = db.execute(""" + """).fetchone()['parent'] diff --git a/apioforum/static/style.css b/apioforum/static/style.css index 09df395..3813d63 100644 --- a/apioforum/static/style.css +++ b/apioforum/static/style.css @@ -195,6 +195,8 @@ fieldset { margin-bottom: 15px; } border: 1px solid black; } +.role-input { width: 12ch; } + .breadcrumbs { list-style: none; } diff --git a/apioforum/templates/edit_permissions.html b/apioforum/templates/edit_permissions.html index a32ceda..e79c0c7 100644 --- a/apioforum/templates/edit_permissions.html +++ b/apioforum/templates/edit_permissions.html @@ -3,22 +3,20 @@ {% block header %}

{% block title %}role permissions for '{{forum.name}}'{% endblock %}

{% endblock %} {% block content %}

- each user has a role in this forum. - the permissions associated with different roles can be configured here. + each user has a role in the forum. + a user may be assigned a role in the forum. + otherwise, the user's role is the same as the parent forum. + everyone's role is "other" by default.

- there are three special roles: "bureaucrat", "approved", and "other". - bureaucrats are automatically granted every permission. - everyone by default has the "other" role. - an assigned role is inherited by all subforæ unless overridden. -

-

- if a role's permissions are set to inherit, - permissions disabled for a role are disabled for that role in all subforæ. + here a set of permissions may be associated with any role. + if a role does not have any permissions configured for this forum, + the permissions set for the role in closest ancestor forum are used. + if no permissions are set for the role in any ancestor forum, + the permissions for the role "other" are used.

-{% set show_footnote = False %} {% for role_config in role_configs %}
{{role_config.role}} @@ -31,10 +29,6 @@ />
{% endmacro %} @@ -51,41 +45,36 @@ {{perm("p_vote","vote", "allow users with the role to vote on poll threads")}} {{perm("p_create_subforum","create subforæ", - "allow users with the role to create subforæ in this forum. they will automatically become a bureaucrat in this subforum.")}} + "allow users with the role to create subforæ in this forum. " + + "they will automatically become a bureaucrat in this subforum.")}} {% if role_config.role != "other" %} {{perm("p_approve","approve others", "allow users with the role to assign the 'approved' role to those with the 'other' role")}} {% endif %} -
- -
{% endfor %} -{% if show_footnote %} -

* disabled in inherited permissions from parent forum

-{% endif %}
-{% if other_roles %} -
- roles from parent foræ -
    - {% for role in other_roles %} -
  • {{role}} -
    - -
    -
  • - {% endfor %} -
-
-{% endif %} +
+ add role +
    + {% for role in other_roles %} +
  • {{role}} +
    + + +
    +
  • + {% endfor %} +
  • +
    + + +
    +
  • +
+

confirm changes?

-- cgit v1.2.3