2019-11-13 10:42:23 +00:00
|
|
|
from django.utils.html import format_html
|
2019-11-13 10:08:19 +00:00
|
|
|
|
2019-11-13 10:42:23 +00:00
|
|
|
|
|
|
|
class Service:
|
2019-11-13 11:26:35 +00:00
|
|
|
api_name = None
|
2019-11-13 10:42:23 +00:00
|
|
|
verbose_name = None
|
|
|
|
fields = ()
|
2019-11-13 10:08:19 +00:00
|
|
|
|
|
|
|
def __init__(self, data={}):
|
|
|
|
if self.verbose_name is None:
|
2019-11-13 11:26:35 +00:00
|
|
|
self.verbose_name = self.api_name
|
2019-11-13 10:08:19 +00:00
|
|
|
|
|
|
|
self.data = data
|
|
|
|
|
|
|
|
def get(self, key):
|
|
|
|
# retrieve attr of the object and if undefined get raw data
|
|
|
|
return getattr(self, key, self.data.get(key))
|
|
|
|
|
2019-11-13 10:42:23 +00:00
|
|
|
|
2019-11-13 11:27:25 +00:00
|
|
|
class DatabaseService(Service):
|
|
|
|
api_name = 'database'
|
|
|
|
fields = ('name', 'type', 'users')
|
|
|
|
|
|
|
|
|
2019-11-13 10:42:23 +00:00
|
|
|
class MailService(Service):
|
2019-11-13 11:26:35 +00:00
|
|
|
api_name = 'address'
|
2019-11-13 10:42:23 +00:00
|
|
|
verbose_name = 'Mail'
|
|
|
|
fields = ('mail_address', 'aliases', 'type', 'type_detail')
|
|
|
|
|
|
|
|
FORWARD = 'forward'
|
|
|
|
MAILBOX = 'mailbox'
|
|
|
|
|
2019-11-13 10:08:19 +00:00
|
|
|
@property
|
|
|
|
def aliases(self):
|
|
|
|
return [
|
|
|
|
name + '@' + self.data['domain']['name'] for name in self.data['names'][1:]
|
|
|
|
]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def mail_address(self):
|
|
|
|
return self.data['names'][0] + '@' + self.data['domain']['name']
|
|
|
|
|
|
|
|
@property
|
|
|
|
def type(self):
|
|
|
|
if self.data['forward']:
|
|
|
|
return self.FORWARD
|
|
|
|
return self.MAILBOX
|
|
|
|
|
|
|
|
@property
|
|
|
|
def type_detail(self):
|
|
|
|
if self.type == self.FORWARD:
|
|
|
|
return self.data['forward']
|
|
|
|
# TODO(@slamora) retrieve mailbox usage
|
|
|
|
return {'usage': 0, 'total': 213}
|
2019-11-13 10:42:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
class MailinglistService(Service):
|
2019-11-13 11:26:35 +00:00
|
|
|
api_name = 'mailinglist'
|
2019-11-13 10:42:23 +00:00
|
|
|
verbose_name = 'Mailing list'
|
|
|
|
fields = ('name', 'status', 'address_name', 'admin_email', 'configure')
|
|
|
|
|
|
|
|
@property
|
|
|
|
def status(self):
|
|
|
|
# TODO(@slamora): where retrieve if the list is active?
|
|
|
|
return 'active'
|
|
|
|
|
|
|
|
@property
|
|
|
|
def address_name(self):
|
|
|
|
return "{}@{}".format(self.data['address_name'], self.data['address_domain']['name'])
|
|
|
|
|
|
|
|
@property
|
|
|
|
def configure(self):
|
|
|
|
# TODO(@slamora): build mailtran absolute URL
|
|
|
|
return format_html('<a href="#TODO">Mailtrain</a>')
|