diff --git a/app/pgp/forms.py b/app/pgp/forms.py index d8c0b58170edf154204544d6f453716affb83dc6..0329fce296a6d6b1fc17febd5460ced8f9261f91 100644 --- a/app/pgp/forms.py +++ b/app/pgp/forms.py @@ -4,6 +4,7 @@ from . import models class PublicKeyForm(forms.ModelForm): public = forms.BooleanField(required=False) + index = forms.BooleanField(required=False) class Meta: model = models.PublicKey diff --git a/app/pgp/migrations/0004_auto_20210311_2124.py b/app/pgp/migrations/0004_auto_20210311_2124.py new file mode 100644 index 0000000000000000000000000000000000000000..a85cfd1df1e0a57fec9414e094ba902a175c5e82 --- /dev/null +++ b/app/pgp/migrations/0004_auto_20210311_2124.py @@ -0,0 +1,17 @@ +# Generated by Django 3.1.3 on 2021-03-11 21:24 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('pgp', '0003_publickey_wkdid'), + ] + + operations = [ + migrations.AlterModelOptions( + name='publickey', + options={'permissions': [('list_publickey', 'Show public key in listing')]}, + ), + ] diff --git a/app/pgp/models.py b/app/pgp/models.py index df1890c6e25647636ecd8b4ac7832e6b4663daa1..878ac7967866cab09a1e9f2f0743653c6d573ed0 100644 --- a/app/pgp/models.py +++ b/app/pgp/models.py @@ -16,6 +16,11 @@ class PublicKey(models.Model): keyid = models.CharField(max_length=40, null=True, blank=True) wkdid = models.CharField(max_length=32, null=True, blank=True) + class Meta: + permissions = [ + ('list_publickey', 'Show public key in listing') + ] + def __init__(self, *args, **kwds): super().__init__(*args, **kwds) self.decoded = None diff --git a/app/pgp/views.py b/app/pgp/views.py index c95ed381b878949223750d7901bde82af6fab09b..3c87a9d1d3cc1493dd09b41200681b5e53e7061e 100644 --- a/app/pgp/views.py +++ b/app/pgp/views.py @@ -14,11 +14,11 @@ from django import template class PublicKeyListView(PermissionListMixin, ListView): model = models.PublicKey - permission_required = ['view_publickey'] + permission_required = ['view_publickey', 'list_publickey'] class PublicKeyDetailView(PermissionRequiredMixin, DetailView): model = models.PublicKey - permission_required = ['view_publickey'] + permission_required = ['view_publickey', 'list_publickey'] class PublicKeyFingerprintDetailView(PermissionRequiredMixin, DetailView): @@ -56,9 +56,15 @@ class PublicKeyCreateView(PermissionRequiredMixin, CreateView): def form_valid(self, form): resp = super().form_valid(form) assign_perm('view_publickey', self.request.user, self.object) + assign_perm('list_publickey', self.request.user, self.object) assign_perm('change_publickey', self.request.user, self.object) + if form.cleaned_data["public"]: any_user = Group.objects.get(name="any-user") assign_perm('view_publickey', any_user, self.object) + if form.cleaned_data["index"]: + any_user = Group.objects.get(name="any-user") + assign_perm('list_publickey', any_user, self.object) + return resp