From 0a76f76e797c42d40b198029f8eba114174a9f93 Mon Sep 17 00:00:00 2001 From: jorgepastorr Date: Thu, 24 Aug 2023 12:23:08 +0200 Subject: [PATCH] hidden user,password in servers without webappusers --- orchestra/contrib/webapps/admin.py | 4 +++- orchestra/plugins/forms.py | 18 ++++++++++++++++-- orchestra/settings.py | 9 +++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/orchestra/contrib/webapps/admin.py b/orchestra/contrib/webapps/admin.py index 24bd4948..6cddeec5 100644 --- a/orchestra/contrib/webapps/admin.py +++ b/orchestra/contrib/webapps/admin.py @@ -15,6 +15,7 @@ from orchestra.contrib.systemusers.models import WebappUsers from orchestra.forms.widgets import DynamicHelpTextSelect from orchestra.plugins.admin import SelectPluginAdminMixin, display_plugin_field from orchestra.utils.html import get_on_site_link +from orchestra.settings import NEW_SERVERS from .filters import HasWebsiteListFilter, DetailListFilter from .models import WebApp, WebAppOption @@ -110,7 +111,8 @@ class WebAppAdmin(SelectPluginAdminMixin, AccountAdminMixin, ExtendedModelAdmin) def save_model(self, request, obj, form, change): if not change: user = form.cleaned_data.get('username') - if user: + server = form.cleaned_data.get('target_server') + if user and server.name in NEW_SERVERS: user = WebappUsers( username=form.cleaned_data['username'], account_id=obj.account.pk, diff --git a/orchestra/plugins/forms.py b/orchestra/plugins/forms.py index 16885756..1cbdd84d 100644 --- a/orchestra/plugins/forms.py +++ b/orchestra/plugins/forms.py @@ -7,9 +7,11 @@ from orchestra.forms.widgets import SpanWidget from django.core.exceptions import ValidationError from orchestra.core import validators from orchestra.utils.python import random_ascii -from orchestra.settings import NEW_SERVERS +from orchestra.settings import NEW_SERVERS, WEB_SERVERS from django.utils.translation import gettext_lazy as _ +import textwrap +from orchestra.contrib.orchestration.models import Server class PluginForm(forms.ModelForm): def __init__(self, *args, **kwargs): @@ -21,7 +23,6 @@ class PluginForm(forms.ModelForm): help_text = self.fields[self.plugin_field].help_text self.fields[self.plugin_field].help_text = getattr(self.plugin, 'help_text', help_text) - class PluginDataForm(PluginForm): data = forms.CharField(widget=forms.HiddenInput, required=False) @@ -98,6 +99,7 @@ class ExtendedPluginDataForm(PluginDataForm): widget=forms.PasswordInput, help_text=_("Enter the same password as above, for verification.")) + target_server = forms.ModelChoiceField(queryset=Server.objects.filter(name__in=WEB_SERVERS),) def __init__(self, *args, **kwargs): super(ExtendedPluginDataForm, self).__init__(*args, **kwargs) @@ -107,6 +109,18 @@ class ExtendedPluginDataForm(PluginDataForm): self.fields['password1'].widget = forms.HiddenInput() self.fields['password2'].widget = forms.HiddenInput() + if not self.instance.pk: + self.fields['target_server'].widget.attrs['onChange'] = textwrap.dedent("""\ + field = $(".field-username, .field-password1, .field-password2"); + input = $("#id_username, #id_password1, #id_password2"); + if (%s.includes(this.options[this.selectedIndex].text)) { + field.removeClass("hidden"); + } else { + field.addClass("hidden"); + input.val(""); + };""" % list(NEW_SERVERS) + ) + def clean_username(self): if not self.instance.id: webapp_server = self.cleaned_data.get("target_server") diff --git a/orchestra/settings.py b/orchestra/settings.py index ff311382..3e43573e 100644 --- a/orchestra/settings.py +++ b/orchestra/settings.py @@ -97,3 +97,12 @@ NEW_SERVERS = Setting('NEW_SERVERS', 'web-12.pangea.lan', ) ) + +WEB_SERVERS = Setting('WEBAPPS_SERVERS', ( + 'web.pangea.lan', + 'web-ng', + 'web-11.pangea.lan', + 'web-12.pangea.lan', + 'bookworm', + ) +) \ No newline at end of file