From: Magnus Hagander Date: Mon, 2 Jun 2025 15:42:46 +0000 (+0200) Subject: Filter list of domains to those with permissions X-Git-Url: http://waps.l3s.uni-hannover.de/gitweb/queryCache.php?a=commitdiff_plain;h=6167e245b1066a40eb9ad695ae3f9acc0fa74a30;p=pgmailmgr.git Filter list of domains to those with permissions --- diff --git a/pgmailmgr/mailmgr/forms.py b/pgmailmgr/mailmgr/forms.py index 97df6a5..da7b8c7 100644 --- a/pgmailmgr/mailmgr/forms.py +++ b/pgmailmgr/mailmgr/forms.py @@ -62,6 +62,8 @@ class VirtualUserForm(forms.ModelForm): self.fields['account'] = forms.CharField(max_length=200, widget=AccountEmailWidget(instance.account), required=False) + if not user.is_superuser: + self.fields['local_domain'].queryset = LocalDomain.objects.only('domain_name').filter(userpermissions__user=user).distinct() if self.instance.pk: self.fields['local_domain'].disabled = True @@ -154,6 +156,9 @@ class ForwarderForm(forms.ModelForm): super(ForwarderForm, self).__init__(data=data, instance=instance) self.user = user + if not user.is_superuser: + self.fields['local_domain'].queryset = LocalDomain.objects.only('domain_name').filter(userpermissions__user=user).distinct() + def clean_local_domain(self): if not self.instance.pk: return self.cleaned_data['local_domain']