Browse Source

Don't display "Delete" button for non-deletable groups

Peter Justin 7 years ago
parent
commit
1890f2727a
2 changed files with 17 additions and 10 deletions
  1. 14 10
      flaskbb/management/views.py
  2. 3 0
      flaskbb/templates/management/groups.html

+ 14 - 10
flaskbb/management/views.py

@@ -355,7 +355,8 @@ class BanUser(MethodView):
     def post(self, user_id=None):
         if not Permission(CanBanUser, identity=current_user):
             flash(
-                _("You do not have the permissions to ban this user."), "danger"
+                _("You do not have the permissions to ban this user."),
+                "danger"
             )
             return redirect(url_for("management.overview"))
 
@@ -366,11 +367,11 @@ class BanUser(MethodView):
             data = []
             users = User.query.filter(User.id.in_(ids)).all()
             for user in users:
-                # don't let a user ban himself and do not allow a moderator to ban
-                # a admin user
-                if (current_user.id == user.id
-                        or Permission(IsAdmin, identity=user)
-                        and Permission(Not(IsAdmin), current_user)):
+                # don't let a user ban himself and do not allow a moderator
+                # to ban a admin user
+                if (current_user.id == user.id or
+                        Permission(IsAdmin, identity=user) and
+                        Permission(Not(IsAdmin), current_user)):
                     continue
 
                 elif user.ban():
@@ -435,7 +436,8 @@ class UnbanUser(MethodView):
                             "type": "unban",
                             "reverse": "ban",
                             "reverse_name": _("Ban"),
-                            "reverse_url": url_for("management.ban_user", user_id=user.id)
+                            "reverse_url": url_for("management.ban_user",
+                                                   user_id=user.id)
                         }
                     )
 
@@ -529,7 +531,8 @@ class DeleteGroup(MethodView):
     def post(self, group_id=None):
         if request.is_xhr:
             ids = request.get_json()["ids"]
-            if not (set(ids) & set(["1", "2", "3", "4", "5"])):
+            # TODO: Get rid of magic numbers
+            if not (set(ids) & set(["1", "2", "3", "4", "5", "6"])):
                 data = []
                 for group in Group.query.filter(Group.id.in_(ids)).all():
                     group.delete()
@@ -557,7 +560,7 @@ class DeleteGroup(MethodView):
             )
 
         if group_id is not None:
-            if group_id <= 5:  # there are 5 standard groups
+            if group_id <= 6:  # there are 6 standard groups
                 flash(
                     _(
                         "You cannot delete the standard groups. "
@@ -610,7 +613,8 @@ class EditForum(MethodView):
         if form.validate_on_submit():
             form.save()
             flash(_('Forum updated.'), 'success')
-            return redirect(url_for('management.edit_forum', forum_id=forum.id))
+            return redirect(url_for('management.edit_forum',
+                                    forum_id=forum.id))
         else:
             if forum.moderators:
                 form.moderators.data = ','.join(

+ 3 - 0
flaskbb/templates/management/groups.html

@@ -58,12 +58,15 @@
                         <a href="{{ url_for('management.edit_group', group_id = group.id) }}" class="btn btn-icon">
                             <span class="fa fa-pencil text-primary" data-toggle="tooltip" data-placement="top" title="{% trans %}Edit{% endtrans %}"></span>
                         </a>
+                        {# only display "Delete" if group is not part of the standard groups. #}
+                        {% if group.id > 6 %}
                         <form class="inline-form" id="delete-{{group.id}}" method="post" action="{{ url_for('management.delete_group', group_id=group.id) }}">
                             <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
                             <button class="btn btn-icon" name="confirmDialog" data-toggle="tooltip" data-placement="top" title="{% trans %}Delete{% endtrans %}">
                                 <span class="fa fa-trash text-danger"></span>
                             </button>
                         </form>
+                        {% endif %}
                     </div>
                 </div>
             {% else %}