From 62c20b6e675bf4461fd76a03b33ea182ff2be4a5 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 1 Jul 2020 12:26:07 +0200 Subject: [PATCH] admin: add list of all tokens --- .../admin/templates/administration/base.html | 6 ++ .../templates/administration/token/list.html | 83 +++++++++++++++++++ passbook/admin/urls.py | 8 ++ passbook/admin/views/applications.py | 3 - passbook/admin/views/tokens.py | 37 +++++++++ passbook/core/models.py | 2 - 6 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 passbook/admin/templates/administration/token/list.html create mode 100644 passbook/admin/views/tokens.py diff --git a/passbook/admin/templates/administration/base.html b/passbook/admin/templates/administration/base.html index 864c526c5..3ac62fa5b 100644 --- a/passbook/admin/templates/administration/base.html +++ b/passbook/admin/templates/administration/base.html @@ -122,6 +122,12 @@ {% trans 'Certificates' %} +
  • + + {% trans 'Tokens' %} + +
  • diff --git a/passbook/admin/templates/administration/token/list.html b/passbook/admin/templates/administration/token/list.html new file mode 100644 index 000000000..2e03dd18c --- /dev/null +++ b/passbook/admin/templates/administration/token/list.html @@ -0,0 +1,83 @@ +{% extends "administration/base.html" %} + +{% load i18n %} +{% load passbook_utils %} + +{% block content %} +
    +
    +

    + + {% trans 'Tokens' %} +

    +

    {% trans "Tokens are used throughout passbook for Email validation stages, Recovery keys and API access." %}

    +
    +
    +
    + +
    +{% endblock %} diff --git a/passbook/admin/urls.py b/passbook/admin/urls.py index af7e41ec9..a660f02c0 100644 --- a/passbook/admin/urls.py +++ b/passbook/admin/urls.py @@ -17,6 +17,7 @@ from passbook.admin.views import ( stages_bindings, stages_invitations, stages_prompts, + tokens, users, ) @@ -41,6 +42,13 @@ urlpatterns = [ applications.ApplicationDeleteView.as_view(), name="application-delete", ), + # Tokens + path("tokens/", tokens.TokenListView.as_view(), name="tokens"), + path( + "tokens//delete/", + tokens.TokenDeleteView.as_view(), + name="token-delete", + ), # Sources path("sources/", sources.SourceListView.as_view(), name="sources"), path("sources/create/", sources.SourceCreateView.as_view(), name="source-create"), diff --git a/passbook/admin/views/applications.py b/passbook/admin/views/applications.py index 357e1ab2c..8850b8998 100644 --- a/passbook/admin/views/applications.py +++ b/passbook/admin/views/applications.py @@ -24,9 +24,6 @@ class ApplicationListView(LoginRequiredMixin, PermissionListMixin, ListView): paginate_by = 40 template_name = "administration/application/list.html" - def get_queryset(self): - return super().get_queryset().select_subclasses() - class ApplicationCreateView( SuccessMessageMixin, diff --git a/passbook/admin/views/tokens.py b/passbook/admin/views/tokens.py new file mode 100644 index 000000000..58cf70f46 --- /dev/null +++ b/passbook/admin/views/tokens.py @@ -0,0 +1,37 @@ +"""passbook Token administration""" +from django.contrib import messages +from django.contrib.auth.mixins import LoginRequiredMixin +from django.contrib.messages.views import SuccessMessageMixin +from django.urls import reverse_lazy +from django.utils.translation import ugettext as _ +from django.views.generic import DeleteView, ListView +from guardian.mixins import PermissionListMixin, PermissionRequiredMixin + +from passbook.core.models import Token + + +class TokenListView(LoginRequiredMixin, PermissionListMixin, ListView): + """Show list of all tokens""" + + model = Token + permission_required = "passbook_core.view_token" + ordering = "expires" + paginate_by = 40 + template_name = "administration/token/list.html" + + +class TokenDeleteView( + SuccessMessageMixin, LoginRequiredMixin, PermissionRequiredMixin, DeleteView +): + """Delete token""" + + model = Token + permission_required = "passbook_core.delete_token" + + template_name = "generic/delete.html" + success_url = reverse_lazy("passbook_admin:tokens") + success_message = _("Successfully deleted Token") + + def delete(self, request, *args, **kwargs): + messages.success(self.request, self.success_message) + return super().delete(request, *args, **kwargs) diff --git a/passbook/core/models.py b/passbook/core/models.py index 2c8a8930e..a632c8369 100644 --- a/passbook/core/models.py +++ b/passbook/core/models.py @@ -112,8 +112,6 @@ class Application(PolicyBindingModel): meta_description = models.TextField(default="", blank=True) meta_publisher = models.TextField(default="", blank=True) - objects = InheritanceManager() - def get_provider(self) -> Optional[Provider]: """Get casted provider instance""" if not self.provider: