summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorcitrons <citrons>2021-07-16 09:46:44 +0000
committercitrons <citrons>2021-07-16 09:46:44 +0000
commit338d67854d5eca63b6596fb309589755012c4ca2 (patch)
tree4285e7703c5592a4ae3e2372b181b7e067c4639e
parenteb340b12ae9844d5ff2e4a927753c4d92d3f56e0 (diff)
committing what I have so that ubq can work on it
-rw-r--r--apioforum/db.py12
-rw-r--r--apioforum/forum.py10
-rw-r--r--apioforum/roles.py40
-rw-r--r--apioforum/static/style.css2
-rw-r--r--apioforum/templates/edit_permissions.html71
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("/<int:forum_id>/roles/new/<role_name>",methods=["POST"])
-def add_role(forum_id,role_name):
- db.execute
+@bp.route("/<int:forum_id>/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 %}<h1>{% block title %}role permissions for '{{forum.name}}'{% endblock %}</h1>{% endblock %}
{% block content %}
<p>
- 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.
</p>
<p>
- 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.
-</p>
-<p>
- 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.
</p>
<form method="post" id="role_config">
-{% set show_footnote = False %}
{% for role_config in role_configs %}
<fieldset>
<legend id="config_{{role_config.role}}">{{role_config.role}}</legend>
@@ -31,10 +29,6 @@
/>
<label for="{{role_config.role}}_{{p}}" title="{{tooltip}}">
{{- description -}}
- {%- if overridden[role_config.id][p] -%}
- *
- {%- set show_footnote = True -%}
- {%- endif -%}
</label>
<br/>
{% 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 %}
- <hr/>
- <input
- type="checkbox"
- id="{{role_config.role}}_inherit"
- name="{{role_config.role}}_inherit"
- {% if role_config.inherit %}checked{% endif %}
- />
- <label for="{{role_config.role}}_inherit">inherit</label>
</fieldset>
{% endfor %}
-{% if show_footnote %}
- <p>* disabled in inherited permissions from parent forum</p>
-{% endif %}
</form>
-{% if other_roles %}
- <fieldset>
- <legend>roles from parent foræ</legend>
- <ul>
- {% for role in other_roles %}
- <li>{{role}}
- <form action="{{url_for('forum.add_role',forum_id=forum.id,role_name=role)}}" method="POST" style="display:inline">
- <input type="submit" value="add" />
- </form>
- </li>
- {% endfor %}
- </ul>
- </fieldset>
-{% endif %}
+<fieldset>
+ <legend>add role</legend>
+ <ul>
+ {% for role in other_roles %}
+ <li>{{role}}
+ <form action="{{url_for('forum.add_role',forum_id=forum.id)}}" method="POST" style="display:inline">
+ <input type="hidden" value="{{role}}" name="role" />
+ <input type="submit" value="add" />
+ </form>
+ </li>
+ {% endfor %}
+ <li>
+ <form action="{{url_for('forum.add_role',forum_id=forum.id,role_name=role)}}" method="POST" style="display:inline">
+ <input type="text" name="role" class="role-input" placeholder="role name"/>
+ <input type="submit" value="add" />
+ </form>
+ </li>
+ </ul>
+</fieldset>
<p>confirm changes?</p>
<input type="submit" value="confirm" form="role_config">