doorcontrol: Add permissions requirements for assigning NFC cards
All checks were successful
Ruff / ruff (push) Successful in 29s
Test / test (push) Successful in 5m50s

This commit is contained in:
Adam Goldsmith 2024-12-12 11:14:44 -05:00
parent 638db1c0b7
commit 801017f316
3 changed files with 29 additions and 2 deletions

View File

@ -0,0 +1,21 @@
# Generated by Django 5.1.4 on 2024-12-12 16:14
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
(
"doorcontrol",
"0003_attributeschedulerule_name_flagschedulerule_name_and_more",
),
]
operations = [
migrations.AlterModelOptions(
name="door",
options={
"permissions": [("assign_nfc_card", "Assign NFC cards to members.")]
},
),
]

View File

@ -22,6 +22,9 @@ class Door(models.Model):
help_text="Membershipworks field that grants members access to this door", help_text="Membershipworks field that grants members access to this door",
) )
class Meta:
permissions = [("assign_nfc_card", "Assign NFC cards to members.")]
def __str__(self): def __str__(self):
return self.name return self.name

View File

@ -3,6 +3,7 @@ import itertools
from typing import TYPE_CHECKING, Any from typing import TYPE_CHECKING, Any
from django.conf import settings from django.conf import settings
from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.auth.mixins import PermissionRequiredMixin
from django.contrib.postgres.aggregates import StringAgg from django.contrib.postgres.aggregates import StringAgg
from django.core.exceptions import BadRequest from django.core.exceptions import BadRequest
@ -320,6 +321,8 @@ def update_access_users() -> list[FullUser]:
return list(access_client.fetch_all_users__unpaged()) return list(access_client.fetch_all_users__unpaged())
@login_required
@permission_required("doorcontrol.assign_nfc_card", raise_exception=True)
def assign_nfc_card_user_selector(request: HttpRequest): def assign_nfc_card_user_selector(request: HttpRequest):
template_name = "doorcontrol/assign_nfc_card_user_selector.dj.html" template_name = "doorcontrol/assign_nfc_card_user_selector.dj.html"
task_group = "update_access_users" task_group = "update_access_users"
@ -396,10 +399,10 @@ class AssignNfcCardStatus(BaseModel):
) )
class AssignNfcCardView(TemplateView): class AssignNfcCardView(PermissionRequiredMixin, TemplateView):
# for storage in request.session # for storage in request.session
ENROLLMENT_STATUS_SESSION_KEY = "unifi_access_enrollment_status" ENROLLMENT_STATUS_SESSION_KEY = "unifi_access_enrollment_status"
requires_permission = "doorcontrol.assign_nfc_card"
template_name = "doorcontrol/assign_nfc_card.dj.html" template_name = "doorcontrol/assign_nfc_card.dj.html"
def get_template_names(self) -> list[str]: def get_template_names(self) -> list[str]: