From 38c9f74b7b526bc5596eb2d87f78fce975a2cf71 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 23 Feb 2024 19:17:56 +0100 Subject: [PATCH] add organizations dids without user --- idhub/admin/forms.py | 11 +++++++---- idhub/admin/views.py | 7 +------ idhub/models.py | 5 ++--- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/idhub/admin/forms.py b/idhub/admin/forms.py index 29ce073..f9ceecc 100644 --- a/idhub/admin/forms.py +++ b/idhub/admin/forms.py @@ -75,6 +75,10 @@ class EncryptionKeyForm(forms.Form): if commit: cache.set("KEY_DIDS", self._key, None) + if not DID.objects.exists(): + did = DID.objects.create(label='Default', type=DID.Types.WEB) + did.set_did() + did.save() return @@ -155,9 +159,8 @@ class ImportForm(forms.Form): self.rows = {} self.properties = {} self.users = [] - self.user = kwargs.pop('user', None) super().__init__(*args, **kwargs) - dids = DID.objects.filter(user=self.user) + dids = DID.objects.filter(user__isnull=True) self.fields['did'].choices = [ (x.did, x.label) for x in dids.filter(eidas1=False) ] @@ -176,7 +179,7 @@ class ImportForm(forms.Form): def clean(self): data = self.cleaned_data["did"] did = DID.objects.filter( - user=self.user, + user__isnull=True, did=data ) @@ -188,7 +191,7 @@ class ImportForm(forms.Form): eidas1 = self.cleaned_data.get('eidas1') if eidas1: self._eidas1 = DID.objects.filter( - user=self.user, + user__isnull=True, eidas1=True, did=eidas1 ).first() diff --git a/idhub/admin/views.py b/idhub/admin/views.py index ad907a6..1c5aaa4 100644 --- a/idhub/admin/views.py +++ b/idhub/admin/views.py @@ -759,7 +759,7 @@ class DidsView(Credentials, SingleTableView): def get_context_data(self, **kwargs): queryset = kwargs.pop('object_list', None) - dids = DID.objects.filter(user=self.request.user) + dids = DID.objects.filter(user__isnull=True) if queryset is None: self.object_list = dids.all() @@ -1062,11 +1062,6 @@ class ImportAddView(NotifyActivateUserByEmail, ImportExport, FormView): form_class = ImportForm success_url = reverse_lazy('idhub:admin_import') - def get_form_kwargs(self): - kwargs = super().get_form_kwargs() - kwargs['user'] = self.request.user - return kwargs - def form_valid(self, form): creds = form.save() if creds: diff --git a/idhub/models.py b/idhub/models.py index 8db241c..6b9d0e4 100644 --- a/idhub/models.py +++ b/idhub/models.py @@ -420,8 +420,8 @@ class Event(models.Model): class DID(models.Model): class Types(models.IntegerChoices): - KEY = 1, "Key" - WEB = 2, "Web" + WEB = 1, "Web" + KEY = 2, "Key" type = models.PositiveSmallIntegerField( _("Type"), choices=Types.choices, @@ -454,7 +454,6 @@ class DID(models.Model): return user.decrypt_data(self.key_material) def set_key_material(self, value): - # import pdb; pdb.set_trace() user = self.user or self.get_organization() if not user.encrypted_sensitive_data: user.set_encrypted_sensitive_data()