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:
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()

View file

@ -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:

View file

@ -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()