Browse Source

Add view handling for hide/unhide

Alec Nikolas Reiter 7 years ago
parent
commit
22c47bcd7e
2 changed files with 26 additions and 6 deletions
  1. 15 6
      flaskbb/forum/views.py
  2. 11 0
      flaskbb/templates/forum/edit_forum.html

+ 15 - 6
flaskbb/forum/views.py

@@ -279,9 +279,7 @@ def hide_topic(topic_id, slug=None):
         flash(_("You do not have permission to hide this topic"),
                 "danger")
         return redirect(topic.url)
-    involved_users = User.query.filter(Post.topic_id == topic.id,
-                                       User.id == Post.user_id).all()
-    topic.hide(involved_users)
+    topic.hide()
     topic.save()
     return redirect(url_for('forum.view_forum', forum_id=topic.forum.id, slug=topic.forum.slug))
 
@@ -296,9 +294,7 @@ def unhide_topic(topic_id, slug=None):
         flash(_("You do not have permission to unhide this topic"),
                 "danger")
         return redirect(topic.url)
-    involved_users = User.query.filter(Post.topic_id == topic.id,
-                                       User.id == Post.user_id).all()
-    topic.unhide(involved_users)
+    topic.unhide()
     topic.save()
     return redirect(topic.url)
 
@@ -401,6 +397,19 @@ def manage_forum(forum_id, slug=None):
             new_forum.move_topics_to(tmp_topics)
             return redirect(mod_forum_url)
 
+        # hiding/unhiding
+        elif "hide" in request.form:
+            changed = do_topic_action(topics=tmp_topics, user=real(current_user),
+                                      action="hide", reverse=False)
+            flash(_("%(count)s topics hidden.", count=changed), "success")
+            return redirect(mod_forum_url)
+
+        elif "unhide" in request.form:
+            changed = do_topic_action(topics=tmp_topics, user=real(current_user),
+                                      action="unhide", reverse=False)
+            flash(_("%(count)s topics unhidden.", count=changed), "success")
+            return redirect(mod_forum_url)
+
     return render_template(
         "forum/edit_forum.html", forum=forum_instance, topics=topics,
         available_forums=available_forums, forumsread=forumsread,

+ 11 - 0
flaskbb/templates/forum/edit_forum.html

@@ -145,6 +145,17 @@
                             <span class="fa fa-trash-o fa-fw"></span> {% trans %}Delete{% endtrans %}
                         </button>
 
+                        {% if current_user.permissions.get('makehidden') %}
+                        <div class="btn-group" role="group">
+                            <button name="hide" class="btn btn-info">
+                                <span class="fa fa-user-secret fa-fw"></span> {% trans %}Hide{% endtrans %}
+                            </button>
+                            <button name="unhide" class="btn btn-info">
+                                <span class="fa fa-user fa-fw"></span> {% trans %}Unhide{% endtrans %}
+                            </button>
+                        </div>
+                        {% endif %}
+
                     </div>
                 </div>
             </div>