def report_invalid_voip_addresses(logger, report): """Find voipAddress-objects owned by persons without primary account. @param logger @type list @param report is a list of dicts. """ logger.debug('-' * 8 + 'voipAddresses' + '-' * 8) db = Factory.get("Database")() va = VoipAddress(db) for entry in va.list_voip_attributes(): if entry['voipOwnerType'] != 'person': continue # skip objects owned by services if not entry.get("cn"): entry["cn"] = () # find addresses owner va.clear() va.find(entry['entity_id']) entry["voipOwnerId"] = va.owner_entity_id if entry["uid"] is None: logger.debug('uid is None') entry['reason'] = find_reason(db, entry) entr = {} for k, v in entry.iteritems(): if k in ('entity_id', 'voipOwnerId', 'cn', 'reason', 'voipExtensionUri', 'uid'): if k == 'voipExtensionUri': k = 'extension' if isinstance(v, basestring): v = v.strip('sip:@uio.no') entr[k] = v report.append(entr) logger.debug('-' * 8 + 'end voipAddresses' + '-' * 8)
def report_invalid_voip_addresses(logger, report): """Find voipAddress-objects owned by persons without primary account. @param logger @type list @param report is a list of dicts. """ logger.debug("-" * 8 + "voipAddresses" + "-" * 8) db = Factory.get("Database")() va = VoipAddress(db) for entry in va.list_voip_attributes(): if entry["voipOwnerType"] != "person": continue # skip objects owned by services if not entry.get("cn"): entry["cn"] = () # find addresses owner va.clear() va.find(entry["entity_id"]) entry["voipOwnerId"] = va.owner_entity_id if entry["uid"] is None: logger.debug("uid is None") entry["reason"] = find_reason(db, entry) entr = {} for k, v in entry.iteritems(): if k in ("entity_id", "voipOwnerId", "cn", "reason", "voipExtensionUri", "uid"): if k == "voipExtensionUri": k = "extension" if isinstance(v, basestring): v = v.strip("sip:@uio.no") entr[k] = v report.append(entr) logger.debug("-" * 8 + "end voipAddresses" + "-" * 8)
def join_uio_voip_objects(old_id, new_id, db): """Transfer voip objects from person old_id to person new_id. Respect that a person can have at most one voip_address, i.e. transfer happens only if old_id owns one address and new_id owns none. In case old_id owns no voip_address, nothing is transfered and join continues. Otherwise, join rolls back. @type int @param old_id person id @type int @param new_id person id """ from Cerebrum.modules.no.uio.voip.voipAddress import VoipAddress va = VoipAddress(db) va.clear() old_person_voip_addr = va.search(owner_entity_id=old_id) new_person_voip_addr = va.search(owner_entity_id=new_id) if (len(old_person_voip_addr) == 1 and not new_person_voip_addr): # Transfer va.clear() try: va.find_by_owner_id(old_id) except Errors.NotFoundError: logger.info("No voip address found for owner id %s" % (old_id)) return logger.debug("Change owner of voip_address %s to %s" % (va.entity_id, new_id)) va.populate(new_id) va.write_db() elif not old_person_voip_addr: logger.info("Nothing to transfer." " Person %s owns no voip addresses" % (old_id)) else: logger.warn("Source person %s owns voip addresses: %s" % (old_id, old_person_voip_addr)) logger.warn("Target person %s owns voip addresses:%s" % (new_id, new_person_voip_addr)) db.rollback() logger.warn("Cannot transfer, rollback all changes." "Manual intervention required to join voip objects.") sys.exit(1)
def _get_or_create_voip_address(self, owner_id, with_softphone=True): """Much like _get_voip_address(), except this one creates it as well if it does not exist, rather than failing. with_softphone controls whether we want to create a softphone for the new voip_address, should voip_address be created. """ address = VoipAddress(self.db) try: address.find_by_owner_id(owner_id) except Errors.NotFoundError: address.clear() address.populate(owner_id) address.write_db() address.write_db() if with_softphone: self._create_default_softphone_client(address.entity_id) return address
def join_uio_voip_objects(old_id, new_id): """Transfer voip objects from person old_id to person new_id. Respect that a person can have at most one voip_address, i.e. transfer happens only if old_id owns one address and new_id owns none. In case old_id owns no voip_address, nothing is transfered and join continues. Otherwise, join rolls back. @type int @param old_id person id @type int @param new_id person id """ from Cerebrum.modules.no.uio.voip.voipAddress import VoipAddress va = VoipAddress(db) va.clear() old_person_voip_addr = va.search(owner_entity_id=old_id) new_person_voip_addr = va.search(owner_entity_id=new_id) if (len(old_person_voip_addr) == 1 and not new_person_voip_addr): # Transfer va.clear() try: va.find_by_owner_id(old_id) except Errors.NotFoundError: logger.info("No voip address found for owner id %s" % (old_id)) return logger.debug("Change owner of voip_address %s to %s" % (va.entity_id, new_id)) va.populate(new_id) va.write_db() elif not old_person_voip_addr: logger.info("Nothing to transfer." " Person %s owns no voip addresses" % (old_id)) else: logger.warn("Source person %s owns voip addresses: %s" % (old_id, old_person_voip_addr)) logger.warn("Target person %s owns voip addresses:%s" % (new_id, new_person_voip_addr)) db.rollback() logger.warn("Cannot transfer, rollback all changes." "Manual intervention required to join voip objects.") sys.exit(1)