def delete(self): """ Tries to delete the item on the server """ lumaConnection = LumaConnectionWrapper(self.serverParent.serverMeta) bindSuccess, exceptionObject = lumaConnection.bindSync() if not bindSuccess: message = QtCore.QCoreApplication.translate( "LDAPTreeItem", "Could not bind to server.") return (False, message, exceptionObject) success, exceptionObject = lumaConnection.delete( self.smartObject().getDN()) lumaConnection.unbind() if success: self.childItems = [] self.populated = True return (True, None, None) else: message = QtCore.QCoreApplication.translate( "LDAPTreeItem", "Could not delete entry: " + exceptionObject[0]["desc"]) return (False, message, exceptionObject)
def saveModel(self): """ Save changes to the current object. """ lumaConnection = LumaConnectionWrapper(self.smartObject.getServerMeta()) bindSuccess, exceptionObject = lumaConnection.bindSync() if not bindSuccess: message = self.str_BIND return (False, message, exceptionObject) if self.CREATE: success, exceptionObject = lumaConnection.addDataObject(self.smartObject) lumaConnection.unbind() if success: #self.CREATE = False self.EDITED = False self.modelChangedSignal.emit(False) return (True, None, None) else: message = self.str_ADD return (False, message, exceptionObject) else: success, exceptionObject = lumaConnection.updateDataObject(self.smartObject) lumaConnection.unbind() if success: self.EDITED = False self.modelChangedSignal.emit(False) return (True, None, None) else: message = self.str_SAVE return (False, message, exceptionObject)
def fetchChildList(self): """ (Re)aquire the list of childs for this item (if any). """ lumaConnection = LumaConnectionWrapper(self.serverParent.serverMeta) bindSuccess, exceptionObject = lumaConnection.bindSync() if not bindSuccess: tmp = LDAPErrorItem(str("[" + exceptionObject[0]["desc"] + "]"), self.serverParent, self) # We're adding the error as LDAPErrorItem-child, so return True return (True, [tmp], exceptionObject) # Search for items at the level under this one success, resultList, exceptionObject = lumaConnection.searchSync(self.itemData.getDN(), \ scope=ldap.SCOPE_ONELEVEL, filter=self.filter.encode('utf8'), sizelimit=self.limit) lumaConnection.unbind() if not success: tmp = LDAPErrorItem(str("[" + exceptionObject[0]["desc"] + "]"), self.serverParent, self) # We're adding the error as LDAPErrorItem-child, so return True return (True, [tmp], exceptionObject) self.error = False # Default behavior: return all return (True, [LDAPTreeItem(x, self.serverParent, self) for x in resultList], exceptionObject)
def deleteObject(self): """ Deletes the remote object that this model represents """ lumaConnection = LumaConnectionWrapper( self.smartObject.getServerMeta()) bindSuccess, exceptionObject = lumaConnection.bindSync() if not bindSuccess: message = self.str_BIND return (False, message, exceptionObject) success, exceptionObject = lumaConnection.delete( self.smartObject.getDN()) lumaConnection.unbind() if success: #serverName = self.smartObject.getServerAlias() #dn = self.smartObject.getPrettyParentDN() #self.model().reloadItem(self.smartObject.parent()) #self.modelChangedSignal.emit() return (True, None, None) else: message = self.str_DELETE return (False, message, exceptionObject)
def reloadModel(self): """ Refreshes the LDAP data from server, """ lumaConnection = LumaConnectionWrapper( self.smartObject.getServerMeta()) bindSuccess, exceptionObject = lumaConnection.bindSync() if not bindSuccess: message = self.str_BIND return (False, message, exceptionObject) success, resultList, exceptionObject = lumaConnection.searchSync( self.smartObject.getDN(), ldap.SCOPE_BASE) lumaConnection.unbind() if success and (len(resultList) > 0): self.smartObject = resultList[0] self.smartObject.checkIntegrity() self.VALID = self.smartObject.isValid self.EDITED = False self.modelChangedSignal.emit(True) return (True, None, None) else: message = self.str_REFRESH return (False, message, exceptionObject)
def fetchChildList(self): """ (Re)aquire the list of childs for this item (if any). """ lumaConnection = LumaConnectionWrapper(self.serverParent.serverMeta) bindSuccess, exceptionObject = lumaConnection.bindSync() if not bindSuccess: tmp = LDAPErrorItem(str("["+exceptionObject[0]["desc"]+"]"), self.serverParent, self) # We're adding the error as LDAPErrorItem-child, so return True return (True, [tmp], exceptionObject) # Search for items at the level under this one success, resultList, exceptionObject = lumaConnection.searchSync(self.itemData.getDN(), \ scope=ldap.SCOPE_ONELEVEL, filter=self.filter.encode('utf8'), sizelimit=self.limit) lumaConnection.unbind() if not success: tmp = LDAPErrorItem(str("["+exceptionObject[0]["desc"]+"]"), self.serverParent, self) # We're adding the error as LDAPErrorItem-child, so return True return (True, [tmp], exceptionObject) self.error = False # Default behavior: return all return (True, [LDAPTreeItem(x, self.serverParent, self) for x in resultList], exceptionObject)
def initModel(self, create=False): if create: self.EDITED = True self.ISLEAF = False self.CREATE = True self.VALID = True else: self.EDITED = False isLeave = False self.smartObject.checkIntegrity() self.VALID = self.smartObject.isValid serverMeta = self.smartObject.getServerMeta() lumaConnection = LumaConnectionWrapper(serverMeta, self) bindSuccess, exceptionObject = lumaConnection.bindSync() if not bindSuccess: message = self.str_BIND return (False, message, exceptionObject) success, resultList, exceptionObject = lumaConnection.searchSync( self.smartObject.dn, ldap.SCOPE_ONELEVEL, filter="(objectClass=*)", attrList=None, attrsonly=1, sizelimit=1) lumaConnection.unbind() # Our search succeeded. No errors if success: # There are no leaves below if len(resultList) == 0: self.ISLEAF = True # Leaves are below else: self.ISLEAF = False # Error during search request else: self.ISLEAF = False message = self.str_CHECK_LEAF self.modelChangedSignal.emit(True) return (False, message, exceptionObject) self.CREATE = False self.modelChangedSignal.emit(True) return (True, None, None)
def initModel(self, create=False): if create: self.EDITED = True self.ISLEAF = False self.CREATE = True self.VALID = True else: self.EDITED = False isLeave = False self.smartObject.checkIntegrity() self.VALID = self.smartObject.isValid serverMeta = self.smartObject.getServerMeta() lumaConnection = LumaConnectionWrapper(serverMeta, self) bindSuccess, exceptionObject = lumaConnection.bindSync() if not bindSuccess: message = self.str_BIND return (False, message, exceptionObject) success, resultList, exceptionObject = lumaConnection.searchSync(self.smartObject.dn, ldap.SCOPE_ONELEVEL, filter="(objectClass=*)", attrList=None, attrsonly=1, sizelimit=1) lumaConnection.unbind() # Our search succeeded. No errors if success: # There are no leaves below if len(resultList) == 0: self.ISLEAF = True # Leaves are below else: self.ISLEAF = False # Error during search request else: self.ISLEAF = False message = self.str_CHECK_LEAF self.modelChangedSignal.emit(True) return (False, message, exceptionObject) self.CREATE = False self.modelChangedSignal.emit(True) return (True, None, None)
def delete(self): """ Tries to delete the item on the server """ lumaConnection = LumaConnectionWrapper(self.serverParent.serverMeta) bindSuccess, exceptionObject = lumaConnection.bindSync() if not bindSuccess: message = QtCore.QCoreApplication.translate("LDAPTreeItem","Could not bind to server.") return (False, message, exceptionObject) success, exceptionObject = lumaConnection.delete(self.smartObject().getDN()) lumaConnection.unbind() if success: self.childItems = [] self.populated = True return (True, None, None) else: message = QtCore.QCoreApplication.translate("LDAPTreeItem","Could not delete entry: "+exceptionObject[0]["desc"]) return (False, message, exceptionObject)
def saveModel(self): """ Save changes to the current object. """ lumaConnection = LumaConnectionWrapper( self.smartObject.getServerMeta()) bindSuccess, exceptionObject = lumaConnection.bindSync() if not bindSuccess: message = self.str_BIND return (False, message, exceptionObject) if self.CREATE: success, exceptionObject = lumaConnection.addDataObject( self.smartObject) lumaConnection.unbind() if success: #self.CREATE = False self.EDITED = False self.modelChangedSignal.emit(False) return (True, None, None) else: message = self.str_ADD return (False, message, exceptionObject) else: success, exceptionObject = lumaConnection.updateDataObject( self.smartObject) lumaConnection.unbind() if success: self.EDITED = False self.modelChangedSignal.emit(False) return (True, None, None) else: message = self.str_SAVE return (False, message, exceptionObject)
def deleteObject(self): """ Deletes the remote object that this model represents """ lumaConnection = LumaConnectionWrapper(self.smartObject.getServerMeta()) bindSuccess, exceptionObject = lumaConnection.bindSync() if not bindSuccess: message = self.str_BIND return (False, message, exceptionObject) success, exceptionObject = lumaConnection.delete(self.smartObject.getDN()) lumaConnection.unbind() if success: #serverName = self.smartObject.getServerAlias() #dn = self.smartObject.getPrettyParentDN() #self.model().reloadItem(self.smartObject.parent()) #self.modelChangedSignal.emit() return (True, None, None) else: message = self.str_DELETE return (False, message, exceptionObject)
def reloadModel(self): """ Refreshes the LDAP data from server, """ lumaConnection = LumaConnectionWrapper(self.smartObject.getServerMeta()) bindSuccess, exceptionObject = lumaConnection.bindSync() if not bindSuccess: message = self.str_BIND return (False, message, exceptionObject) success, resultList, exceptionObject = lumaConnection.searchSync(self.smartObject.getDN(), ldap.SCOPE_BASE) lumaConnection.unbind() if success and (len(resultList) > 0): self.smartObject = resultList[0] self.smartObject.checkIntegrity() self.VALID = self.smartObject.isValid self.EDITED = False self.modelChangedSignal.emit(True) return (True, None, None) else: message = self.str_REFRESH return (False, message, exceptionObject)