Set mailbox related addresses on creation
This commit is contained in:
parent
ddd8ecf634
commit
056f472ee0
|
@ -76,6 +76,12 @@ class MailboxCreateForm(forms.Form):
|
||||||
strip=False,
|
strip=False,
|
||||||
help_text=_("Enter the same password as before, for verification."),
|
help_text=_("Enter the same password as before, for verification."),
|
||||||
)
|
)
|
||||||
|
addresses = forms.MultipleChoiceField(required=False)
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
addresses = kwargs.pop('addresses')
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.fields['addresses'].choices = [(addr.url, addr.full_address_name) for addr in addresses]
|
||||||
|
|
||||||
def clean_password2(self):
|
def clean_password2(self):
|
||||||
password = self.cleaned_data.get("password")
|
password = self.cleaned_data.get("password")
|
||||||
|
@ -92,6 +98,7 @@ class MailboxCreateForm(forms.Form):
|
||||||
serialized_data = {
|
serialized_data = {
|
||||||
"name": self.cleaned_data["name"],
|
"name": self.cleaned_data["name"],
|
||||||
"password": self.cleaned_data["password2"],
|
"password": self.cleaned_data["password2"],
|
||||||
|
"addresses": self.cleaned_data["addresses"],
|
||||||
}
|
}
|
||||||
return serialized_data
|
return serialized_data
|
||||||
|
|
||||||
|
|
|
@ -339,6 +339,14 @@ class MailboxCreateView(CustomContextMixin, UserTokenRequiredMixin, FormView):
|
||||||
number_of_mailboxes = len(self.orchestra.retrieve_mailbox_list())
|
number_of_mailboxes = len(self.orchestra.retrieve_mailbox_list())
|
||||||
return number_of_mailboxes >= profile.allowed_resources('mailbox')
|
return number_of_mailboxes >= profile.allowed_resources('mailbox')
|
||||||
|
|
||||||
|
def get_form_kwargs(self):
|
||||||
|
kwargs = super().get_form_kwargs()
|
||||||
|
kwargs.update({
|
||||||
|
'addresses': self.orchestra.retrieve_mail_address_list(),
|
||||||
|
})
|
||||||
|
|
||||||
|
return kwargs
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
serialized_data = form.serialize()
|
serialized_data = form.serialize()
|
||||||
status, response = self.orchestra.create_mailbox(serialized_data)
|
status, response = self.orchestra.create_mailbox(serialized_data)
|
||||||
|
@ -347,11 +355,11 @@ class MailboxCreateView(CustomContextMixin, UserTokenRequiredMixin, FormView):
|
||||||
if status == 400:
|
if status == 400:
|
||||||
# handle errors & add to form (they will be rendered)
|
# handle errors & add to form (they will be rendered)
|
||||||
form.add_error(field=None, error=response)
|
form.add_error(field=None, error=response)
|
||||||
return self.form_invalid(form)
|
|
||||||
else:
|
else:
|
||||||
logger.error("{}: {}".format(status, response[:120]))
|
logger.error("{}: {}".format(status, response[:120]))
|
||||||
msg = "Sorry, an error occurred while processing your request ({})".format(status)
|
msg = "Sorry, an error occurred while processing your request ({})".format(status)
|
||||||
form.add_error(field='__all__', error=msg)
|
form.add_error(field='__all__', error=msg)
|
||||||
|
return self.form_invalid(form)
|
||||||
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue