forked from shaba/openuds
Fixed UserInterface new guiField acceptance of values
This commit is contained in:
parent
88c3f9077b
commit
f90f108869
@ -1,4 +0,0 @@
|
||||
Linux:
|
||||
python3-prctl (recommended, but not required in fact)
|
||||
python3-pyqt5
|
||||
|
@ -217,7 +217,7 @@
|
||||
<string>UDS Service Token</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>Administrator user on UDS Server.</p><p>Note: This credential will not be stored on client. Will be used to obtain an unique token for this image.</p></body></html></string>
|
||||
<string><html><head/><body><p>Token of the service on UDS platform</p><p>This token can be obtainend from the service configuration on UDS.</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -268,10 +268,10 @@
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="restrictNet">
|
||||
<property name="toolTip">
|
||||
<string>UDS user with administration rights (Will not be stored on template)</string>
|
||||
<string>Restrict valid detection of network interfaces to this network.</string>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string><html><head/><body><p>Administrator user on UDS Server.</p><p>Note: This credential will not be stored on client. Will be used to obtain an unique token for this image.</p></body></html></string>
|
||||
<string><html><head/><body><p>Restrics valid detection of network interfaces.</p><p>Note: Use this field only in case of several network interfaces, so UDS knows which one is the interface where the user will be connected..</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -37,6 +37,7 @@ import pickle
|
||||
import copy
|
||||
import typing
|
||||
import logging
|
||||
from collections import abc
|
||||
|
||||
from django.utils.translation import get_language, ugettext as _, ugettext_noop
|
||||
|
||||
@ -112,19 +113,30 @@ class gui:
|
||||
# Helpers
|
||||
@staticmethod
|
||||
def convertToChoices(
|
||||
vals: typing.Union[typing.List[str], typing.MutableMapping[str, str]]
|
||||
vals: typing.Union[typing.Iterable[typing.Union[str, typing.Dict[str, str]]], typing.Dict[str, str]]
|
||||
) -> typing.List[typing.Dict[str, str]]:
|
||||
"""
|
||||
Helper to convert from array of strings to the same dict used in choice,
|
||||
Helper to convert from array of strings (or dictionaries) to the same dict used in choice,
|
||||
multichoice, ..
|
||||
"""
|
||||
if not vals:
|
||||
return []
|
||||
if isinstance(vals, (list, tuple)):
|
||||
return [{'id': v, 'text': v} for v in vals]
|
||||
# Helper to convert an item to a dict
|
||||
def choiceFromValue(val: typing.Union[str, typing.Dict[str, str]]) -> typing.Dict[str, str]:
|
||||
if isinstance(val, str):
|
||||
return {'id': val, 'name': val}
|
||||
# Return a deepcopy
|
||||
return copy.deepcopy(val)
|
||||
|
||||
# If is an iterator
|
||||
if isinstance(vals, abc.Iterable):
|
||||
return [choiceFromValue(v) for v in vals]
|
||||
|
||||
# Dictionary
|
||||
return [{'id': str(k), 'text': v} for k, v in vals.items()]
|
||||
# If is a dict
|
||||
if isinstance(vals, abc.Mapping):
|
||||
return [{'id': str(k), 'text': v} for k, v in vals.items()]
|
||||
|
||||
raise ValueError('Invalid type for convertToChoices: {}'.format(type(vals)))
|
||||
|
||||
@staticmethod
|
||||
def convertToList(vals: typing.Iterable[str]) -> typing.List[str]:
|
||||
@ -770,7 +782,8 @@ class gui:
|
||||
|
||||
def __init__(self, **options):
|
||||
super().__init__(**options)
|
||||
if options.get('values') and isinstance(options.get('values'), (dict, list, tuple)):
|
||||
vals = options.get('values')
|
||||
if vals and isinstance(vals, (dict, list, tuple)):
|
||||
options['values'] = gui.convertToChoices(options['values'])
|
||||
self._data['values'] = options.get('values', [])
|
||||
if 'fills' in options:
|
||||
@ -782,7 +795,7 @@ class gui:
|
||||
gui.callbacks[fills['callbackName']] = fnc
|
||||
self._type(gui.InputField.CHOICE_TYPE)
|
||||
|
||||
def setValues(self, values: typing.List[typing.Any]):
|
||||
def setValues(self, values: typing.List[typing.Dict[str, typing.Any]]):
|
||||
"""
|
||||
Set the values for this choice field
|
||||
"""
|
||||
|
@ -173,7 +173,7 @@ class LinuxOsManager(osmanagers.OSManager):
|
||||
pass
|
||||
|
||||
def loginNotified(self, userService, userName=None):
|
||||
if '\\' not in userName:
|
||||
if userName and '\\' not in userName:
|
||||
osmanagers.OSManager.loggedIn(userService, userName)
|
||||
|
||||
def logoutNotified(self, userService, userName=None):
|
||||
|
Loading…
Reference in New Issue
Block a user