def get_voip_persons_and_primary_accounts(): va = VoipAddress(db) ac = Factory.get("Account")(db) const = Factory.get("Constants")() voippersons = list() for row in va.search(owner_entity_type=const.entity_person): voippersons.append(row["owner_entity_id"]) sysadm_aid = ac.list_sysadm_accounts() primary2pid = dict( (r["account_id"], r["person_id"]) for r in ac.list_accounts_by_type(primary_only=True, person_id=voippersons, exclude_account_id=sysadm_aid)) return voippersons, primary2pid, sysadm_aid
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 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)