diff --git a/orchestra/contrib/musician/forms.py b/orchestra/contrib/musician/forms.py index 068591b7..c55fad6e 100644 --- a/orchestra/contrib/musician/forms.py +++ b/orchestra/contrib/musician/forms.py @@ -16,6 +16,7 @@ from orchestra.contrib.webapps.options import AppOption from orchestra.contrib.webapps.types import AppType from . import api +from .settings import MUSICIAN_EDIT_ENABLE_PHP_OPTIONS class LoginForm(AuthenticationForm): @@ -208,7 +209,7 @@ class SystemUsersChangePasswordForm(ChangePasswordForm): model = SystemUser -class WebappOptionCreateForm(forms.ModelForm): +class WebappOptionForm(forms.ModelForm): OPTIONS_HELP_TEXT = { op.name: force_str(op.help_text) for op in AppOption.get_plugins() @@ -219,13 +220,27 @@ class WebappOptionCreateForm(forms.ModelForm): fields = ("name", "value") def __init__(self, *args, **kwargs): - self.webapp = kwargs.pop('webapp') - super().__init__(*args, **kwargs) + try: + self.webapp = kwargs.pop('webapp') + super().__init__(*args, **kwargs) + except: + super().__init__(*args, **kwargs) + self.webapp = self.instance.webapp + target = 'this.id.replace("name", "value")' self.fields['name'].widget.attrs = DynamicHelpTextSelect(target, self.OPTIONS_HELP_TEXT).attrs + plugin = AppType.get(self.webapp.type) - self.fields['name'].widget.choices = plugin.get_group_options_choices() + choices = list(plugin.get_group_options_choices()) + for grupo, opciones in enumerate(choices): + if isinstance(opciones[1], list): + nueva_lista = [opc for opc in opciones[1] if opc[0] in MUSICIAN_EDIT_ENABLE_PHP_OPTIONS] + choices[grupo] = (opciones[0], nueva_lista) + self.fields['name'].widget.choices = choices + + +class WebappOptionCreateForm(WebappOptionForm): def save(self, commit=True): instance = super().save(commit=False) @@ -234,21 +249,7 @@ class WebappOptionCreateForm(forms.ModelForm): super().save(commit=True) return instance -class WebappOptionUpdateForm(forms.ModelForm): - OPTIONS_HELP_TEXT = { - op.name: force_str(op.help_text) for op in AppOption.get_plugins() - } - - class Meta: - model = WebAppOption - fields = ("name", "value") - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - self.webapp = self.instance.webapp - target = 'this.id.replace("name", "value")' - self.fields['name'].widget.attrs = DynamicHelpTextSelect(target, self.OPTIONS_HELP_TEXT).attrs - plugin = AppType.get(self.webapp.type) - self.fields['name'].widget.choices = plugin.get_group_options_choices() +class WebappOptionUpdateForm(WebappOptionForm): + pass diff --git a/orchestra/contrib/musician/settings.py b/orchestra/contrib/musician/settings.py index fe662567..8872536e 100644 --- a/orchestra/contrib/musician/settings.py +++ b/orchestra/contrib/musician/settings.py @@ -1,3 +1,4 @@ +from orchestra.contrib.settings import Setting from collections import defaultdict from django.conf import settings @@ -46,3 +47,14 @@ URL_SAAS_GITLAB = getsetting("URL_SAAS_GITLAB") URL_SAAS_OWNCLOUD = getsetting("URL_SAAS_OWNCLOUD") URL_SAAS_WORDPRESS = getsetting("URL_SAAS_WORDPRESS") + + +MUSICIAN_EDIT_ENABLE_PHP_OPTIONS = Setting('MUSICIAN_EDIT_ENABLE_PHP_OPTIONS', ( + 'public-root', + 'timeout', + 'max_input_time', + 'max_input_vars', + 'memory_limit', + 'post_max_size', + 'upload_max_filesize', +)) diff --git a/orchestra/contrib/musician/templates/musician/dashboard.html b/orchestra/contrib/musician/templates/musician/dashboard.html index df5a7325..8a3ca505 100644 --- a/orchestra/contrib/musician/templates/musician/dashboard.html +++ b/orchestra/contrib/musician/templates/musician/dashboard.html @@ -50,6 +50,7 @@
{% with domain.websites.0 as website %} {% with website.contents.0 as content %} + {% trans "View DNS records" %}