hidden user,password in servers without webappusers

This commit is contained in:
jorgepastorr 2023-08-24 12:23:08 +02:00 committed by Marc Aymerich
parent db3ec91fc7
commit 0a76f76e79
3 changed files with 28 additions and 3 deletions

View File

@ -15,6 +15,7 @@ from orchestra.contrib.systemusers.models import WebappUsers
from orchestra.forms.widgets import DynamicHelpTextSelect from orchestra.forms.widgets import DynamicHelpTextSelect
from orchestra.plugins.admin import SelectPluginAdminMixin, display_plugin_field from orchestra.plugins.admin import SelectPluginAdminMixin, display_plugin_field
from orchestra.utils.html import get_on_site_link from orchestra.utils.html import get_on_site_link
from orchestra.settings import NEW_SERVERS
from .filters import HasWebsiteListFilter, DetailListFilter from .filters import HasWebsiteListFilter, DetailListFilter
from .models import WebApp, WebAppOption from .models import WebApp, WebAppOption
@ -110,7 +111,8 @@ class WebAppAdmin(SelectPluginAdminMixin, AccountAdminMixin, ExtendedModelAdmin)
def save_model(self, request, obj, form, change): def save_model(self, request, obj, form, change):
if not change: if not change:
user = form.cleaned_data.get('username') 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( user = WebappUsers(
username=form.cleaned_data['username'], username=form.cleaned_data['username'],
account_id=obj.account.pk, account_id=obj.account.pk,

View File

@ -7,9 +7,11 @@ from orchestra.forms.widgets import SpanWidget
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from orchestra.core import validators from orchestra.core import validators
from orchestra.utils.python import random_ascii 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 _ from django.utils.translation import gettext_lazy as _
import textwrap
from orchestra.contrib.orchestration.models import Server
class PluginForm(forms.ModelForm): class PluginForm(forms.ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -21,7 +23,6 @@ class PluginForm(forms.ModelForm):
help_text = self.fields[self.plugin_field].help_text help_text = self.fields[self.plugin_field].help_text
self.fields[self.plugin_field].help_text = getattr(self.plugin, 'help_text', help_text) self.fields[self.plugin_field].help_text = getattr(self.plugin, 'help_text', help_text)
class PluginDataForm(PluginForm): class PluginDataForm(PluginForm):
data = forms.CharField(widget=forms.HiddenInput, required=False) data = forms.CharField(widget=forms.HiddenInput, required=False)
@ -98,6 +99,7 @@ class ExtendedPluginDataForm(PluginDataForm):
widget=forms.PasswordInput, widget=forms.PasswordInput,
help_text=_("Enter the same password as above, for verification.")) 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): def __init__(self, *args, **kwargs):
super(ExtendedPluginDataForm, self).__init__(*args, **kwargs) super(ExtendedPluginDataForm, self).__init__(*args, **kwargs)
@ -107,6 +109,18 @@ class ExtendedPluginDataForm(PluginDataForm):
self.fields['password1'].widget = forms.HiddenInput() self.fields['password1'].widget = forms.HiddenInput()
self.fields['password2'].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): def clean_username(self):
if not self.instance.id: if not self.instance.id:
webapp_server = self.cleaned_data.get("target_server") webapp_server = self.cleaned_data.get("target_server")

View File

@ -97,3 +97,12 @@ NEW_SERVERS = Setting('NEW_SERVERS',
'web-12.pangea.lan', 'web-12.pangea.lan',
) )
) )
WEB_SERVERS = Setting('WEBAPPS_SERVERS', (
'web.pangea.lan',
'web-ng',
'web-11.pangea.lan',
'web-12.pangea.lan',
'bookworm',
)
)