hidden user,password in servers without webappusers
This commit is contained in:
parent
4475b3257e
commit
8f84b4fee9
|
@ -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,
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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',
|
||||
)
|
||||
)
|
Loading…
Reference in a new issue