diff --git a/django_x509/base/admin.py b/django_x509/base/admin.py index 818519b..23a3887 100644 --- a/django_x509/base/admin.py +++ b/django_x509/base/admin.py @@ -1,13 +1,14 @@ from django import forms from django.conf.urls import url from django.contrib.admin import ModelAdmin -from django.shortcuts import render +from django.http import HttpResponse +from django.shortcuts import get_object_or_404, render from django.urls import reverse from django.utils.html import format_html from django.utils.translation import ngettext from django.utils.translation import ugettext_lazy as _ -from .mixin import CrlDownloadMixin +from django_x509 import settings as app_settings class X509Form(forms.ModelForm): @@ -96,7 +97,7 @@ def get_context(self, data, ca_count=0, cert_count=0): return context -class AbstractCaAdmin(BaseAdmin, CrlDownloadMixin): +class AbstractCaAdmin(BaseAdmin): list_filter = ['key_length', 'digest', 'created'] fields = [ 'operation_type', @@ -131,6 +132,16 @@ def get_urls(self): url(r'^x509/ca/(?P[^/]+).crl$', self.crl_view, name='crl') ] + super().get_urls() + def crl_view(self, request, pk): + authenticated = request.user.is_authenticated + authenticated = authenticated() if callable(authenticated) else authenticated + if app_settings.CRL_PROTECTED and not authenticated: + return HttpResponse(_('Forbidden'), status=403, content_type='text/plain') + instance = get_object_or_404(self.model, pk=pk) + return HttpResponse( + instance.crl, status=200, content_type='application/x-pem-file' + ) + def renew_ca(self, request, queryset): if request.POST.get('post'): renewed_rows = 0 diff --git a/django_x509/base/mixin.py b/django_x509/base/mixin.py deleted file mode 100644 index a82afd1..0000000 --- a/django_x509/base/mixin.py +++ /dev/null @@ -1,17 +0,0 @@ -from django.http import HttpResponse -from django.shortcuts import get_object_or_404 -from django.utils.translation import ugettext_lazy as _ - -from django_x509 import settings as app_settings - - -class CrlDownloadMixin: - def crl_view(self, request, pk): - authenticated = request.user.is_authenticated - authenticated = authenticated() if callable(authenticated) else authenticated - if app_settings.CRL_PROTECTED and not authenticated: - return HttpResponse(_('Forbidden'), status=403, content_type='text/plain') - instance = get_object_or_404(self.model, pk=pk) - return HttpResponse( - instance.crl, status=200, content_type='application/x-pem-file' - )