|
32 |
# <http://www.gnu.org/licenses/>. |
32 |
# <http://www.gnu.org/licenses/>. |
33 |
|
33 |
|
34 |
from univention.lib.i18n import Translation |
34 |
from univention.lib.i18n import Translation |
35 |
from univention.management.console.modules import Base |
35 |
from univention.management.console.modules import Base, UMC_Error |
|
|
36 |
from univention.management.console.config import ucr |
36 |
from univention.management.console.protocol.definitions import BAD_REQUEST_INVALID_OPTS, SUCCESS |
37 |
from univention.management.console.protocol.definitions import BAD_REQUEST_INVALID_OPTS, SUCCESS |
37 |
|
38 |
|
38 |
from univention.management.console.modules.decorators import simple_response, sanitize |
39 |
from univention.management.console.modules.decorators import simple_response, sanitize |
39 |
from univention.management.console.modules.sanitizers import PatternSanitizer, ChoicesSanitizer |
40 |
from univention.management.console.modules.sanitizers import PatternSanitizer, ChoicesSanitizer |
40 |
|
41 |
|
41 |
import univention.config_registry as ucr |
42 |
from univention.config_registry import handler_set, handler_unset, ConfigRegistry, validate_key |
42 |
from univention.config_registry_info import ConfigRegistryInfo, Variable |
43 |
from univention.config_registry_info import ConfigRegistryInfo, Variable |
43 |
|
44 |
|
44 |
import univention.info_tools as uit |
45 |
import univention.info_tools as uit |
Lines 87-93
def is_readonly( self, key ):
|
Link Here
|
---|
|
87 |
|
88 |
|
88 |
def add( self, request ): |
89 |
def add( self, request ): |
89 |
# does the same as put |
90 |
# does the same as put |
90 |
self.put( request ) |
91 |
ucr.load() |
|
|
92 |
already_set = set(ucr.keys()) & set(v['object']['key'] for v in request.options.values()) |
93 |
if already_set: |
94 |
raise UMC_Error(_('The keys %r are already set.') % (', '.join(already_set)) |
95 |
|
96 |
self.put(request) |
91 |
|
97 |
|
92 |
def put( self, request ): |
98 |
def put( self, request ): |
93 |
message = '' |
99 |
message = '' |
Lines 99-122
def put( self, request ):
|
Link Here
|
---|
|
99 |
var = _var['object'] |
105 |
var = _var['object'] |
100 |
value = var['value'] or '' |
106 |
value = var['value'] or '' |
101 |
key = var['key'] |
107 |
key = var['key'] |
|
|
108 |
if not validate_key(key): |
109 |
raise UMC_Error(_('The UCR variable %r has an invalid name.') % (key,)) |
102 |
if self.is_readonly( key ): |
110 |
if self.is_readonly( key ): |
103 |
success = False |
111 |
raise UMC_Error(_('The UCR variable %s is read-only and can not be changed!') % (key,)) |
104 |
message = _( 'The UCR variable %s is read-only and can not be changed!' ) % key |
|
|
105 |
break |
106 |
arg = [ '%s=%s' % ( key.encode(), value.encode() ) ] |
112 |
arg = [ '%s=%s' % ( key.encode(), value.encode() ) ] |
107 |
ucr.handler_set( arg ) |
113 |
handler_set( arg ) |
108 |
|
114 |
|
109 |
# handle descriptions, type, and categories |
115 |
# handle descriptions, type, and categories |
110 |
if 'descriptions' in var or 'type' in var or 'categories' in var: |
116 |
if 'descriptions' in var or 'type' in var or 'categories' in var: |
111 |
self.__create_variable_info( var ) |
117 |
self.__create_variable_info( var ) |
112 |
except KeyError: |
118 |
except KeyError: |
113 |
# handle the case that neither key nor value are given for an UCR variable entry |
119 |
# handle the case that neither key nor value are given for an UCR variable entry |
114 |
request.status = BAD_REQUEST_INVALID_OPTS |
120 |
raise UMC_Error(_('Invalid UCR variable entry, the properties "key" and "value" need to be specified.'))) |
115 |
self.finished(request.id, False, message = _('Invalid UCR variable entry, the properties "key" and "value" need to be specified.')) |
|
|
116 |
return |
117 |
else: |
118 |
success = False |
119 |
request.status = BAD_REQUEST_INVALID_OPTS |
120 |
|
121 |
|
121 |
self.finished( request.id, success, message ) |
122 |
self.finished( request.id, success, message ) |
122 |
|
123 |
|
Lines 128-138
def remove( self, request ):
|
Link Here
|
---|
|
128 |
self.finished( request.id, False, message ) |
129 |
self.finished( request.id, False, message ) |
129 |
return |
130 |
return |
130 |
|
131 |
|
131 |
ucr.handler_unset( variables ) |
132 |
handler_unset( variables ) |
132 |
self.finished( request.id, True ) |
133 |
self.finished( request.id, True ) |
133 |
|
134 |
|
134 |
def get( self, request ): |
135 |
def get( self, request ): |
135 |
ucrReg = ucr.ConfigRegistry() |
136 |
ucrReg = ConfigRegistry() |
136 |
ucrReg.load() |
137 |
ucrReg.load() |
137 |
ucrInfo = ConfigRegistryInfo( registered_only = False ) |
138 |
ucrInfo = ConfigRegistryInfo( registered_only = False ) |
138 |
|
139 |
|