Browse Source

Added kitchensink buttons to post template

Rafał Pitoń 10 years ago
parent
commit
017f012f5b
2 changed files with 80 additions and 11 deletions
  1. 46 3
      misago/templates/misago/thread/post.html
  2. 34 8
      misago/threads/permissions.py

+ 46 - 3
misago/templates/misago/thread/post.html

@@ -30,7 +30,7 @@
           {{ post.posted_on|date }}
         </a>
 
-        {% if post.is_read %}
+        {% if not post.is_read %}
         <span class="label label-success">
           <span class="fa fa-plus-circle"></span>
           {% trans "New" %}
@@ -77,8 +77,51 @@
       </div>
 
       <div class="panel-footer">
-        Like Report
-        Approve Hide Delete Reply
+
+        {% if thread.acl.can_reply %}
+        <button type="button" class="btn btn-primary btn-flat pull-right">
+          <span class="fa fa-reply">
+          Reply
+        </button>
+        {% endif %}
+
+        {% if post.acl.can_edit %}
+        <button type="button" class="btn btn-default btn-flat pull-right">
+          <span class="fa fa-pencil">
+          Edit
+        </button>
+        {% endif %}
+
+
+        <button type="button" class="btn btn-warning btn-flat pull-right">
+          <span class="fa fa-eye-slash">
+          Hide
+        </button>
+
+        <button type="button" class="btn btn-default btn-flat pull-right">
+          <span class="fa fa-eye">
+          Show
+        </button>
+
+        <button type="button" class="btn btn-danger btn-flat pull-right">
+          <span class="fa fa-times">
+          Delete
+        </button>
+
+        <button type="button" class="btn btn-warning btn-flat pull-right">
+          <span class="fa fa-exclamation-triangle">
+          Report
+        </button>
+
+        <button type="button" class="btn btn-success btn-flat pull-right">
+          <span class="fa fa-check">
+          Approve
+        </button>
+
+        <button type="button" class="btn btn-success btn-flat pull-left">
+          <span class="fa fa-heart">
+          Like
+        </button>
       </div>
     </div>
 

+ 34 - 8
misago/threads/permissions.py

@@ -262,7 +262,7 @@ def add_acl_to_forum(user, forum):
             can_hide_own_threads=algebra.greater,
             can_hide_own_posts=algebra.greater,
             thread_edit_time=algebra.greater_or_zero,
-            posts_edit_time=algebra.greater_or_zero,
+            post_edit_time=algebra.greater_or_zero,
             can_protect_posts=algebra.greater,
             can_move_posts=algebra.greater,
             can_merge_posts=algebra.greater,
@@ -310,7 +310,7 @@ def add_acl_to_post(user, post):
 
     post.acl.update({
         'can_reply': can_reply_thread(user, post.thread),
-        'can_edit': can_edit_reply(user, post),
+        'can_edit': can_edit_post(user, post),
         'can_unhide': forum_acl.get('can_hide_threads'),
         'can_hide': forum_acl.get('can_hide_threads'),
         'can_delete': forum_acl.get('can_hide_threads'),
@@ -385,13 +385,10 @@ def allow_edit_thread(user, target):
             _("You can't edit closed threads in this forum."))
 
     if forum_acl['can_edit_threads'] == 1:
-        if thread.starter_id != user.pk:
+        if target.starter_id != user.pk:
             raise PermissionDenied(
                 _("You can't edit other users threads in this forum."))
-        if thread.starter_id != user.pk:
-            raise PermissionDenied(
-                _("You can't edit other users threads in this forum."))
-        if not has_time_to_edit_thread(user, thread):
+        if not has_time_to_edit_thread(user, target):
             message = ungettext("You can't edit threads that are "
                                 "older than %(minutes)s minute.",
                                 "You can't edit threads that are "
@@ -412,7 +409,36 @@ can_see_post = return_boolean(allow_see_post)
 
 
 def allow_edit_post(user, target):
-    pass
+    if target.forum.is_closed:
+        message = _("This forum is closed. You can't edit posts in it.")
+        raise PermissionDenied(message)
+    if user.is_anonymous():
+        raise PermissionDenied(_("You have to sign in to edit posts."))
+
+    forum_acl = target.forum.acl
+
+    if not forum_acl['can_edit_posts']:
+        raise PermissionDenied(_("You can't edit posts in this forum."))
+
+    if target.thread.is_closed and not forum_acl['can_close_threads']:
+        raise PermissionDenied(
+            _("You can't edit posts in closed threads."))
+
+    if target.is_protected and not forum_acl['can_protect_posts']:
+        raise PermissionDenied(_("This post is protected. You can't edit it."))
+
+    if forum_acl['can_edit_posts'] == 1:
+        if target.poster_id != user.pk:
+            raise PermissionDenied(
+                _("You can't edit other users posts in this forum."))
+        if not has_time_to_edit_post(user, target):
+            message = ungettext("You can't edit posts that are "
+                                "older than %(minutes)s minute.",
+                                "You can't edit posts that are "
+                                "older than %(minutes)s minutes.",
+                                forum_acl['post_edit_time'])
+            raise PermissionDenied(
+                message % {'minutes': forum_acl['post_edit_time']})
 can_edit_post = return_boolean(allow_edit_post)