From d7fa52ebf369387aedecd2459c82e8794aff88ce Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 16 Dec 2020 23:10:33 +0100 Subject: [PATCH] admin: remove old admin overview --- authentik/admin/api/version.py | 8 ++-- authentik/admin/api/workers.py | 1 - .../templates/administration/overview.html | 17 -------- authentik/admin/urls.py | 1 - authentik/admin/views/overview.py | 41 +------------------ authentik/policies/api.py | 1 - web/src/interfaces/AdminInterface.ts | 2 +- web/src/routes.ts | 2 +- 8 files changed, 8 insertions(+), 65 deletions(-) delete mode 100644 authentik/admin/templates/administration/overview.html diff --git a/authentik/admin/api/version.py b/authentik/admin/api/version.py index 74a5dfbd0..93c099151 100644 --- a/authentik/admin/api/version.py +++ b/authentik/admin/api/version.py @@ -1,6 +1,7 @@ """authentik administration overview""" from django.core.cache import cache from drf_yasg2.utils import swagger_auto_schema +from packaging.version import parse from rest_framework.fields import SerializerMethodField from rest_framework.mixins import ListModelMixin from rest_framework.permissions import IsAdminUser @@ -8,7 +9,6 @@ from rest_framework.request import Request from rest_framework.response import Response from rest_framework.serializers import Serializer from rest_framework.viewsets import GenericViewSet -from packaging.version import parse from authentik import __version__ from authentik.admin.tasks import VERSION_CACHE_KEY, update_latest_version @@ -33,9 +33,11 @@ class VersionSerializer(Serializer): return __version__ return version_in_cache - def get_outdated(self, instance) -> str: + def get_outdated(self, instance) -> bool: """Check if we're running the latest version""" - return parse(self.get_version_current(instance)) < parse(self.get_version_latest(instance)) + return parse(self.get_version_current(instance)) < parse( + self.get_version_latest(instance) + ) def create(self, request: Request) -> Response: raise NotImplementedError diff --git a/authentik/admin/api/workers.py b/authentik/admin/api/workers.py index 334222738..48bf248a7 100644 --- a/authentik/admin/api/workers.py +++ b/authentik/admin/api/workers.py @@ -6,7 +6,6 @@ from rest_framework.response import Response from rest_framework.serializers import Serializer from rest_framework.viewsets import GenericViewSet -from authentik import __version__ from authentik.root.celery import CELERY_APP diff --git a/authentik/admin/templates/administration/overview.html b/authentik/admin/templates/administration/overview.html deleted file mode 100644 index 421619c2b..000000000 --- a/authentik/admin/templates/administration/overview.html +++ /dev/null @@ -1,17 +0,0 @@ -{% extends "administration/base.html" %} - -{% load i18n %} -{% load static %} - -{% block content %} -
-
-

{% trans 'System Overview' %}

-
-
-
- -
-{% endblock %} diff --git a/authentik/admin/urls.py b/authentik/admin/urls.py index ecd81d8d6..afcce4cc9 100644 --- a/authentik/admin/urls.py +++ b/authentik/admin/urls.py @@ -34,7 +34,6 @@ urlpatterns = [ overview.PolicyCacheClearView.as_view(), name="overview-clear-policy-cache", ), - path("overview/", overview.AdministrationOverviewView.as_view(), name="overview"), # Applications path( "applications/", applications.ApplicationListView.as_view(), name="applications" diff --git a/authentik/admin/views/overview.py b/authentik/admin/views/overview.py index bded396d8..6447279e5 100644 --- a/authentik/admin/views/overview.py +++ b/authentik/admin/views/overview.py @@ -1,58 +1,19 @@ """authentik administration overview""" -from typing import Union - -from django.conf import settings from django.contrib.messages.views import SuccessMessageMixin from django.core.cache import cache from django.http.request import HttpRequest from django.http.response import HttpResponse from django.urls import reverse_lazy from django.utils.translation import gettext as _ -from django.views.generic import FormView, TemplateView -from packaging.version import LegacyVersion, Version, parse +from django.views.generic import FormView from structlog import get_logger -from authentik import __version__ from authentik.admin.forms.overview import FlowCacheClearForm, PolicyCacheClearForm from authentik.admin.mixins import AdminRequiredMixin -from authentik.admin.tasks import VERSION_CACHE_KEY, update_latest_version -from authentik.core.models import Provider, User -from authentik.policies.models import Policy LOGGER = get_logger() -class AdministrationOverviewView(AdminRequiredMixin, TemplateView): - """Overview View""" - - template_name = "administration/overview.html" - - def get_latest_version(self) -> Union[LegacyVersion, Version]: - """Get latest version from cache""" - version_in_cache = cache.get(VERSION_CACHE_KEY) - if not version_in_cache: - if not settings.DEBUG: - update_latest_version.delay() - return parse(__version__) - return parse(version_in_cache) - - def get_context_data(self, **kwargs): - kwargs["policy_count"] = len(Policy.objects.all()) - kwargs["user_count"] = len(User.objects.all()) - 1 # Remove anonymous user - kwargs["provider_count"] = len(Provider.objects.all()) - kwargs["version"] = parse(__version__) - kwargs["version_latest"] = self.get_latest_version() - kwargs["providers_without_application"] = Provider.objects.filter( - application=None - ) - kwargs["policies_without_binding"] = len( - Policy.objects.filter(bindings__isnull=True, promptstage__isnull=True) - ) - kwargs["cached_policies"] = len(cache.keys("policy_*")) - kwargs["cached_flows"] = len(cache.keys("flow_*")) - return super().get_context_data(**kwargs) - - class PolicyCacheClearView(AdminRequiredMixin, SuccessMessageMixin, FormView): """View to clear Policy cache""" diff --git a/authentik/policies/api.py b/authentik/policies/api.py index 65533cf13..99e51dc58 100644 --- a/authentik/policies/api.py +++ b/authentik/policies/api.py @@ -1,7 +1,6 @@ """policy API Views""" from django.core.cache import cache from django.core.exceptions import ObjectDoesNotExist -from drf_yasg2.utils import swagger_auto_schema from rest_framework.mixins import ListModelMixin from rest_framework.request import Request from rest_framework.response import Response diff --git a/web/src/interfaces/AdminInterface.ts b/web/src/interfaces/AdminInterface.ts index 5614d7544..6730d985b 100644 --- a/web/src/interfaces/AdminInterface.ts +++ b/web/src/interfaces/AdminInterface.ts @@ -7,7 +7,7 @@ import { Interface } from "./Interface"; export const SIDEBAR_ITEMS: SidebarItem[] = [ new SidebarItem("Library", "/library/"), new SidebarItem("Monitor").children( - new SidebarItem("Overview", "/administration/overview-ng/"), + new SidebarItem("Overview", "/administration/overview/"), new SidebarItem("System Tasks", "/administration/tasks/"), new SidebarItem("Events", "/audit/audit"), ).when((): Promise => { diff --git a/web/src/routes.ts b/web/src/routes.ts index 9c1620fde..5df10adfd 100644 --- a/web/src/routes.ts +++ b/web/src/routes.ts @@ -13,7 +13,7 @@ export const ROUTES: Route[] = [ new Route(new RegExp("^/$")).redirect("/library/"), new Route(new RegExp("^#.*")).redirect("/library/"), new Route(new RegExp("^/library/$"), html``), - new Route(new RegExp("^/administration/overview-ng/$"), html``), + new Route(new RegExp("^/administration/overview/$"), html``), new Route(new RegExp("^/applications/$"), html``), new Route(new RegExp(`^/applications/(?${SLUG_REGEX})/$`)).then((args) => { return html``;