From 0d5dbce1f92c9bff13c86d18563d927ba0a98890 Mon Sep 17 00:00:00 2001 From: rebecca Date: Mon, 2 Nov 2026 19:34:01 +0000 Subject: merge view_history and view_post views into one it's a little odd to have two similar-looking pages for two pieces of information about a post, when we can combine the two quite easily. the ux feels a lot nicer now these are in the same place. this also fixes the inconsistent permission checks i mentioned on xmpp. featuring a ridiculous name for the actionbutton, to avoid any choice of name distracting from the main changes. --- apioforum/templates/common.html | 12 ++++++----- apioforum/templates/history.html | 22 -------------------- apioforum/templates/view_post.html | 41 ++++++++++++++++++++++++++++---------- apioforum/thread.py | 29 ++++++++++----------------- 4 files changed, 48 insertions(+), 56 deletions(-) delete mode 100644 apioforum/templates/history.html diff --git a/apioforum/templates/common.html b/apioforum/templates/common.html index c731180..ee31507 100644 --- a/apioforum/templates/common.html +++ b/apioforum/templates/common.html @@ -49,11 +49,13 @@ href="{{url_for('thread.delete_post',post_id=post.id)}}">delete {% endif %} src - {% if post.wiki == 1 or is_admin() or g.user == post.author %} - history - {% endif %} + href="{{url_for('thread.view_post',post_id=post.id)}}"> + {%- if post.wiki == 1 or is_admin() or g.user == post.author -%} + src and history and also you can change the colour of the bike shed + {%- else -%} + src + {%- endif -%} + {% endif %} #{{post.id}} diff --git a/apioforum/templates/history.html b/apioforum/templates/history.html deleted file mode 100644 index 48fcc97..0000000 --- a/apioforum/templates/history.html +++ /dev/null @@ -1,22 +0,0 @@ -{% from 'common.html' import disp_post, ts %} -{% extends 'base.html' %} -{% block header %} -

{%block title%}revision history{%endblock%}

-{% endblock %} - -{% block content %} -{{disp_post(post, preview = True)}} -

edits

- -{% for rev in history %} - -
{{disp_user(rev.author)}} - - - {{ts(rev.time)}} ago - - {{rev.comment}} -{% endfor %} -
-

i am satisfied

-{% endblock %} diff --git a/apioforum/templates/view_post.html b/apioforum/templates/view_post.html index ed8e0dd..810794e 100644 --- a/apioforum/templates/view_post.html +++ b/apioforum/templates/view_post.html @@ -1,24 +1,45 @@ -{% from 'common.html' import disp_post %} +{% from 'common.html' import disp_post, ts %} {% extends 'base.html' %} {% block header %}

{%block title%} {% if not revision %} - viewing post + viewing post #{{post.id}} {% else %} - viewing revision + viewing revision #{{revision.id}} of #{{post.id}} {% endif %} {%endblock%}

{% endblock %} {% block content %} -{{disp_post(post,False)}} -

post source:

- -{% if not revision %} - i am satisfied -{% else %} - i am satisfied + +{{disp_post(post)}} + +
view post source + +
+ +{% if history %} +

revision history

+ +{% for rev in history %} + + +{% endfor %} +
{{disp_user(rev.author)}} + + {% if rev.id == revision.id or (loop.index == 1 and not revision) %} + {{ts(rev.time)}} ago + {% else %} + + {{ts(rev.time)}} ago + + {% endif %} + {{rev.comment or "(no comment)"}}
{% endif %} + +

i am satisfied

+ + {% endblock %} diff --git a/apioforum/thread.py b/apioforum/thread.py index b679b2a..485fe01 100644 --- a/apioforum/thread.py +++ b/apioforum/thread.py @@ -411,6 +411,8 @@ def view_post(post_id): if not has_permission(post['f_id'], g.user, "p_view_threads", False): abort(403) + can_view_history = post['wiki'] or is_admin() or g.user == post['author'] + rev = None if 'revision' in request.args: rev_id = None @@ -418,35 +420,24 @@ def view_post(post_id): rev_id = int(request.args['revision']) except ValueError: abort(404) + if not can_view_history: + abort(403) rev = db.execute("SELECT * FROM revisions WHERE id = ?;",(rev_id,)).fetchone() if not rev: abort(404) if rev['post'] != post_id: abort(404) - if post['wiki'] != 1 and not is_admin() and g.user != post['author']: - abort(403) post = dict(post) post['content'] = rev['content'] post['updated'] = rev['time'] - return render_template("view_post.html",post=post,revision=rev) + history = None + if can_view_history: + history = db.execute(""" + SELECT author, time, comment, id FROM revisions WHERE post = ? ORDER BY id DESC; + """,(post_id,)).fetchall() -@bp.route("/history/") -def view_history(post_id): - db = get_db() - post = db.execute(""" - SELECT p.*,h.f_id FROM posts p - INNER JOIN forum_thread_of_post h ON p.id = h.p_id - WHERE p.id = ?; - """,(post_id,)).fetchone() - if post is None: - abort(404) - if not has_permission(post['f_id'], g.user, "p_view_threads", False): - abort(403) - history = db.execute(""" - SELECT author, time, comment, id FROM revisions WHERE post = ? ORDER BY time DESC; - """,(post_id,)).fetchall() - return render_template("history.html",post=post,history=history) + return render_template("view_post.html",post=post,revision=rev,history=history) def apply_selected_tags(thread, form): db = get_db() -- cgit v1.2.3