Răsfoiți Sursa

Clean up home view stats

jeremystretch 4 ani în urmă
părinte
comite
29ee3e5ac0
2 a modificat fișierele cu 12 adăugiri și 5 ștergeri
  1. 1 2
      netbox/netbox/views/__init__.py
  2. 11 3
      netbox/templates/home.html

+ 1 - 2
netbox/netbox/views/__init__.py

@@ -56,7 +56,6 @@ class HomeView(View):
         ).defer('data')[:10]
         ).defer('data')[:10]
 
 
         def build_stats():
         def build_stats():
-            perms = request.user.get_all_permissions()
             org = (
             org = (
                 ("dcim.view_site", "Sites", Site.objects.restrict(request.user, 'view').count),
                 ("dcim.view_site", "Sites", Site.objects.restrict(request.user, 'view').count),
                 ("tenancy.view_tenant", "Tenants", Tenant.objects.restrict(request.user, 'view').count),
                 ("tenancy.view_tenant", "Tenants", Tenant.objects.restrict(request.user, 'view').count),
@@ -116,7 +115,7 @@ class HomeView(View):
                         "url": url,
                         "url": url,
                         "disabled": True
                         "disabled": True
                     }
                     }
-                    if perm in perms:
+                    if request.user.has_perm(perm):
                         item["count"] = get_count()
                         item["count"] = get_count()
                         item["disabled"] = False
                         item["disabled"] = False
                     items.append(item)
                     items.append(item)

+ 11 - 3
netbox/templates/home.html

@@ -4,7 +4,6 @@
 {% load render_table from django_tables2 %}
 {% load render_table from django_tables2 %}
 
 
 {% block header %}
 {% block header %}
-    {{ block.super }}
     {% if new_release %}
     {% if new_release %}
         {# new_release is set only if the current user is a superuser or staff member #}
         {# new_release is set only if the current user is a superuser or staff member #}
         <div class="header-alert-container">
         <div class="header-alert-container">
@@ -35,13 +34,22 @@
           <div class="card-body">
           <div class="card-body">
             <div class="list-group list-group-flush">
             <div class="list-group list-group-flush">
               {% for item in items %}
               {% for item in items %}
-                {% if item.count %}
-                  <a href="{% url item.url %}" class="list-group-item list-group-item-action{% if item.disabled %} disabled{% endif %}">
+                {% if not item.disabled %}
+                  <a href="{% url item.url %}" class="list-group-item list-group-item-action">
                     <div class="d-flex w-100 justify-content-between align-items-center">
                     <div class="d-flex w-100 justify-content-between align-items-center">
                       {{ item.label }}
                       {{ item.label }}
                       <h4 class="mb-1">{{ item.count }}</h4>
                       <h4 class="mb-1">{{ item.count }}</h4>
                     </div>
                     </div>
                   </a>
                   </a>
+                {% else %}
+                  <li class="list-group-item list-group-item-action disabled">
+                    <div class="d-flex w-100 justify-content-between align-items-center">
+                      {{ item.label }}
+                      <h4 class="mb-1">
+                        <i title="No permission" class="mdi mdi-lock"></i>
+                      </h4>
+                    </div>
+                  </li>
                 {% endif %}
                 {% endif %}
               {% endfor %}
               {% endfor %}
             </div>
             </div>