Fix api.retrieve_mail_address_list()

This commit is contained in:
Santiago L 2021-10-05 10:04:41 +02:00
parent b0366ff1d0
commit ed5460c4b1
4 changed files with 6 additions and 27 deletions

View File

@ -131,32 +131,13 @@ class Orchestra(object):
return self.request("PUT", url=url, data=data) return self.request("PUT", url=url, data=data)
def retrieve_mail_address_list(self, querystring=None): def retrieve_mail_address_list(self, querystring=None):
def get_mailbox_id(value):
mailboxes = value.get('mailboxes')
# forwarded address should not grouped
if len(mailboxes) == 0:
return value.get('name')
return mailboxes[0]['id']
# retrieve mails applying filters (if any) # retrieve mails applying filters (if any)
raw_data = self.retrieve_service_list( raw_data = self.retrieve_service_list(
Address.api_name, Address.api_name,
querystring=querystring, querystring=querystring,
) )
# group addresses with the same mailbox addresses = [Address.new_from_json(data) for data in raw_data]
addresses = []
for key, group in groupby(raw_data, get_mailbox_id):
aliases = []
data = {}
for thing in group:
aliases.append(thing.pop('name'))
data = thing
data['names'] = aliases
addresses.append(Address.new_from_json(data))
# PATCH to include Pangea addresses not shown by orchestra # PATCH to include Pangea addresses not shown by orchestra
# described on issue #4 # described on issue #4

View File

@ -265,10 +265,6 @@ class Address(OrchestraModel):
def full_address_name(self): def full_address_name(self):
return "{}@{}".format(self.name, self.domain['name']) return "{}@{}".format(self.name, self.domain['name'])
@property
def mail_address(self):
return self.data['names'][0] + '@' + self.data['domain']['name']
@property @property
def type(self): def type(self):
if self.data['forward']: if self.data['forward']:

View File

@ -21,11 +21,12 @@
<tbody> <tbody>
{% for obj in object_list %} {% for obj in object_list %}
<tr> <tr>
<td><a href="{% url 'musician:address-update' obj.id %}">{{ obj.mail_address }}</a></td> <td><a href="{% url 'musician:address-update' obj.id %}">{{ obj.full_address_name }}</a></td>
<td>{{ obj.domain.name }}</td> <td>{{ obj.domain.name }}</td>
<td> <td>
{% for mailbox in obj.mailboxes %} {% for mailbox in obj.mailboxes %}
<a href="#TODO-mailbox-detail-{{ mailbox.id }}">{{ mailbox.name }}</a> <a href="#TODO-mailbox-detail-{{ mailbox.id }}">{{ mailbox.name }}</a>
{% if not forloop.last %}<br/> {% endif %}
{% endfor %} {% endfor %}
</td> </td>
<td>{{ obj.forward }}</td> <td>{{ obj.forward }}</td>

View File

@ -6,8 +6,9 @@
<a class="btn-arrow-left" href="{% url 'musician:address-list' %}">{% trans "Go to global" %}</a> <a class="btn-arrow-left" href="{% url 'musician:address-list' %}">{% trans "Go to global" %}</a>
{% endif %} {% endif %}
<h1 class="service-name">{{ service.verbose_name }}{% if active_domain %} <span class="font-weight-light">{% trans "for" <h1 class="service-name">{{ service.verbose_name }}
%} {{ active_domain.name }}</span>{% endif %}</h1> {% if active_domain %}<span class="font-weight-light">{% trans "for" %} {{ active_domain.name }}</span>{% endif %}
</h1>
<p class="service-description">{{ service.description }}</p> <p class="service-description">{{ service.description }}</p>
{% with request.resolver_match.url_name as url_name %} {% with request.resolver_match.url_name as url_name %}