Univention Bugzilla – Attachment 9012 Details for
Bug 25095
No error message for invalid UCR variable names
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
patch
25095.patch (text/plain), 5.16 KB, created by
Florian Best
on 2017-07-11 14:20:19 CEST
(
hide
)
Description:
patch
Filename:
MIME Type:
Creator:
Florian Best
Created:
2017-07-11 14:20:19 CEST
Size:
5.16 KB
patch
obsolete
>diff --git a/management/univention-management-console-module-ucr/umc/js/ucr.js b/management/univention-management-console-module-ucr/umc/js/ucr.js >index 59fa709..6ec7967 100644 >--- a/management/univention-management-console-module-ucr/umc/js/ucr.js >+++ b/management/univention-management-console-module-ucr/umc/js/ucr.js >@@ -106,24 +106,7 @@ define([ > label: _( 'Save' ), > style: 'float: right', > callback: lang.hitch(this, function() { >- var keyWidget = this._form.getWidget('key'); >- tools.umcpCommand('ucr/validate', {'key': keyWidget.get('value')}).then(lang.hitch(this, function(data) { >- var keyIsValid = data.result; >- if (keyIsValid) { >- // save the UCR variable >- keyWidget.setValid(true); >- this._form.save(); >- this.hide(); >- } else { >- // show invalid UCR variable message >- var invalidMessage = _('A valid key must contain at least one character and can only contain letters, numerals, and "/", ".", ":", "_" and "-".'); >- if (keyWidget.get('value').indexOf(': ') !== -1) { >- invalidMessage = lang.replace('{0}<br>{1}', [_('The sequence ": " in the name of a UCR variable is not allowed.'), invalidMessage]); >- } >- keyWidget.setValid(false, invalidMessage); >- keyWidget.focus(); >- } >- })); >+ this._form.save(); > }) > }, { > //FIXME: Should be much simpler. The key name should be enough >@@ -165,7 +148,10 @@ define([ > this._position(); > this.standby(false); > })); >- this._form.on('saved', lang.hitch(this, function() { >+ this._form.on('saved', lang.hitch(this, function(success) { >+ if (success) { >+ this.hide(); >+ } > this._position(); > this.standby(false); > })); >@@ -173,6 +159,8 @@ define([ > > clearForm: function() { > var emptyValues = {}; >+ this._form.getWidget('key').setValid(true); >+ this._form.getWidget('value').setValid(true); > tools.forIn(this._form.get('value'), function(ikey) { > emptyValues[ikey] = ''; > }); >diff --git a/management/univention-management-console-module-ucr/umc/python/ucr/__init__.py b/management/univention-management-console-module-ucr/umc/python/ucr/__init__.py >index 589063f..5ae5ebd 100644 >--- a/management/univention-management-console-module-ucr/umc/python/ucr/__init__.py >+++ b/management/univention-management-console-module-ucr/umc/python/ucr/__init__.py >@@ -31,6 +31,8 @@ > # /usr/share/common-licenses/AGPL-3; if not, see > # <http://www.gnu.org/licenses/>. > >+from io import BytesIO >+ > from univention.lib.i18n import Translation > from univention.management.console.base import Base, UMC_Error > from univention.management.console.config import ucr >@@ -46,6 +48,18 @@ > _ = Translation('univention-management-console-module-ucr').translate > > >+class UCRKeySanitizer(StringSanitizer): >+ >+ def _sanitize(self, value, name, further_arguments): >+ value = super(UCRKeySanitizer, self)._sanitize(value, name, further_arguments) >+ b = BytesIO() >+ if not validate_key(value, b): >+ error_message = b.getvalue() >+ self.raise_validation_error('%s %s' % (_('A valid UCR variable name must contain at least one character and can only contain letters, numerals, "/", ".", ":", "_" and "-".'), error_message)) >+ return >+ return value >+ >+ > class Instance(Base): > > def init(self): >@@ -88,22 +102,24 @@ def is_readonly(self, key): > return var.get('readonly') in ('yes', '1', 'true') > return False > >+ @sanitize(DictSanitizer({ >+ 'object': DictSanitizer({ >+ 'key': UCRKeySanitizer(required=True), >+ 'value': StringSanitizer(default=''), >+ }) >+ })) > def add(self, request): > # does the same as put > ucr.load() > already_set = set(ucr.keys()) & set(v['object']['key'] for v in request.options) > if already_set: >- raise UMC_Error(_('The UCR variable %r is already set.') % (', '.join(already_set))) >+ raise UMC_Error(_('The UCR variable %s is already set.') % ('", "'.join(already_set))) > > self.put(request) > >- @simple_response >- def validate(self, key): >- return validate_key(key) >- > @sanitize(DictSanitizer({ > 'object': DictSanitizer({ >- 'key': StringSanitizer(required=True), >+ 'key': UCRKeySanitizer(required=True), > 'value': StringSanitizer(default=''), > }) > })) >@@ -112,8 +128,6 @@ def put(self, request): > var = _var['object'] > value = var['value'] or '' > key = var['key'] >- if not validate_key(key): >- raise UMC_Error(_('The UCR variable %r has an invalid name.') % (key,)) > if self.is_readonly(key): > raise UMC_Error(_('The UCR variable %s is read-only and can not be changed!') % (key,)) > arg = ['%s=%s' % (key.encode(), value.encode())] >diff --git a/management/univention-management-console-module-ucr/umc/ucr.xml b/management/univention-management-console-module-ucr/umc/ucr.xml >index 3cb3fc4..1975b21 100644 >--- a/management/univention-management-console-module-ucr/umc/ucr.xml >+++ b/management/univention-management-console-module-ucr/umc/ucr.xml >@@ -9,7 +9,6 @@ > </categories> > <command name="ucr/put" function="put" /> > <command name="ucr/add" function="add" /> >- <command name="ucr/validate" function="validate" /> > <command name="ucr/remove" function="remove" /> > <command name="ucr/get" function="get" /> > <command name="ucr/categories" function="categories" />
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 25095
:
8093
|
8107
|
8113
| 9012