From 22881eae6f85f9bff9b1f05d7a59ce3f98431483 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 2 Apr 2021 07:32:10 +0200 Subject: Forms: fix permissions evaluation on field options --- ishtar_common/forms.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'ishtar_common/forms.py') diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index f5ddee48e..bc74001dc 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -672,15 +672,26 @@ class IshtarForm(forms.Form, BSForm): self.fields[site_key].label = profile.get_site_label( self.SITE_KEYS[site_key] ) - for field_name, permissions, options in self.OPTIONS_PERMISSIONS: - if field_name not in self.fields or not getattr(self, "user", None): - continue - if not [ - True for permission in permissions if self.user.has_perm(permission) - ]: - continue - for option, value in options.items(): - setattr(self.fields[field_name].widget, option, value) + user = getattr(self, "user", None) + ishtar_user = None + if user: + try: + ishtar_user = models.IshtarUser.objects.get(pk=user.pk) + except models.IshtarUser.DoesNotExist: + pass + if ishtar_user: + for field_name, permissions, options in self.OPTIONS_PERMISSIONS: + if field_name not in self.fields: + continue + + if not any( + True + for permission in permissions + if ishtar_user.has_perm(permission) + ): + continue + for option, value in options.items(): + setattr(self.fields[field_name].widget, option, value) self._post_init() def _init_type(self, field): -- cgit v1.2.3