Beispiel #1
0
def send_content(content_id):
    """Handle sending a Content object out via the federation layer.

    Currently we only deliver public content.
    """
    try:
        content = Content.objects.get(id=content_id,
                                      visibility=Visibility.PUBLIC)
    except Content.DoesNotExist:
        logger.warning("No content found with id %s", content_id)
        return
    if not content.is_local:
        return
    entity = make_federable_entity(content)
    if entity:
        if settings.DEBUG:
            # Don't send in development mode
            return
        recipients = [
            (settings.SOCIALHOME_RELAY_DOMAIN, "diaspora"),
        ]
        recipients.extend(_get_remote_followers(content.author))
        handle_send(entity, content.author, recipients)
    else:
        logger.warning("No entity for %s", content)
Beispiel #2
0
def send_content(content_id):
    """Handle sending a Content object out via the federation layer.

    Currently we only deliver public content.
    """
    try:
        content = Content.objects.get(id=content_id)
    except Content.DoesNotExist:
        logger.warning("No content found with id %s", content_id)
        return
    if not content.visibility == Visibility.PUBLIC:
        return
    entity = make_federable_entity(content)
    if entity:
        if settings.DEBUG:
            # Don't send in development mode
            return
        # TODO: federation should provide one method to send,
        # which handles also payload creation and url calculation
        payload = handle_create_payload(entity, content.author)
        # Just dump to the relay system for now
        url = "https://%s/receive/public" % settings.SOCIALHOME_RELAY_DOMAIN
        send_document(url, payload)
    else:
        logger.warning("No entity for %s", content)
Beispiel #3
0
def content_fetch_view(request, objtype, guid):
    """Diaspora content fetch view.

    Returns the signed payload for the public content. Non-public content will return 404.

    If the content is not local, redirect to content author server.

    Args:
        objtype (str) - Diaspora content type. Currently if it is `status_message`, `post` or `reshare`,
            we try to find `Content`.
        guid (str) - The object guid to look for.
    """
    if objtype not in ["status_message", "post", "reshare", "comment"]:
        raise Http404()
    content = get_object_or_404(Content,
                                guid=guid,
                                visibility=Visibility.PUBLIC)
    if not content.is_local:
        url = "https://%s/fetch/%s/%s" % (content.author.handle.split("@")[1],
                                          objtype, guid)
        return HttpResponseRedirect(url)
    entity = make_federable_entity(content)
    message = get_full_xml_representation(entity, content.author.private_key)
    document = MagicEnvelope(message=message,
                             private_key=content.author.private_key,
                             author_handle=content.author.handle)
    return HttpResponse(document.render(),
                        content_type="application/magic-envelope+xml")
Beispiel #4
0
 def test_returns_entity(self):
     content = ContentFactory()
     entity = make_federable_entity(content)
     self.assertEqual(entity.raw_content, content.text)
     self.assertEqual(entity.guid, content.guid)
     self.assertEqual(entity.handle, content.author.handle)
     self.assertEqual(entity.public, True)
     self.assertEqual(entity.provider_display_name, "Socialhome")
     self.assertEqual(entity.created_at, content.effective_created)
Beispiel #5
0
def content_xml_view(request, guid):
    """Diaspora single post view XML representation.

    Fetched by remote servers in certain situations.
    """
    content = get_object_or_404(Content,
                                guid=guid,
                                visibility=Visibility.PUBLIC)
    if not content.is_local:
        raise Http404()
    entity = make_federable_entity(content)
    xml = get_full_xml_representation(entity, content.author.private_key)
    return HttpResponse(xml, content_type="application/xml")
Beispiel #6
0
 def test_returns_none_on_exception(self, mock_post):
     entity = make_federable_entity(Mock())
     self.assertIsNone(entity)
 def test_returns_none_on_exception(self, mock_post):
     mock_post = Mock()
     mock_post.parent = False
     entity = make_federable_entity(mock_post)
     self.assertIsNone(entity)