View | Details | Raw Unified | Return to bug 25095 | Differences between
and this patch

Collapse All | Expand All

(-)a/management/univention-management-console-module-ucr/umc/js/ucr.js (-19 / +7 lines)
 Lines 106-129   define([ Link Here 
106
				label: _( 'Save' ),
106
				label: _( 'Save' ),
107
				style: 'float: right',
107
				style: 'float: right',
108
				callback: lang.hitch(this, function() {
108
				callback: lang.hitch(this, function() {
109
					var keyWidget = this._form.getWidget('key');
109
					this._form.save();
110
					tools.umcpCommand('ucr/validate', {'key': keyWidget.get('value')}).then(lang.hitch(this, function(data) {
111
						var keyIsValid = data.result;
112
						if (keyIsValid) {
113
							// save the UCR variable
114
							keyWidget.setValid(true);
115
							this._form.save();
116
							this.hide();
117
						} else {
118
							// show invalid UCR variable message
119
							var invalidMessage =  _('A valid key must contain at least one character and can only contain letters, numerals, and "/", ".", ":", "_" and "-".');
120
							if (keyWidget.get('value').indexOf(': ') !== -1) {
121
								invalidMessage = lang.replace('{0}<br>{1}', [_('The sequence ": " in the name of a UCR variable is not allowed.'), invalidMessage]);
122
							}
123
							keyWidget.setValid(false, invalidMessage);
124
							keyWidget.focus();
125
						}
126
					}));
127
				})
110
				})
128
			}, {
111
			}, {
129
				//FIXME: Should be much simpler. The key name should be enough
112
				//FIXME: Should be much simpler. The key name should be enough
 Lines 165-171   define([ Link Here 
165
				this._position();
148
				this._position();
166
				this.standby(false);
149
				this.standby(false);
167
			}));
150
			}));
168
			this._form.on('saved', lang.hitch(this, function() {
151
			this._form.on('saved', lang.hitch(this, function(success) {
152
				if (success) {
153
					this.hide();
154
				}
169
				this._position();
155
				this._position();
170
				this.standby(false);
156
				this.standby(false);
171
			}));
157
			}));
 Lines 173-178   define([ Link Here 
173
159
174
		clearForm: function() {
160
		clearForm: function() {
175
			var emptyValues = {};
161
			var emptyValues = {};
162
			this._form.getWidget('key').setValid(true);
163
			this._form.getWidget('value').setValid(true);
176
			tools.forIn(this._form.get('value'), function(ikey) {
164
			tools.forIn(this._form.get('value'), function(ikey) {
177
				emptyValues[ikey] = '';
165
				emptyValues[ikey] = '';
178
			});
166
			});
(-)a/management/univention-management-console-module-ucr/umc/python/ucr/__init__.py (-8 / +22 lines)
 Lines 31-36    Link Here 
31
# /usr/share/common-licenses/AGPL-3; if not, see
31
# /usr/share/common-licenses/AGPL-3; if not, see
32
# <http://www.gnu.org/licenses/>.
32
# <http://www.gnu.org/licenses/>.
33
33
34
from io import BytesIO
35
34
from univention.lib.i18n import Translation
36
from univention.lib.i18n import Translation
35
from univention.management.console.base import Base, UMC_Error
37
from univention.management.console.base import Base, UMC_Error
36
from univention.management.console.config import ucr
38
from univention.management.console.config import ucr
 Lines 46-51    Link Here 
46
_ = Translation('univention-management-console-module-ucr').translate
48
_ = Translation('univention-management-console-module-ucr').translate
47
49
48
50
51
class UCRKeySanitizer(StringSanitizer):
52
53
	def _sanitize(self, value, name, further_arguments):
54
		value = super(UCRKeySanitizer, self)._sanitize(value, name, further_arguments)
55
		b = BytesIO()
56
		if not validate_key(value, b):
57
			error_message = b.getvalue()
58
			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))
59
			return
60
		return value
61
62
49
class Instance(Base):
63
class Instance(Base):
50
64
51
	def init(self):
65
	def init(self):
 Lines 88-109   def is_readonly(self, key): Link Here 
88
			return var.get('readonly') in ('yes', '1', 'true')
102
			return var.get('readonly') in ('yes', '1', 'true')
89
		return False
103
		return False
90
104
105
	@sanitize(DictSanitizer({
106
		'object': DictSanitizer({
107
			'key': UCRKeySanitizer(required=True),
108
			'value': StringSanitizer(default=''),
109
		})
110
	}))
91
	def add(self, request):
111
	def add(self, request):
92
		# does the same as put
112
		# does the same as put
93
		ucr.load()
113
		ucr.load()
94
		already_set = set(ucr.keys()) & set(v['object']['key'] for v in request.options)
114
		already_set = set(ucr.keys()) & set(v['object']['key'] for v in request.options)
95
		if already_set:
115
		if already_set:
96
			raise UMC_Error(_('The UCR variable %r is already set.') % (', '.join(already_set)))
116
			raise UMC_Error(_('The UCR variable %s is already set.') % ('", "'.join(already_set)))
97
117
98
		self.put(request)
118
		self.put(request)
99
119
100
	@simple_response
101
	def validate(self, key):
102
		return validate_key(key)
103
104
	@sanitize(DictSanitizer({
120
	@sanitize(DictSanitizer({
105
		'object': DictSanitizer({
121
		'object': DictSanitizer({
106
			'key': StringSanitizer(required=True),
122
			'key': UCRKeySanitizer(required=True),
107
			'value': StringSanitizer(default=''),
123
			'value': StringSanitizer(default=''),
108
		})
124
		})
109
	}))
125
	}))
 Lines 112-119   def put(self, request): Link Here 
112
			var = _var['object']
128
			var = _var['object']
113
			value = var['value'] or ''
129
			value = var['value'] or ''
114
			key = var['key']
130
			key = var['key']
115
			if not validate_key(key):
116
				raise UMC_Error(_('The UCR variable %r has an invalid name.') % (key,))
117
			if self.is_readonly(key):
131
			if self.is_readonly(key):
118
				raise UMC_Error(_('The UCR variable %s is read-only and can not be changed!') % (key,))
132
				raise UMC_Error(_('The UCR variable %s is read-only and can not be changed!') % (key,))
119
			arg = ['%s=%s' % (key.encode(), value.encode())]
133
			arg = ['%s=%s' % (key.encode(), value.encode())]
(-)a/management/univention-management-console-module-ucr/umc/ucr.xml (-1 lines)
 Lines 9-15    Link Here 
9
		</categories>
9
		</categories>
10
		<command name="ucr/put" function="put" />
10
		<command name="ucr/put" function="put" />
11
		<command name="ucr/add" function="add" />
11
		<command name="ucr/add" function="add" />
12
		<command name="ucr/validate" function="validate" />
13
		<command name="ucr/remove" function="remove" />
12
		<command name="ucr/remove" function="remove" />
14
		<command name="ucr/get" function="get" />
13
		<command name="ucr/get" function="get" />
15
		<command name="ucr/categories" function="categories" />
14
		<command name="ucr/categories" function="categories" />

Return to bug 25095