def voip_address_delete_number(self, operator, value, owner=None): """Delete a previously registered phone number. If a phone number is associated with several entities, we cowardly refuse, unless owner is specified. @param value: Contact info string. Could be full or short version of the phone number. """ self.ba.can_alter_number(operator.get_entity_id()) contacts = self._get_contact_info(value) if not contacts: return "OK, nothing to delete (no record of %r)" % (value) if owner is not None: owner = self._get_voip_owner(owner) if len(contacts) > 1 and owner is None: raise CerebrumError("Multiple entities have %s registered. You " "must specified entity to update." % (value,)) eci = EntityContactInfo(self.db) victims = set() for d in contacts: if owner and owner.entity_id != d["entity_id"]: continue eci.clear() eci.find(d["entity_id"]) eci.delete_contact_info(d["source_system"], d["contact_type"], d["contact_pref"]) victims.add(eci.entity_id) return "OK, removed %r from %d entit%s: %s" % ( value, len(victims), len(victims) != 1 and "ies" or "y", ", ".join("id=%s" % x for x in victims))
def voip_address_delete_number(self, operator, value, owner=None): """Delete a previously registered phone number. If a phone number is associated with several entities, we cowardly refuse, unless owner is specified. @param value: Contact info string. Could be full or short version of the phone number. """ self.ba.can_alter_number(operator.get_entity_id()) contacts = self._get_contact_info(value) if not contacts: return "OK, nothing to delete (no record of %s)" % (str(value)) if owner is not None: owner = self._get_voip_owner(owner) if len(contacts) > 1 and owner is None: raise CerebrumError("Multiple entities have %s registered. You " "must specified entity to update." % (value, )) eci = EntityContactInfo(self.db) victims = set() for d in contacts: if owner and owner.entity_id != d["entity_id"]: continue eci.clear() eci.find(d["entity_id"]) eci.delete_contact_info(d["source_system"], d["contact_type"], d["contact_pref"]) victims.add(eci.entity_id) return "OK, removed %s from %d entit%s: %s" % ( str(value), len(victims), len(victims) != 1 and "ies" or "y", ", ".join("id=%s" % x for x in victims))