-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor] Moved download
crl-view
to mixin #116
Closes #116
- Loading branch information
1 parent
43d810f
commit eca0b79
Showing
2 changed files
with
20 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
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' | ||
) |