diff --git a/app/models/user.py b/app/models/user.py index 7b2fe72..1e9de8c 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -227,6 +227,10 @@ class Member(User): return self.can_access_post(post) and \ ((post.author == self) or self.priv("delete.posts")) + def can_punish_post(self, post): + """Whether this member can delete the post with penalty.""" + return self.can_access_post(post) and self.priv("delete.posts") + def can_set_topcomment(self, comment): """Whether this member can designate the comment as top comment.""" if comment.type != "comment": diff --git a/app/routes/posts/edit.py b/app/routes/posts/edit.py index 11b0a45..ab6269b 100644 --- a/app/routes/posts/edit.py +++ b/app/routes/posts/edit.py @@ -67,11 +67,16 @@ def edit_post(postid): @login_required @check_csrf def delete_post(postid): + next_page = request.referrer p = Post.query.filter_by(id=postid).first_or_404() if current_user.is_anonymous or not current_user.can_delete_post(p): abort(403) + # When deleting topics, return to forum page + if isinstance(p, Topic): + next_page = url_for('forum_page', f=p.forum) + if isinstance(p.author, Member): amount = -3 if request.args.get('penalty') == 'True' else -1 p.author.add_xp(amount) @@ -79,7 +84,7 @@ def delete_post(postid): p.delete() db.session.commit() - return redirect(request.referrer) + return redirect(next_page) @app.route('/post/entete/', methods=['GET']) @login_required diff --git a/app/templates/forum/topic.html b/app/templates/forum/topic.html index 468949c..aca7f5a 100644 --- a/app/templates/forum/topic.html +++ b/app/templates/forum/topic.html @@ -3,6 +3,7 @@ {% import "widgets/thread.html" as widget_thread with context %} {% import "widgets/user.html" as widget_user %} {% import "widgets/pagination.html" as widget_pagination with context %} +{% import "widgets/attachments.html" as widget_attachments %} {% block title %} Forum de Planète Casio » {{ t.forum.name }} »

{{ t.title }}

@@ -13,7 +14,12 @@

{{ t.title }}

{% call widget_thread.thread_leader(t.thread.top_comment) %} +
+
Posté le {{ t.date_created | dyndate }}
+ {{ widget_thread.post_actions(t) }} +
{{ t.thread.top_comment.text | md }} + {{ widget_attachments.attachments(t.thread.top_comment) }} {% endcall %} {{ widget_pagination.paginate(comments, 'forum_topic', t, {'f': t.forum}) }} diff --git a/app/templates/widgets/thread.html b/app/templates/widgets/thread.html index 486ecea..bcb4534 100644 --- a/app/templates/widgets/thread.html +++ b/app/templates/widgets/thread.html @@ -1,6 +1,46 @@ {% import "widgets/user.html" as widget_user %} {% import "widgets/attachments.html" as widget_attachments %} +{# Post actions: this widget expands to a context menu with actions controlling + a post, supporting different types of posts. #} +{% macro post_actions(post) %} + {# TODO (Guest edit): determine permissions in post_actions widget #} + + {% set auth = current_user.is_authenticated %} + {% set can_edit = auth and current_user.can_edit_post(post) %} + {% set can_delete = auth and current_user.can_delete_post(post) %} + {% set can_punish = auth and current_user.can_punish_post(post) %} + {% set can_topcomm = auth and current_user.can_set_topcomment(post) %} + + {% if post.type == "topic" %} + {% set suffix = " le topic" %} + {% elif post.type == "program" %} + {% set suffix = " le programme" %} + {% endif %} + + {% if can_edit or can_delete or can_punish or can_topcomm %} +
+ +
+ {% if can_edit %} + Modifier{{ suffix }} + {% endif %} + + {% if can_punish %} + Supprimer{{ suffix }} (normal) + Supprimer{{ suffix }} (pénalité) + {% elif can_delete %} + Supprimer{{ suffix }} + {% endif %} + + {% if can_topcomm %} + Utiliser comme en-tête + {% endif %} +
+
+ {% endif %} +{% endmacro %} + {# Thread widget: this widget expands to a table that shows a list of comments from a thread, along with message controls. @@ -19,38 +59,10 @@ {% if c.date_created != c.date_modified %}
Modifié le {{ c.date_modified | dyndate }}
{% endif %} - - {# TODO: Let guests edit their posts #} - {% set can_edit = current_user.is_authenticated and current_user.can_edit_post(c) %} - {% set can_delete = current_user.is_authenticated and current_user.can_delete_post(c) %} - {% set can_punish = current_user.is_authenticated and current_user.priv("delete.posts") %} - {% set can_topcomm = current_user.is_authenticated and current_user.can_set_topcomment(c) %} - - {% if can_edit or can_delete or can_punish %} -
- -
- {% if can_edit %} - Modifier - {% endif %} - - {% if can_punish %} - Supprimer (normal) - Supprimer (pénalité) - {% elif can_delete %} - Supprimer - {% endif %} - - {% if can_topcomm %} - Utiliser comme en-tête - {% endif %} -
-
- {% endif %} + {{ post_actions(c) }} {{ c.text|md }} - {{ widget_attachments.attachments(c) }} {% if c.author.signature %}