comparison src/memory/memory.py @ 641:49587e170f53

core: added the security_limit to setParam - params with a security greater than security_limit can not be modified - special value: security_limit < 0 disable the check (all params can be modified)
author souliane <souliane@mailoo.org>
date Sat, 07 Sep 2013 02:03:17 +0200
parents 99eee75ec1b7
children e07a03d52321
comparison
equal deleted inserted replaced
640:8211b462af6b 641:49587e170f53
390 """Filter with security level. 390 """Filter with security level.
391 @return: True is this param must be filtered""" 391 @return: True is this param must be filtered"""
392 if security_limit < 0: 392 if security_limit < 0:
393 return False 393 return False
394 if not node.hasAttribute('security'): 394 if not node.hasAttribute('security'):
395 debug("filtered param: %s (no security set)" 395 #debug("filtered param: %s (no security set)"
396 % node.getAttribute("name")) 396 # % node.getAttribute("name"))
397 return True 397 return True
398 if int(node.getAttribute('security')) > security_limit: 398 if int(node.getAttribute('security')) > security_limit:
399 debug("filtered param: %s (security level > %i)" 399 #debug("filtered param: %s (security level > %i)"
400 % (node.getAttribute("name"), security_limit)) 400 # % (node.getAttribute("name"), security_limit))
401 return True 401 return True
402 return False 402 return False
403 403
404 # init the result document 404 # init the result document
405 prof_xml = minidom.parseString('<params/>') 405 prof_xml = minidom.parseString('<params/>')
543 name = cat.getAttribute("name") 543 name = cat.getAttribute("name")
544 if name not in categories: 544 if name not in categories:
545 categories.append(cat.getAttribute("name")) 545 categories.append(cat.getAttribute("name"))
546 return categories 546 return categories
547 547
548 def setParam(self, name, value, category, profile_key='@NONE@'): 548 def setParam(self, name, value, category, security_limit=-1, profile_key='@NONE@'):
549 """Set a parameter, return None if the parameter is not in param xml""" 549 """Set a parameter, return None if the parameter is not in param xml"""
550 #TODO: use different behaviour depending of the data type (e.g. password encrypted) 550 #TODO: use different behaviour depending of the data type (e.g. password encrypted)
551 if profile_key != "@NONE@": 551 if profile_key != "@NONE@":
552 profile = self.getProfileName(profile_key) 552 profile = self.getProfileName(profile_key)
553 if not profile: 553 if not profile:
554 error(_('Trying to set parameter for an unknown profile')) 554 error(_('Trying to set parameter for an unknown profile'))
555 return # TODO: throw an error 555 return # TODO: throw an error
556 556
557 node = self.__getParamNode(name, category, '@ALL@') 557 node = self.__getParamNode(name, category, '@ALL@')
558 if not node: 558 if not node:
559 error(_('Requesting an unknown parameter (%(category)s/%(name)s)') % {'category': category, 'name': name}) 559 error(_('Requesting an unknown parameter (%(category)s/%(name)s)')
560 % {'category': category, 'name': name})
560 return 561 return
562
563 if security_limit >= 0:
564 abort = True
565 if node[1].hasAttribute("security"):
566 if int(node[1].getAttribute("security")) <= security_limit:
567 abort = False
568 if abort:
569 warning(_("Trying to set parameter '%s' in category '%s' without authorization!!!"
570 % (name, category)))
571 return
561 572
562 if node[0] == 'general': 573 if node[0] == 'general':
563 self.params_gen[(category, name)] = value 574 self.params_gen[(category, name)] = value
564 self.storage.setGenParam(category, name, value) 575 self.storage.setGenParam(category, name, value)
565 for profile in self.storage.getProfilesList(): 576 for profile in self.storage.getProfilesList():
919 return self.params.getParamsForCategory(category, security_limit, profile_key) 930 return self.params.getParamsForCategory(category, security_limit, profile_key)
920 931
921 def getParamsCategories(self): 932 def getParamsCategories(self):
922 return self.params.getParamsCategories() 933 return self.params.getParamsCategories()
923 934
924 def setParam(self, name, value, category, profile_key): 935 def setParam(self, name, value, category, security_limit, profile_key):
925 return self.params.setParam(name, value, category, profile_key) 936 return self.params.setParam(name, value, category, security_limit, profile_key)
926 937
927 def importParams(self, xml): 938 def importParams(self, xml):
928 return self.params.importParams(xml) 939 return self.params.importParams(xml)
929 940
930 def setDefault(self, name, category, callback, errback=None): 941 def setDefault(self, name, category, callback, errback=None):