Browse Source

ACL debug panel #369

Rafał Pitoń 11 years ago
parent
commit
3699b19623
4 changed files with 90 additions and 0 deletions
  1. 1 0
      docs/developers/acls.rst
  2. 26 0
      misago/acl/panels.py
  3. 17 0
      misago/conf/defaults.py
  4. 46 0
      misago/templates/misago/acl_debug.html

+ 1 - 0
docs/developers/acls.rst

@@ -76,6 +76,7 @@ Optional. Is called when Misago is trying to make ``target`` aware of its ACLs.
 
 
 Value of ``target`` argument has ``acl`` attribute which is dict with incomplete ACL that function can change and update with new keys.
 Value of ``target`` argument has ``acl`` attribute which is dict with incomplete ACL that function can change and update with new keys.
 
 
+Misago comes with its own debug page titled "Misago User ACL" that is available from Django Debug Toolbar menu. This page display user roles permissions as well as final ACL assigned to current user.
 
 
 Algebra
 Algebra
 -------
 -------

+ 26 - 0
misago/acl/panels.py

@@ -0,0 +1,26 @@
+from django.template.loader import render_to_string
+from django.utils.translation import ugettext_lazy as _
+from debug_toolbar.panels import Panel
+
+
+class MisagoACLPanel(Panel):
+    """
+    Panel that displays current user's ACL
+    """
+    title = _('Misago User ACL')
+    template = 'misago/acl_debug.html'
+
+    @property
+    def nav_subtitle(self):
+        misago_user = self.get_stats().get('misago_user')
+
+        if misago_user.is_authenticated():
+            return misago_user.username
+        else:
+            return _("Anonymous user")
+
+    def process_response(self, request, response):
+        self.record_stats({
+            'misago_user': request.user,
+            'misago_acl': request.user.acl,
+        })

+ 17 - 0
misago/conf/defaults.py

@@ -200,3 +200,20 @@ MISAGO_ADMIN_SESSION_EXPIRATION = 60
 
 
 # Default forms templates
 # Default forms templates
 CRISPY_TEMPLATE_PACK = 'bootstrap3'
 CRISPY_TEMPLATE_PACK = 'bootstrap3'
+
+
+# Register Misago debug panels
+DEBUG_TOOLBAR_PANELS = (
+    'debug_toolbar.panels.versions.VersionsPanel',
+    'debug_toolbar.panels.timer.TimerPanel',
+    'debug_toolbar.panels.settings.SettingsPanel',
+    'debug_toolbar.panels.headers.HeadersPanel',
+    'debug_toolbar.panels.request.RequestPanel',
+    'debug_toolbar.panels.sql.SQLPanel',
+    'misago.acl.panels.MisagoACLPanel',
+    'debug_toolbar.panels.staticfiles.StaticFilesPanel',
+    'debug_toolbar.panels.templates.TemplatesPanel',
+    'debug_toolbar.panels.cache.CachePanel',
+    'debug_toolbar.panels.signals.SignalsPanel',
+    'debug_toolbar.panels.logging.LoggingPanel',
+)

+ 46 - 0
misago/templates/misago/acl_debug.html

@@ -0,0 +1,46 @@
+{% load i18n %}
+
+<h4>
+{% if misago_user.is_authenticated %}
+  {% blocktrans with username=misago_user.username %}
+  {{ username }} roles
+  {% endblocktrans %}
+{% else %}
+  {% trans "Anonymous roles" %}
+{% endif %}
+</h4>
+<table>
+    <thead>
+        <tr>
+            <th style="width: 180px;">{% trans "Role" %}</th>
+            <th>{% trans "Permissions" %}</th>
+        </tr>
+    </thead>
+    <tbody>
+        {% for role in misago_user.get_roles %}
+        <tr>
+            <td>{{ role.name }}</td>
+            <td>{{ role.permissions }}</td>
+        </tr>
+        {% endfor %}
+    </tbody>
+</table>
+
+
+<h4>{% trans "Current ACL" %}</h4>
+<table>
+    <thead>
+        <tr>
+            <th style="width: 180px;">{% trans "Key" %}</th>
+            <th>{% trans "Value" %}</th>
+        </tr>
+    </thead>
+    <tbody>
+        {% for key, value in misago_acl.items %}
+        <tr>
+            <td>{{ key }}</td>
+            <td>{{ value }}</td>
+        </tr>
+        {% endfor %}
+    </tbody>
+</table>