Compare commits

...

7 Commits

7 changed files with 83 additions and 12 deletions

View File

@ -8,6 +8,7 @@ from django.utils.translation import gettext_lazy as _
from orchestra.core import validators
from .models import DatabaseUser, Database
from .settings import DATABASES_SERVERS
class DatabaseUserCreationForm(forms.ModelForm):
@ -22,6 +23,11 @@ class DatabaseUserCreationForm(forms.ModelForm):
model = DatabaseUser
fields = ('username', 'account', 'type')
def __init__(self, *args, **kwargs):
super(DatabaseUserCreationForm, self).__init__(*args, **kwargs)
qsServer = self.fields['target_server'].queryset.filter(name__in=DATABASES_SERVERS)
self.fields['target_server'].queryset = qsServer
def clean_password2(self):
password1 = self.cleaned_data.get("password1")
password2 = self.cleaned_data.get("password2")
@ -74,6 +80,10 @@ class DatabaseCreationForm(DatabaseUserCreationForm):
def __init__(self, *args, **kwargs):
super(DatabaseCreationForm, self).__init__(*args, **kwargs)
account_id = self.initial.get('account', self.initial_account)
qsServer = self.fields['target_server'].queryset.filter(name__in=DATABASES_SERVERS)
self.fields['target_server'].queryset = qsServer
if account_id:
qs = self.fields['user'].queryset.filter(account=account_id).order_by('username')
choices = [ (u.pk, "%s (%s) (%s)" % (u, u.get_type_display(), str(u.target_server.name) )) for u in qs ]

View File

@ -27,3 +27,12 @@ DATABASES_DEFAULT_HOST = Setting('DATABASES_DEFAULT_HOST',
DATABASES_MYSQL_DB_DIR = Setting('DATABASES_MYSQL_DB_DIR',
'/var/lib/mysql',
)
DATABASES_SERVERS = Setting('DATABASES_SERVERS', (
'wpmu',
'mysql.pangea.lan',
'web-11.pangea.lan',
'web-12.pangea.lan',
)
)

View File

@ -198,8 +198,10 @@ class ResourceData(models.Model):
('content_type', 'object_id'),
)
# def __str__(self):
# return "%s: %s" % (self.resource, self.content_object)
def __str__(self):
return "%s: %s" % (self.resource, self.content_object)
return "%s" % (self.content_object)
@property
def unit(self):

View File

@ -10,6 +10,8 @@ from django.utils.translation import gettext_lazy as _
from orchestra.contrib.orchestration import ServiceController
from orchestra.contrib.resources import ServiceMonitor
from orchestra.contrib.resources.models import ResourceData
from orchestra.contrib.saas.models import SaaS
from . import ApacheTrafficByName
from .. import settings
@ -52,11 +54,31 @@ class NextCloudAPIMixin(object):
def create(self, saas):
data = {
'userid': saas.name,
'password': saas.password
'password': saas.password,
}
self.api_post('users', data)
def update_group(self, saas):
data = {
'groupid': saas.account.username
}
try:
self.api_get('groups/%s' % saas.account.username)
except RuntimeError:
self.api_post('groups', data)
self.api_post(f'users/{saas.name}/groups', data)
def update(self, saas):
def update_quota(self, saas):
if hasattr(saas, 'resources') and hasattr(saas.resources, 'nextcloud-disk'):
resource = getattr(saas.resources, 'nextcloud-disk')
quotaValue = f"{resource.allocated}G" if resource.allocated > 0 else "default"
data = {
'key': "quota",
'value': quotaValue
}
self.api_put(f'users/{saas.name}', data)
def update_password(self, saas):
"""
key: email|quota|display|password
value: el valor a modificar.
@ -69,6 +91,12 @@ class NextCloudAPIMixin(object):
'value': saas.password,
}
self.api_put('users/%s' % saas.name, data)
def disable_user(self, saas):
self.api_put('users/%s/disable' % saas.name)
def enable_user(self, saas):
self.api_put('users/%s/enable' % saas.name)
def get_user(self, saas):
"""
@ -112,21 +140,30 @@ class NextCloudController(NextCloudAPIMixin, ServiceController):
try:
self.api_get('users/%s' % saas.name)
except RuntimeError:
if getattr(saas, 'password'):
if getattr(saas, 'password', None):
self.create(saas)
self.update_group(saas)
self.update_quota(saas)
else:
raise
else:
if getattr(saas, 'password'):
self.update(saas)
if getattr(saas, 'password', None):
self.update_password(saas)
else:
self.update_group(saas)
self.update_quota(saas)
def remove(self, saas, server):
self.api_delete('users/%s' % saas.name)
def save(self, saas):
# TODO disable user https://github.com/owncloud/core/issues/12601
def save(self, saas):
self.append(self.update_or_create, saas)
if saas.is_active:
self.enable_user(saas)
else:
self.disable_user(saas)
def delete(self, saas):
self.append(self.remove, saas)

View File

@ -8,7 +8,7 @@ from orchestra.plugins.forms import ExtendedPluginDataForm, PluginDataForm
from ..options import AppOption
from . import AppType
from .php import PHPApp, PHPAppForm, PHPAppSerializer
from orchestra.settings import WEB_SERVERS
class StaticApp(AppType):
name = 'static'
@ -27,6 +27,9 @@ class WebalizerAppform(PluginDataForm):
def __init__(self, *args, **kwargs):
super(WebalizerAppform, self).__init__(*args, **kwargs)
self.fields['sftpuser'].widget = forms.HiddenInput()
if self.instance.id is None:
qsServer = self.fields['target_server'].queryset.filter(name__in=WEB_SERVERS)
self.fields['target_server'].queryset = qsServer
class WebalizerApp(AppType):
name = 'webalizer'

View File

@ -7,9 +7,18 @@ from orchestra.contrib.webapps.models import WebApp
from .utils import normurlpath
from .validators import validate_domain_protocol, validate_server_name
from orchestra.settings import WEB_SERVERS
class WebsiteAdminForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(WebsiteAdminForm, self).__init__(*args, **kwargs)
if self.instance.id is None:
qsServer = self.fields['target_server'].queryset.filter(name__in=WEB_SERVERS)
else:
qsServer = self.fields['target_server'].queryset.filter(id=self.instance.target_server_id)
self.fields['target_server'].queryset = qsServer
def clean(self):
""" Prevent multiples domains on the same protocol """
super(WebsiteAdminForm, self).clean()

View File

@ -99,7 +99,8 @@ NEW_SERVERS = Setting('NEW_SERVERS',
)
)
WEB_SERVERS = Setting('WEBAPPS_SERVERS', (
WEB_SERVERS = Setting('WEB_SERVERS', (
'wpmu',
'web.pangea.lan',
'web-ng',
'web-11.pangea.lan',