Beispiel #1
0
    def patch(self):
        """Update a contact with payload.

        method follows the rfc5789 PATCH and rfc7396 Merge patch specifications,
        + 'current_state' caliopen's specs.
        stored messages are modified according to the fields within the payload,
        ie payload fields squash existing db fields, no other modification done.
        If message doesn't existing, response is 404.
        If payload fields are not conform to the message db schema, response is
        422 (Unprocessable Entity).
        Successful response is 204, without a body.
        """
        contact_id = self.request.swagger_data["contact_id"]
        patch = self.request.json

        contact = ContactObject(self.user.user_id, contact_id=contact_id)
        try:
            contact.apply_patch(patch,
                                db=True,
                                index=True,
                                with_validation=True)
        except Exception as exc:
            raise MergePatchError(error=exc)

        return Response(None, 204)
Beispiel #2
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()
Beispiel #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(self.user.user_id, contact_id=contact_id)
        contact.get_db()
        contact.unmarshall_db()
        return contact.marshall_json_dict()
Beispiel #4
0
    def delete(self):
        contact_id = self.request.swagger_data["contact_id"]
        contact = ContactObject(self.user.user_id, contact_id=contact_id)

        try:
            contact.delete()
        except Exception as exc:
            if isinstance(exc, ForbiddenAction):
                raise HTTPForbidden(exc)
            else:
                raise HTTPServerError(exc)

        return Response(None, 204)
Beispiel #5
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()