From 9b12895faba448b161fdc53552d98bd52498d432 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 19 Feb 2021 19:31:23 +0100 Subject: [PATCH] admin: remove unneeded code --- authentik/admin/views/applications.py | 4 +-- authentik/admin/views/certificate_key_pair.py | 5 +-- .../admin/views/events_notifications_rules.py | 4 +-- .../views/events_notifications_transports.py | 4 +-- authentik/admin/views/flows.py | 4 +-- authentik/admin/views/groups.py | 4 +-- authentik/admin/views/outposts.py | 4 +-- .../views/outposts_service_connections.py | 3 -- authentik/admin/views/policies.py | 3 -- authentik/admin/views/policies_bindings.py | 4 +-- authentik/admin/views/property_mappings.py | 3 -- authentik/admin/views/providers.py | 3 -- authentik/admin/views/sources.py | 3 -- authentik/admin/views/stages.py | 3 -- authentik/admin/views/stages_bindings.py | 4 +-- authentik/admin/views/stages_invitations.py | 2 -- authentik/admin/views/stages_prompts.py | 3 -- authentik/admin/views/users.py | 15 +++------ authentik/admin/views/utils.py | 33 ++----------------- 19 files changed, 15 insertions(+), 93 deletions(-) diff --git a/authentik/admin/views/applications.py b/authentik/admin/views/applications.py index 88e72940c..f80eda369 100644 --- a/authentik/admin/views/applications.py +++ b/authentik/admin/views/applications.py @@ -11,7 +11,7 @@ from django.views.generic import UpdateView from guardian.mixins import PermissionRequiredMixin from guardian.shortcuts import get_objects_for_user -from authentik.admin.views.utils import BackSuccessUrlMixin, DeleteMessageView +from authentik.admin.views.utils import DeleteMessageView from authentik.core.forms.applications import ApplicationForm from authentik.core.models import Application from authentik.lib.views import CreateAssignPermView @@ -19,7 +19,6 @@ from authentik.lib.views import CreateAssignPermView class ApplicationCreateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, @@ -52,7 +51,6 @@ class ApplicationCreateView( class ApplicationUpdateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView, diff --git a/authentik/admin/views/certificate_key_pair.py b/authentik/admin/views/certificate_key_pair.py index 4653cb154..1e2ea400a 100644 --- a/authentik/admin/views/certificate_key_pair.py +++ b/authentik/admin/views/certificate_key_pair.py @@ -10,7 +10,7 @@ from django.views.generic import UpdateView from django.views.generic.edit import FormView from guardian.mixins import PermissionRequiredMixin -from authentik.admin.views.utils import BackSuccessUrlMixin, DeleteMessageView +from authentik.admin.views.utils import DeleteMessageView from authentik.crypto.builder import CertificateBuilder from authentik.crypto.forms import ( CertificateKeyPairForm, @@ -22,7 +22,6 @@ from authentik.lib.views import CreateAssignPermView class CertificateKeyPairCreateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, @@ -40,7 +39,6 @@ class CertificateKeyPairCreateView( class CertificateKeyPairGenerateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, FormView, @@ -68,7 +66,6 @@ class CertificateKeyPairGenerateView( class CertificateKeyPairUpdateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView, diff --git a/authentik/admin/views/events_notifications_rules.py b/authentik/admin/views/events_notifications_rules.py index 7cb2fc390..66577dc40 100644 --- a/authentik/admin/views/events_notifications_rules.py +++ b/authentik/admin/views/events_notifications_rules.py @@ -8,7 +8,7 @@ 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.admin.views.utils import DeleteMessageView from authentik.events.forms import NotificationRuleForm from authentik.events.models import NotificationRule from authentik.lib.views import CreateAssignPermView @@ -16,7 +16,6 @@ from authentik.lib.views import CreateAssignPermView class NotificationRuleCreateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, @@ -33,7 +32,6 @@ class NotificationRuleCreateView( class NotificationRuleUpdateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView, diff --git a/authentik/admin/views/events_notifications_transports.py b/authentik/admin/views/events_notifications_transports.py index d211831ed..a5c4cd990 100644 --- a/authentik/admin/views/events_notifications_transports.py +++ b/authentik/admin/views/events_notifications_transports.py @@ -8,7 +8,7 @@ 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.admin.views.utils import DeleteMessageView from authentik.events.forms import NotificationTransportForm from authentik.events.models import NotificationTransport from authentik.lib.views import CreateAssignPermView @@ -16,7 +16,6 @@ from authentik.lib.views import CreateAssignPermView class NotificationTransportCreateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, @@ -33,7 +32,6 @@ class NotificationTransportCreateView( class NotificationTransportUpdateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView, diff --git a/authentik/admin/views/flows.py b/authentik/admin/views/flows.py index 775316245..9cfa6ffd2 100644 --- a/authentik/admin/views/flows.py +++ b/authentik/admin/views/flows.py @@ -10,7 +10,7 @@ from django.utils.translation import gettext as _ from django.views.generic import DetailView, FormView, UpdateView from guardian.mixins import PermissionRequiredMixin -from authentik.admin.views.utils import BackSuccessUrlMixin, DeleteMessageView +from authentik.admin.views.utils import DeleteMessageView from authentik.flows.exceptions import FlowNonApplicableException from authentik.flows.forms import FlowForm, FlowImportForm from authentik.flows.models import Flow @@ -25,7 +25,6 @@ from authentik.lib.views import CreateAssignPermView, bad_request_message class FlowCreateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, @@ -43,7 +42,6 @@ class FlowCreateView( class FlowUpdateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView, diff --git a/authentik/admin/views/groups.py b/authentik/admin/views/groups.py index 462fd87ba..74a77b5f1 100644 --- a/authentik/admin/views/groups.py +++ b/authentik/admin/views/groups.py @@ -8,7 +8,7 @@ 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.admin.views.utils import DeleteMessageView from authentik.core.forms.groups import GroupForm from authentik.core.models import Group from authentik.lib.views import CreateAssignPermView @@ -16,7 +16,6 @@ from authentik.lib.views import CreateAssignPermView class GroupCreateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, @@ -34,7 +33,6 @@ class GroupCreateView( class GroupUpdateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView, diff --git a/authentik/admin/views/outposts.py b/authentik/admin/views/outposts.py index 5cc7bd8eb..fc160b901 100644 --- a/authentik/admin/views/outposts.py +++ b/authentik/admin/views/outposts.py @@ -11,7 +11,7 @@ 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.admin.views.utils import DeleteMessageView from authentik.lib.views import CreateAssignPermView from authentik.outposts.forms import OutpostForm from authentik.outposts.models import Outpost, OutpostConfig @@ -19,7 +19,6 @@ from authentik.outposts.models import Outpost, OutpostConfig class OutpostCreateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, @@ -43,7 +42,6 @@ class OutpostCreateView( class OutpostUpdateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView, diff --git a/authentik/admin/views/outposts_service_connections.py b/authentik/admin/views/outposts_service_connections.py index 4f2b107ed..442690bed 100644 --- a/authentik/admin/views/outposts_service_connections.py +++ b/authentik/admin/views/outposts_service_connections.py @@ -8,7 +8,6 @@ from django.utils.translation import gettext as _ from guardian.mixins import PermissionRequiredMixin from authentik.admin.views.utils import ( - BackSuccessUrlMixin, DeleteMessageView, InheritanceCreateView, InheritanceUpdateView, @@ -18,7 +17,6 @@ from authentik.outposts.models import OutpostServiceConnection class OutpostServiceConnectionCreateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, InheritanceCreateView, @@ -35,7 +33,6 @@ class OutpostServiceConnectionCreateView( class OutpostServiceConnectionUpdateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, InheritanceUpdateView, diff --git a/authentik/admin/views/policies.py b/authentik/admin/views/policies.py index d4491edf2..bb18a3502 100644 --- a/authentik/admin/views/policies.py +++ b/authentik/admin/views/policies.py @@ -14,7 +14,6 @@ from guardian.mixins import PermissionRequiredMixin from authentik.admin.forms.policies import PolicyTestForm from authentik.admin.views.utils import ( - BackSuccessUrlMixin, DeleteMessageView, InheritanceCreateView, InheritanceUpdateView, @@ -25,7 +24,6 @@ from authentik.policies.process import PolicyProcess, PolicyRequest class PolicyCreateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, InheritanceCreateView, @@ -42,7 +40,6 @@ class PolicyCreateView( class PolicyUpdateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, InheritanceUpdateView, diff --git a/authentik/admin/views/policies_bindings.py b/authentik/admin/views/policies_bindings.py index 3dfd8ca9a..336f0dd64 100644 --- a/authentik/admin/views/policies_bindings.py +++ b/authentik/admin/views/policies_bindings.py @@ -11,7 +11,7 @@ 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.admin.views.utils import DeleteMessageView from authentik.lib.views import CreateAssignPermView from authentik.policies.forms import PolicyBindingForm from authentik.policies.models import PolicyBinding, PolicyBindingModel @@ -19,7 +19,6 @@ from authentik.policies.models import PolicyBinding, PolicyBindingModel class PolicyBindingCreateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, @@ -53,7 +52,6 @@ class PolicyBindingCreateView( class PolicyBindingUpdateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView, diff --git a/authentik/admin/views/property_mappings.py b/authentik/admin/views/property_mappings.py index ca6b2796f..f9b2fc7d7 100644 --- a/authentik/admin/views/property_mappings.py +++ b/authentik/admin/views/property_mappings.py @@ -15,7 +15,6 @@ from guardian.mixins import PermissionRequiredMixin from authentik.admin.forms.policies import PolicyTestForm from authentik.admin.views.utils import ( - BackSuccessUrlMixin, DeleteMessageView, InheritanceCreateView, InheritanceUpdateView, @@ -25,7 +24,6 @@ from authentik.core.models import PropertyMapping class PropertyMappingCreateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, InheritanceCreateView, @@ -41,7 +39,6 @@ class PropertyMappingCreateView( class PropertyMappingUpdateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, InheritanceUpdateView, diff --git a/authentik/admin/views/providers.py b/authentik/admin/views/providers.py index 76eefa839..71394c18a 100644 --- a/authentik/admin/views/providers.py +++ b/authentik/admin/views/providers.py @@ -8,7 +8,6 @@ from django.utils.translation import gettext as _ from guardian.mixins import PermissionRequiredMixin from authentik.admin.views.utils import ( - BackSuccessUrlMixin, DeleteMessageView, InheritanceCreateView, InheritanceUpdateView, @@ -18,7 +17,6 @@ from authentik.core.models import Provider class ProviderCreateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, InheritanceCreateView, @@ -34,7 +32,6 @@ class ProviderCreateView( class ProviderUpdateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, InheritanceUpdateView, diff --git a/authentik/admin/views/sources.py b/authentik/admin/views/sources.py index 7ebe243b8..5bc002ced 100644 --- a/authentik/admin/views/sources.py +++ b/authentik/admin/views/sources.py @@ -8,7 +8,6 @@ from django.utils.translation import gettext as _ from guardian.mixins import PermissionRequiredMixin from authentik.admin.views.utils import ( - BackSuccessUrlMixin, DeleteMessageView, InheritanceCreateView, InheritanceUpdateView, @@ -18,7 +17,6 @@ from authentik.core.models import Source class SourceCreateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, InheritanceCreateView, @@ -34,7 +32,6 @@ class SourceCreateView( class SourceUpdateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, InheritanceUpdateView, diff --git a/authentik/admin/views/stages.py b/authentik/admin/views/stages.py index bb4b190eb..049b591e4 100644 --- a/authentik/admin/views/stages.py +++ b/authentik/admin/views/stages.py @@ -8,7 +8,6 @@ from django.utils.translation import gettext as _ from guardian.mixins import PermissionRequiredMixin from authentik.admin.views.utils import ( - BackSuccessUrlMixin, DeleteMessageView, InheritanceCreateView, InheritanceUpdateView, @@ -18,7 +17,6 @@ from authentik.flows.models import Stage class StageCreateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, InheritanceCreateView, @@ -35,7 +33,6 @@ class StageCreateView( class StageUpdateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, InheritanceUpdateView, diff --git a/authentik/admin/views/stages_bindings.py b/authentik/admin/views/stages_bindings.py index 7aae1d33c..e8376e6b3 100644 --- a/authentik/admin/views/stages_bindings.py +++ b/authentik/admin/views/stages_bindings.py @@ -11,7 +11,7 @@ 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.admin.views.utils import DeleteMessageView from authentik.flows.forms import FlowStageBindingForm from authentik.flows.models import Flow, FlowStageBinding from authentik.lib.views import CreateAssignPermView @@ -19,7 +19,6 @@ from authentik.lib.views import CreateAssignPermView class StageBindingCreateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, @@ -51,7 +50,6 @@ class StageBindingCreateView( class StageBindingUpdateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView, diff --git a/authentik/admin/views/stages_invitations.py b/authentik/admin/views/stages_invitations.py index cf2c4bcca..8c6e0aa81 100644 --- a/authentik/admin/views/stages_invitations.py +++ b/authentik/admin/views/stages_invitations.py @@ -11,7 +11,6 @@ from django.views.generic import ListView from guardian.mixins import PermissionListMixin, PermissionRequiredMixin from authentik.admin.views.utils import ( - BackSuccessUrlMixin, DeleteMessageView, SearchListMixin, UserPaginateListMixin, @@ -39,7 +38,6 @@ class InvitationListView( class InvitationCreateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, diff --git a/authentik/admin/views/stages_prompts.py b/authentik/admin/views/stages_prompts.py index cc59a2ba5..e1f182336 100644 --- a/authentik/admin/views/stages_prompts.py +++ b/authentik/admin/views/stages_prompts.py @@ -10,7 +10,6 @@ from django.views.generic import ListView, UpdateView from guardian.mixins import PermissionListMixin, PermissionRequiredMixin from authentik.admin.views.utils import ( - BackSuccessUrlMixin, DeleteMessageView, SearchListMixin, UserPaginateListMixin, @@ -43,7 +42,6 @@ class PromptListView( class PromptCreateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, @@ -61,7 +59,6 @@ class PromptCreateView( class PromptUpdateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView, diff --git a/authentik/admin/views/users.py b/authentik/admin/views/users.py index daea36fe9..379a8c641 100644 --- a/authentik/admin/views/users.py +++ b/authentik/admin/views/users.py @@ -14,14 +14,13 @@ from django.views.generic import DetailView, UpdateView from guardian.mixins import PermissionRequiredMixin from authentik.admin.forms.users import UserForm -from authentik.admin.views.utils import BackSuccessUrlMixin, DeleteMessageView +from authentik.admin.views.utils import DeleteMessageView from authentik.core.models import Token, User from authentik.lib.views import CreateAssignPermView class UserCreateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, DjangoPermissionRequiredMixin, CreateAssignPermView, @@ -39,7 +38,6 @@ class UserCreateView( class UserUpdateView( SuccessMessageMixin, - BackSuccessUrlMixin, LoginRequiredMixin, PermissionRequiredMixin, UpdateView, @@ -70,9 +68,7 @@ class UserDeleteView(LoginRequiredMixin, PermissionRequiredMixin, DeleteMessageV success_message = _("Successfully deleted User") -class UserDisableView( - LoginRequiredMixin, PermissionRequiredMixin, BackSuccessUrlMixin, DeleteMessageView -): +class UserDisableView(LoginRequiredMixin, PermissionRequiredMixin, DeleteMessageView): """Disable user""" object: User @@ -94,9 +90,7 @@ class UserDisableView( return HttpResponseRedirect(success_url) -class UserEnableView( - LoginRequiredMixin, PermissionRequiredMixin, BackSuccessUrlMixin, DetailView -): +class UserEnableView(LoginRequiredMixin, PermissionRequiredMixin, DetailView): """Enable user""" object: User @@ -111,10 +105,9 @@ class UserEnableView( def get(self, request: HttpRequest, *args, **kwargs): self.object: User = self.get_object() - success_url = self.get_success_url() self.object.is_active = True self.object.save() - return HttpResponseRedirect(success_url) + return HttpResponseRedirect(self.success_url) class UserPasswordResetView(LoginRequiredMixin, PermissionRequiredMixin, DetailView): diff --git a/authentik/admin/views/utils.py b/authentik/admin/views/utils.py index 17c33f434..8146a4607 100644 --- a/authentik/admin/views/utils.py +++ b/authentik/admin/views/utils.py @@ -1,6 +1,5 @@ """authentik admin util views""" -from typing import Any, Optional -from urllib.parse import urlparse +from typing import Any from django.contrib import messages from django.contrib.messages.views import SuccessMessageMixin @@ -8,7 +7,7 @@ from django.contrib.postgres.search import SearchQuery, SearchVector from django.db.models import QuerySet from django.http import Http404 from django.http.request import HttpRequest -from django.views.generic import DeleteView, ListView, UpdateView +from django.views.generic import DeleteView, UpdateView from django.views.generic.list import MultipleObjectMixin from authentik.lib.utils.reflection import all_subclasses @@ -25,17 +24,6 @@ class DeleteMessageView(SuccessMessageMixin, DeleteView): return super().delete(request, *args, **kwargs) -class InheritanceListView(ListView): - """ListView for objects using InheritanceManager""" - - def get_context_data(self, **kwargs): - kwargs["types"] = {x.__name__: x for x in all_subclasses(self.model)} - return super().get_context_data(**kwargs) - - def get_queryset(self): - return super().get_queryset().select_subclasses() - - class SearchListMixin(MultipleObjectMixin): """Accept search query using `search` querystring parameter. Requires self.search_fields, a list of all fields to search. Can contain special lookups like __icontains""" @@ -98,23 +86,6 @@ class InheritanceUpdateView(UpdateView): ) -class BackSuccessUrlMixin: - """Checks if a relative URL has been given as ?back param, and redirect to it. Otherwise - default to self.success_url.""" - - request: HttpRequest - - success_url: Optional[str] - - def get_success_url(self) -> str: - """get_success_url from FormMixin""" - back_param = self.request.GET.get("back") - if back_param: - if not bool(urlparse(back_param).netloc): - return back_param - return str(self.success_url) - - class UserPaginateListMixin: """Get paginate_by value from user's attributes, defaulting to 15"""