fixes on configuration administration section

This commit is contained in:
Adolfo Gómez García 2019-01-29 13:39:03 +01:00
parent b55c9756e8
commit 0d4f2122c6
3 changed files with 23 additions and 8 deletions

View File

@ -34,16 +34,22 @@ from __future__ import unicode_literals
from uds.core.util.Config import Config as cfgConfig
from uds.REST import Handler, AccessDenied
import six
from uds.REST import Handler
import logging
logger = logging.getLogger(__name__)
# Pair of section/value removed from current UDS version
REMOVED = {
'UDS': ('allowPreferencesAccess', 'customHtmlLogin', 'UDS Theme', 'UDS Theme Enhaced', 'css'),
'Cluster': ('Destination CPU Load', 'Migration CPU Load', 'Migration Free Memory'),
'IPAUTH': ('autoLogin',),
'VMWare': ('minUsableDatastoreGB', 'maxRetriesOnError'),
};
# Enclosed methods under /config path
class Config(Handler):
needs_admin = True # By default, staff is lower level needed
@ -52,6 +58,11 @@ class Config(Handler):
addCrypt = self.is_admin()
for cfg in cfgConfig.enumerate():
# Skip removed configuration values, even if they are in database
logger.debug('Key: %s, val: %s', cfg.section(), cfg.key());
if cfg.key() in REMOVED.get(cfg.section(), ()):
continue
if cfg.isCrypted() is True and addCrypt is False:
continue
# add section if it do not exists
@ -68,7 +79,7 @@ class Config(Handler):
return res
def put(self):
for section, secDict in six.iteritems(self._params):
for key, vals in six.iteritems(secDict):
for section, secDict in self._params.items():
for key, vals in secDict.items():
cfgConfig.update(section, key, vals['value'])
return 'done'

View File

@ -209,10 +209,13 @@ class Config(object):
yield val
@staticmethod
def update(section, key, value):
def update(section, key, value, checkType=False):
# If cfg value does not exists, simply ignore request
try:
cfg = uds.models.Config.objects.filter(section=section, key=key)[0] # @UndefinedVariable
if checkType and cfg.field_type in (Config.READ_FIELD, Config.HIDDEN_FIELD):
return # Skip non writable elements
if cfg.crypt is True:
value = CryptoManager.manager().encrypt(value)
cfg.value = value

View File

@ -50,7 +50,7 @@ from uds.core.util.Config import GlobalConfig
from uds.core import VERSION, VERSION_STAMP
from uds.models import Authenticator
from uds.models import Authenticator, Image
logger = logging.getLogger(__name__)
@ -104,6 +104,7 @@ def udsJs(request):
'os': request.os['OS'],
'csrf_field': CSRF_FIELD,
'csrf': csrf_token,
'image_size': Image.MAX_IMAGE_SIZE,
'urls': {
'changeLang': reverse('set_language'),
'login': reverse('page.login'),