add organizations dids without user

This commit is contained in:
Cayo Puigdefabregas 2024-02-23 19:17:56 +01:00
parent 8191b1aaee
commit 38c9f74b7b
3 changed files with 10 additions and 13 deletions

View File

@ -75,6 +75,10 @@ class EncryptionKeyForm(forms.Form):
if commit: if commit:
cache.set("KEY_DIDS", self._key, None) 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 return
@ -155,9 +159,8 @@ class ImportForm(forms.Form):
self.rows = {} self.rows = {}
self.properties = {} self.properties = {}
self.users = [] self.users = []
self.user = kwargs.pop('user', None)
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
dids = DID.objects.filter(user=self.user) dids = DID.objects.filter(user__isnull=True)
self.fields['did'].choices = [ self.fields['did'].choices = [
(x.did, x.label) for x in dids.filter(eidas1=False) (x.did, x.label) for x in dids.filter(eidas1=False)
] ]
@ -176,7 +179,7 @@ class ImportForm(forms.Form):
def clean(self): def clean(self):
data = self.cleaned_data["did"] data = self.cleaned_data["did"]
did = DID.objects.filter( did = DID.objects.filter(
user=self.user, user__isnull=True,
did=data did=data
) )
@ -188,7 +191,7 @@ class ImportForm(forms.Form):
eidas1 = self.cleaned_data.get('eidas1') eidas1 = self.cleaned_data.get('eidas1')
if eidas1: if eidas1:
self._eidas1 = DID.objects.filter( self._eidas1 = DID.objects.filter(
user=self.user, user__isnull=True,
eidas1=True, eidas1=True,
did=eidas1 did=eidas1
).first() ).first()

View File

@ -759,7 +759,7 @@ class DidsView(Credentials, SingleTableView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
queryset = kwargs.pop('object_list', None) 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: if queryset is None:
self.object_list = dids.all() self.object_list = dids.all()
@ -1062,11 +1062,6 @@ class ImportAddView(NotifyActivateUserByEmail, ImportExport, FormView):
form_class = ImportForm form_class = ImportForm
success_url = reverse_lazy('idhub:admin_import') 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): def form_valid(self, form):
creds = form.save() creds = form.save()
if creds: if creds:

View File

@ -420,8 +420,8 @@ class Event(models.Model):
class DID(models.Model): class DID(models.Model):
class Types(models.IntegerChoices): class Types(models.IntegerChoices):
KEY = 1, "Key" WEB = 1, "Web"
WEB = 2, "Web" KEY = 2, "Key"
type = models.PositiveSmallIntegerField( type = models.PositiveSmallIntegerField(
_("Type"), _("Type"),
choices=Types.choices, choices=Types.choices,
@ -454,7 +454,6 @@ class DID(models.Model):
return user.decrypt_data(self.key_material) return user.decrypt_data(self.key_material)
def set_key_material(self, value): def set_key_material(self, value):
# import pdb; pdb.set_trace()
user = self.user or self.get_organization() user = self.user or self.get_organization()
if not user.encrypted_sensitive_data: if not user.encrypted_sensitive_data:
user.set_encrypted_sensitive_data() user.set_encrypted_sensitive_data()