Skip to content

Commit

Permalink
add link to dashboard, protect staff views
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed Dec 3, 2024
1 parent f1da62b commit 8748219
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/apps/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ def get_absolute_url(self: Self) -> str:
"""
return reverse("users:detail", kwargs={"pk": self.id})

def is_genlab_staff(self) -> bool:
return self.groups.filter(name="genlab").exists()
2 changes: 1 addition & 1 deletion src/genlab_bestilling/staff/templates/staff/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="px-2 py-2 min-w-72 bg-white">
<h5 class="font-bold text-xl">Menu</h5>
<ul class="flex flex-col gap-2 mt-2 text-lg px-4">
<li><a href="{% url 'staff:order-analysis-list' %}">Dashboard</a></li>
<li><a href="{% url 'staff:dashboard' %}">Dashboard</a></li>
<li><a href="{% url 'staff:order-analysis-list' %}">Analysis Orders</a></li>
<li><a href="{% url 'staff:order-equipment-list' %}">Equipment Orders</a></li>
</ul>
Expand Down
2 changes: 2 additions & 0 deletions src/genlab_bestilling/staff/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.urls import path
from django.views.generic import TemplateView

from ..models import AnalysisOrder, EquipmentOrder
from .views import (
Expand All @@ -14,6 +15,7 @@
app_name = "genlab.staff"

urlpatterns = [
path("", TemplateView.as_view(template_name="staff/base.html"), name="dashboard"),
path(
"orders/analysis/", AnalysisOrderListView.as_view(), name="order-analysis-list"
),
Expand Down
7 changes: 5 additions & 2 deletions src/genlab_bestilling/staff/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any

from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.http import HttpResponse, HttpResponseRedirect
from django.urls import reverse_lazy
from django.utils.translation import gettext as _
Expand All @@ -16,11 +16,14 @@
from .tables import AnalysisOrderTable, EquipmentOrderTable, SampleTable


class StaffMixin(LoginRequiredMixin):
class StaffMixin(LoginRequiredMixin, UserPassesTestMixin):
def get_template_names(self) -> list[str]:
names = super().get_template_names()
return [name.replace("genlab_bestilling", "staff") for name in names]

def test_func(self):
return self.request.user.is_genlab_staff()


class AnalysisOrderListView(StaffMixin, SingleTableMixin, FilterView):
model = AnalysisOrder
Expand Down
7 changes: 6 additions & 1 deletion src/templates/core/partials/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
</a>
</div>

<div class="flex items-center gap-3 2xsm:gap-7">
<div class="flex items-center gap-8 2xsm:gap-7 text-sm font-bold">
{% if user.is_authenticated %}
{% if user.is_genlab_staff %}
<div class="">
<a href="{% url 'staff:dashboard' %}">Staff</a>
</div>
{% endif %}
{% include 'core/partials/user-dropdown.html' %}
{% else %}
<a href="{% url 'account_login' %}">Login</a>
Expand Down

0 comments on commit 8748219

Please sign in to comment.