admin: add event transport forms

This commit is contained in:
Jens Langhammer 2021-01-12 22:03:33 +01:00
parent 6f56c37d2f
commit cac94792fa
4 changed files with 119 additions and 0 deletions

View File

@ -4,6 +4,7 @@ from django.urls import path
from authentik.admin.views import ( from authentik.admin.views import (
applications, applications,
certificate_key_pair, certificate_key_pair,
events_notifications_transports,
flows, flows,
groups, groups,
outposts, outposts,
@ -352,4 +353,20 @@ urlpatterns = [
tasks.TaskListView.as_view(), tasks.TaskListView.as_view(),
name="tasks", name="tasks",
), ),
# Event Notification Transpots
path(
"events/transports/create/",
events_notifications_transports.NotificationTransportCreateView.as_view(),
name="notification-transport-create",
),
path(
"events/transports/<uuid:pk>/update/",
events_notifications_transports.NotificationTransportUpdateView.as_view(),
name="notification-transport-update",
),
path(
"events/transports/<uuid:pk>/delete/",
events_notifications_transports.NotificationTransportDeleteView.as_view(),
name="notification-transport-delete",
),
] ]

View File

@ -0,0 +1,64 @@
"""authentik NotificationTransport administration"""
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.mixins import (
PermissionRequiredMixin as DjangoPermissionRequiredMixin,
)
from django.contrib.messages.views import SuccessMessageMixin
from django.urls import reverse_lazy
from django.utils.translation import gettext as _
from django.views.generic import UpdateView
from guardian.mixins import PermissionRequiredMixin
from authentik.admin.views.utils import BackSuccessUrlMixin, DeleteMessageView
from authentik.events.forms import NotificationTransportForm
from authentik.events.models import NotificationTransport
from authentik.lib.views import CreateAssignPermView
class NotificationTransportCreateView(
SuccessMessageMixin,
BackSuccessUrlMixin,
LoginRequiredMixin,
DjangoPermissionRequiredMixin,
CreateAssignPermView,
):
"""Create new NotificationTransport"""
model = NotificationTransport
form_class = NotificationTransportForm
permission_required = "authentik_events.add_notificationtransport"
template_name = "generic/create.html"
success_url = reverse_lazy("authentik_core:shell")
success_message = _("Successfully created Notification Transport")
class NotificationTransportUpdateView(
SuccessMessageMixin,
BackSuccessUrlMixin,
LoginRequiredMixin,
PermissionRequiredMixin,
UpdateView,
):
"""Update application"""
model = NotificationTransport
form_class = NotificationTransportForm
permission_required = "authentik_events.change_notificationtransport"
template_name = "generic/update.html"
success_url = reverse_lazy("authentik_core:shell")
success_message = _("Successfully updated Notification Transport")
class NotificationTransportDeleteView(
LoginRequiredMixin, PermissionRequiredMixin, DeleteMessageView
):
"""Delete application"""
model = NotificationTransport
permission_required = "authentik_events.delete_notificationtransport"
template_name = "generic/delete.html"
success_url = reverse_lazy("authentik_core:shell")
success_message = _("Successfully deleted Notification Transport")

32
authentik/events/forms.py Normal file
View File

@ -0,0 +1,32 @@
"""authentik events NotificationTransport forms"""
from django import forms
from django.utils.translation import gettext_lazy as _
from authentik.events.models import NotificationTransport
class NotificationTransportForm(forms.ModelForm):
"""NotificationTransport Form"""
class Meta:
model = NotificationTransport
fields = [
"name",
"mode",
"webhook_url",
]
widgets = {
"name": forms.TextInput(),
"webhook_url": forms.TextInput(),
}
labels = {
"webhook_url": _("Webhook URL"),
}
help_texts = {
"webhook_url": _(
(
"Only required when the Generic or Slack Webhook is used."
)
),
}

View File

@ -276,6 +276,9 @@ class NotificationTransport(models.Model):
except (SMTPException, ConnectionError) as exc: except (SMTPException, ConnectionError) as exc:
raise NotificationTransportError from exc raise NotificationTransportError from exc
def __str__(self) -> str:
return f"Notification Transport {self.name}"
class Meta: class Meta:
verbose_name = _("Notification Transport") verbose_name = _("Notification Transport")
@ -344,6 +347,9 @@ class NotificationTrigger(PolicyBindingModel):
on_delete=models.SET_NULL, on_delete=models.SET_NULL,
) )
def __str__(self) -> str:
return f"Notification Trigger {self.name}"
class Meta: class Meta:
verbose_name = _("Notification Trigger") verbose_name = _("Notification Trigger")