stages/authenticator_webauthn: add views to update and delete devices
This commit is contained in:
parent
3941590d0c
commit
8c41d2f4cb
|
@ -1,7 +1,10 @@
|
||||||
"""Webauthn stage forms"""
|
"""Webauthn stage forms"""
|
||||||
from django import forms
|
from django import forms
|
||||||
|
|
||||||
from authentik.stages.authenticator_webauthn.models import AuthenticateWebAuthnStage
|
from authentik.stages.authenticator_webauthn.models import (
|
||||||
|
AuthenticateWebAuthnStage,
|
||||||
|
WebAuthnDevice,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class AuthenticateWebAuthnStageForm(forms.ModelForm):
|
class AuthenticateWebAuthnStageForm(forms.ModelForm):
|
||||||
|
@ -15,3 +18,16 @@ class AuthenticateWebAuthnStageForm(forms.ModelForm):
|
||||||
widgets = {
|
widgets = {
|
||||||
"name": forms.TextInput(),
|
"name": forms.TextInput(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class DeviceEditForm(forms.ModelForm):
|
||||||
|
"""Form to edit webauthn device"""
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
|
||||||
|
model = WebAuthnDevice
|
||||||
|
fields = ["name"]
|
||||||
|
|
||||||
|
widgets = {
|
||||||
|
"name": forms.TextInput(),
|
||||||
|
}
|
||||||
|
|
|
@ -79,3 +79,8 @@ class WebAuthnDevice(Device):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name or str(self.user)
|
return self.name or str(self.user)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
|
||||||
|
verbose_name = _("WebAuthn Device")
|
||||||
|
verbose_name_plural = _("WebAuthn Devices")
|
||||||
|
|
|
@ -17,6 +17,20 @@
|
||||||
Created {{ created_on }}
|
Created {{ created_on }}
|
||||||
{% endblocktrans %}
|
{% endblocktrans %}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="pf-c-data-list__cell">
|
||||||
|
<ak-modal-button href="{% url 'authentik_stages_authenticator_webauthn:device-update' pk=device.pk %}">
|
||||||
|
<ak-spinner-button slot="trigger" class="pf-m-primary">
|
||||||
|
{% trans 'Update' %}
|
||||||
|
</ak-spinner-button>
|
||||||
|
<div slot="modal"></div>
|
||||||
|
</ak-modal-button>
|
||||||
|
<ak-modal-button href="{% url 'authentik_stages_authenticator_webauthn:device-delete' pk=device.pk %}">
|
||||||
|
<ak-spinner-button slot="trigger" class="pf-m-danger">
|
||||||
|
{% trans 'Delete' %}
|
||||||
|
</ak-spinner-button>
|
||||||
|
<div slot="modal"></div>
|
||||||
|
</ak-modal-button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
"""WebAuthn urls"""
|
"""WebAuthn urls"""
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from authentik.stages.authenticator_webauthn.views import UserSettingsView
|
from authentik.stages.authenticator_webauthn.views import (
|
||||||
|
DeviceDeleteView,
|
||||||
|
DeviceUpdateView,
|
||||||
|
UserSettingsView,
|
||||||
|
)
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path(
|
path(
|
||||||
"<uuid:stage_uuid>/settings/", UserSettingsView.as_view(), name="user-settings"
|
"<uuid:stage_uuid>/settings/", UserSettingsView.as_view(), name="user-settings"
|
||||||
),
|
),
|
||||||
|
path("devices/<int:pk>/delete/", DeviceDeleteView.as_view(), name="device-delete"),
|
||||||
|
path("devices/<int:pk>/update/", DeviceUpdateView.as_view(), name="device-update"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
"""webauthn views"""
|
"""webauthn views"""
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
|
from django.contrib.messages.views import SuccessMessageMixin
|
||||||
|
from django.http.response import Http404
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.views.generic import TemplateView
|
from django.utils.translation import gettext as _
|
||||||
|
from django.views.generic import TemplateView, UpdateView
|
||||||
|
|
||||||
|
from authentik.admin.views.utils import DeleteMessageView
|
||||||
|
from authentik.stages.authenticator_webauthn.forms import DeviceEditForm
|
||||||
from authentik.stages.authenticator_webauthn.models import (
|
from authentik.stages.authenticator_webauthn.models import (
|
||||||
AuthenticateWebAuthnStage,
|
AuthenticateWebAuthnStage,
|
||||||
WebAuthnDevice,
|
WebAuthnDevice,
|
||||||
|
@ -22,3 +27,34 @@ class UserSettingsView(LoginRequiredMixin, TemplateView):
|
||||||
)
|
)
|
||||||
kwargs["stage"] = stage
|
kwargs["stage"] = stage
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
|
class DeviceUpdateView(SuccessMessageMixin, LoginRequiredMixin, UpdateView):
|
||||||
|
"""Update device"""
|
||||||
|
|
||||||
|
model = WebAuthnDevice
|
||||||
|
form_class = DeviceEditForm
|
||||||
|
template_name = "generic/update.html"
|
||||||
|
success_url = "/"
|
||||||
|
success_message = _("Successfully updated Device")
|
||||||
|
|
||||||
|
def get_object(self) -> WebAuthnDevice:
|
||||||
|
device: WebAuthnDevice = super().get_object()
|
||||||
|
if device.user != self.request.user:
|
||||||
|
raise Http404
|
||||||
|
return device
|
||||||
|
|
||||||
|
|
||||||
|
class DeviceDeleteView(LoginRequiredMixin, DeleteMessageView):
|
||||||
|
"""Delete device"""
|
||||||
|
|
||||||
|
model = WebAuthnDevice
|
||||||
|
template_name = "generic/delete.html"
|
||||||
|
success_url = "/"
|
||||||
|
success_message = _("Successfully deleted Device")
|
||||||
|
|
||||||
|
def get_object(self) -> WebAuthnDevice:
|
||||||
|
device: WebAuthnDevice = super().get_object()
|
||||||
|
if device.user != self.request.user:
|
||||||
|
raise Http404
|
||||||
|
return device
|
||||||
|
|
Reference in New Issue