def diffObject(self, user, ref): """ Opens a copy of the object given as ref and returns a diff - if any. """ item = self.db.object_pool.find_one({'uuid': ref}) if item is None: return None if not self.__check_user(ref, user): raise ValueError(C.make_error("NO_OBJECT_OWNER")) # Load current object current_obj = ObjectProxy(item['object']['dn']) # Load cache object cache_obj = item['object']['object'] if cache_obj is None: cache_obj = self.__object[ref] ## ## Generate delta ## delta = {'attributes': {'added': {}, 'removed': [], 'changed': {}}, 'extensions': {'added': [], 'removed': []}} # Compare extension list crnt_extensions = set(current_obj.get_object_info()['extensions'].items()) cche_extensions = set(cache_obj.get_object_info()['extensions'].items()) for _e, _s in crnt_extensions - cche_extensions: if _s: delta['extensions']['added'].append(_e) else: delta['extensions']['removed'].append(_e) # Compare attribute contents crnt_attributes = dict(filter(lambda x: x[1], current_obj.get_attribute_values()['value'].items())) cche_attributes = dict(filter(lambda x: x[1], cache_obj.get_attribute_values()['value'].items())) for _k, _v in crnt_attributes.items(): if _k in cche_attributes: if _v != cche_attributes[_k]: delta['attributes']['changed'][_k] = _v else: delta['attributes']['added'][_k] = _v for _k, _v in cche_attributes.items(): if not _k in crnt_attributes: delta['attributes']['removed'].append(_k) return delta
def saveUserPreferences(self, userid, name, value): index = PluginRegistry.getInstance("ObjectIndex") res = index.search({'_type': 'User', 'uid': userid}, {'dn': 1}) if not res.count(): raise GOsaException(C.make_error("UNKNOWN_USER", userid)) user = ObjectProxy(res[0]['dn']) prefs = user.guiPreferences if not prefs: prefs = {} else: prefs = loads(prefs) prefs[name] = value user.guiPreferences = dumps(prefs) user.commit() return True
#!/usr/bin/env python # -*- coding: utf-8 -*- import logging from clacks.agent.objects import ObjectProxy from clacks.agent.objects.index import ObjectIndex, SCOPE_SUB # Do some searching ie = ObjectIndex() print "*" * 80 print "Create" print "*" * 80 obj = ObjectProxy(u"ou=people,dc=gonicus,dc=de", "User") obj.uid = "eike" obj.sn = u"Kunst" obj.givenName = u"Eike" obj.commit() print "*" * 80 print "Delete" print "*" * 80 obj = ObjectProxy(u"cn=Eike Kunst,ou=people,dc=gonicus,dc=de") obj.remove() print "*" * 80 print "Extend or retract" print "*" * 80