# -*- coding: utf-8 -*- # Copyright (C) 2017 Jan Jancar # # This file is a part of the Django Mailman PGP plugin. # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free # Software Foundation, either version 3 of the License, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # more details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see . from __future__ import absolute_import, unicode_literals from django.contrib.auth.decorators import login_required from django.core.files.base import ContentFile from django.http import HttpResponse from django.shortcuts import render from django.utils.decorators import method_decorator from django.views.generic import FormView from six.moves.urllib.error import HTTPError from django_pgpmailman.decorators import list_view from django_pgpmailman.forms import (ListSignatureSettingsForm, ListEncryptionSettingsForm) from django_pgpmailman.plugin import get_pgp_plugin def pgp_list_index(request): return render(request, 'django_pgpmailman/index.html', {'lists': get_pgp_plugin().lists}) @list_view def pgp_list_summary(request, pgp_list): return render(request, 'django_pgpmailman/list/summary.html', {'pgp_list': pgp_list}) # TODO: proper list owner auth class ListSettings(FormView): properties = None def get_initial(self): result = {} for key in self.properties: result[key] = getattr(self.pgp_list, key, None) return result def get_context_data(self, **kwargs): data = super(ListSettings, self).get_context_data( **kwargs) data['pgp_list'] = self.pgp_list data['mlist'] = self.pgp_list.mlist return data @method_decorator(login_required) def dispatch(self, request, *args, **kwargs): self.pgp_list = get_pgp_plugin().get_list(kwargs['list_id']) return super(ListSettings, self).dispatch(request, *args, **kwargs) class ListSignatureSettingsView(ListSettings): form_class = ListSignatureSettingsForm template_name = 'django_pgpmailman/list/signature_settings.html' properties = ('sign_outgoing', 'strip_original_sig', 'unsigned_msg_action', 'inline_pgp_action', 'expired_sig_action', 'revoked_sig_action', 'invalid_sig_action', 'duplicate_sig_action') def form_valid(self, form): try: pass except HTTPError as e: pass class ListEncryptionSettingsView(ListSettings): form_class = ListEncryptionSettingsForm template_name = 'django_pgpmailman/list/encryption_settings.html' properties = ('nonencrypted_msg_action', 'encrypt_outgoing') def form_valid(self, form): try: pass except HTTPError as e: pass # TODO: proper list owner auth @login_required @list_view def pgp_list_key_management(request, pgp_list): return render(request, 'django_pgpmailman/list/key_management.html', {'pgp_list': pgp_list}) # TODO: proper list owner auth @login_required @list_view def pgp_list_signature_settings(request, pgp_list): return render(request, 'django_pgpmailman/list/signature_settings.html', {'pgp_list': pgp_list}) @list_view def pgp_list_pubkey(request, pgp_list): pubkey = pgp_list.pubkey pubkey_file = ContentFile(str(pubkey)) response = HttpResponse(pubkey_file, 'application/pgp-keys') response['Content-Length'] = pubkey_file.size response[ 'Content-Disposition'] = 'attachment; filename="%s.asc"' % pgp_list.list_id return response