2014-11-09 10:16:07 +00:00
|
|
|
from django.core.exceptions import ValidationError
|
2014-09-26 19:21:09 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
2014-11-24 14:39:41 +00:00
|
|
|
from orchestra import plugins
|
2015-04-07 15:14:49 +00:00
|
|
|
from orchestra.contrib.orchestration import Operation
|
2014-09-26 19:21:09 +00:00
|
|
|
from orchestra.utils.functional import cached
|
2015-09-21 10:28:49 +00:00
|
|
|
from orchestra.utils.python import import_class
|
2014-09-26 19:21:09 +00:00
|
|
|
|
|
|
|
from .. import settings
|
2015-09-21 10:28:49 +00:00
|
|
|
from ..forms import SaaSPasswordForm
|
2014-11-20 15:34:59 +00:00
|
|
|
|
2014-11-24 14:39:41 +00:00
|
|
|
|
2014-09-26 19:21:09 +00:00
|
|
|
class SoftwareService(plugins.Plugin):
|
2015-09-21 10:28:49 +00:00
|
|
|
form = SaaSPasswordForm
|
2015-03-25 15:45:04 +00:00
|
|
|
site_domain = None
|
2015-03-23 15:36:51 +00:00
|
|
|
has_custom_domain = False
|
2014-10-11 12:43:08 +00:00
|
|
|
icon = 'orchestra/icons/apps.png'
|
|
|
|
class_verbose_name = _("Software as a Service")
|
2015-03-23 15:36:51 +00:00
|
|
|
plugin_field = 'service'
|
2014-09-26 19:21:09 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@cached
|
|
|
|
def get_plugins(cls):
|
|
|
|
plugins = []
|
|
|
|
for cls in settings.SAAS_ENABLED_SERVICES:
|
|
|
|
plugins.append(import_class(cls))
|
|
|
|
return plugins
|
|
|
|
|
2015-03-04 21:06:16 +00:00
|
|
|
def get_change_readonly_fileds(cls):
|
2015-03-23 15:36:51 +00:00
|
|
|
fields = super(SoftwareService, cls).get_change_readonly_fileds()
|
2015-03-25 15:45:04 +00:00
|
|
|
return fields + ('name',)
|
2015-03-04 21:06:16 +00:00
|
|
|
|
2015-03-25 15:45:04 +00:00
|
|
|
def get_site_domain(self):
|
2015-09-29 12:35:22 +00:00
|
|
|
context = {
|
|
|
|
'site_name': self.instance.name,
|
|
|
|
'name': self.instance.name,
|
|
|
|
}
|
|
|
|
return self.site_domain % context
|
2014-11-20 15:34:59 +00:00
|
|
|
|
2015-04-02 16:14:55 +00:00
|
|
|
def clean_data(self):
|
|
|
|
data = super(SoftwareService, self).clean_data()
|
|
|
|
if not self.instance.pk:
|
|
|
|
try:
|
|
|
|
log = Operation.execute_action(self.instance, 'validate_creation')[0]
|
|
|
|
except IndexError:
|
|
|
|
pass
|
|
|
|
else:
|
2015-04-20 14:23:10 +00:00
|
|
|
if log.state != log.SUCCESS:
|
|
|
|
raise ValidationError(_("Validate creation execution has failed."))
|
2015-04-02 16:14:55 +00:00
|
|
|
errors = {}
|
|
|
|
if 'user-exists' in log.stdout:
|
|
|
|
errors['name'] = _("User with this username already exists.")
|
2015-04-07 15:14:49 +00:00
|
|
|
if 'email-exists' in log.stdout:
|
2015-04-02 16:14:55 +00:00
|
|
|
errors['email'] = _("User with this email address already exists.")
|
|
|
|
if errors:
|
|
|
|
raise ValidationError(errors)
|
|
|
|
return data
|
|
|
|
|
2015-03-23 15:36:51 +00:00
|
|
|
def save(self):
|
|
|
|
pass
|
2014-09-26 19:21:09 +00:00
|
|
|
|
2015-03-23 15:36:51 +00:00
|
|
|
def delete(self):
|
|
|
|
pass
|
2015-03-26 16:00:30 +00:00
|
|
|
|
|
|
|
def get_related(self):
|
|
|
|
return []
|