Пример #1
0
def copy_user_contacts(user,
                       new_domain,
                       old_domain,
                       only_index=False,
                       filter_id=None):
    ids = copy_contacts(user, only_index, filter_id)
    for id in ids:
        contact = ContactObject(user, contact_id=id)
        try:
            contact.get_db()
        except NotFound:
            log.error('Contact {} not found for user {}'.format(
                user.contact_id, user.user_id))
            continue
        contact.unmarshall_db()

        if not only_index:
            if str(user.contact_id) == str(id):
                try:
                    patch_user_contact(user, contact, new_domain, old_domain)
                except Exception as exc:
                    log.exception('Error during user contact patch {}'.format(
                        user.user_id))
                continue
            for email in contact.emails:
                ContactLookup.create(user=user,
                                     contact_id=id,
                                     value=email.address.lower(),
                                     type='email')
            for ident in contact.identities:
                ContactLookup.create(user=user,
                                     contact_id=id,
                                     value=ident.name.lower(),
                                     type=ident.type.lower())
        contact.create_index()
Пример #2
0
    def get(self):
        contact_id = self.request.swagger_data["contact_id"]
        try:
            uuid.UUID(contact_id)
        except Exception as exc:
            log.error("unable to extract contact_id: {}".format(exc))
            raise ValidationError(exc)

        contact = ContactObject(self.user.user_id, contact_id=contact_id)
        contact.get_db()
        contact.unmarshall_db()
        return contact.marshall_json_dict()
Пример #3
0
    def get(self):
        contact_id = self.request.swagger_data["contact_id"]
        try:
            uuid.UUID(contact_id)
        except Exception as exc:
            log.error("unable to extract contact_id: {}".format(exc))
            raise ValidationError(exc)

        contact = ContactObject(user=self.user, contact_id=contact_id)
        try:
            contact.get_db()
            contact.unmarshall_db()
        except Exception as exc:
            log.warn(exc)
            raise ResourceNotFound(detail=exc.message)
        return contact.marshall_json_dict()