Skip to content

Commit 29ee3e5

Browse files
committed
Clean up home view stats
1 parent 011f351 commit 29ee3e5

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

netbox/netbox/views/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def get(self, request):
5656
).defer('data')[:10]
5757

5858
def build_stats():
59-
perms = request.user.get_all_permissions()
6059
org = (
6160
("dcim.view_site", "Sites", Site.objects.restrict(request.user, 'view').count),
6261
("tenancy.view_tenant", "Tenants", Tenant.objects.restrict(request.user, 'view').count),
@@ -116,7 +115,7 @@ def build_stats():
116115
"url": url,
117116
"disabled": True
118117
}
119-
if perm in perms:
118+
if request.user.has_perm(perm):
120119
item["count"] = get_count()
121120
item["disabled"] = False
122121
items.append(item)

netbox/templates/home.html

+11-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
{% load render_table from django_tables2 %}
55

66
{% block header %}
7-
{{ block.super }}
87
{% if new_release %}
98
{# new_release is set only if the current user is a superuser or staff member #}
109
<div class="header-alert-container">
@@ -35,13 +34,22 @@ <h6 class="card-header text-primary text-center">{{ section }}</h6>
3534
<div class="card-body">
3635
<div class="list-group list-group-flush">
3736
{% for item in items %}
38-
{% if item.count %}
39-
<a href="{% url item.url %}" class="list-group-item list-group-item-action{% if item.disabled %} disabled{% endif %}">
37+
{% if not item.disabled %}
38+
<a href="{% url item.url %}" class="list-group-item list-group-item-action">
4039
<div class="d-flex w-100 justify-content-between align-items-center">
4140
{{ item.label }}
4241
<h4 class="mb-1">{{ item.count }}</h4>
4342
</div>
4443
</a>
44+
{% else %}
45+
<li class="list-group-item list-group-item-action disabled">
46+
<div class="d-flex w-100 justify-content-between align-items-center">
47+
{{ item.label }}
48+
<h4 class="mb-1">
49+
<i title="No permission" class="mdi mdi-lock"></i>
50+
</h4>
51+
</div>
52+
</li>
4553
{% endif %}
4654
{% endfor %}
4755
</div>

0 commit comments

Comments
 (0)