Пример #1
0
def send_profile_retraction(profile):
    """Handle sending of retractions for profiles.

    Only sent for public and limited profiles. Reason: we might actually leak user information
    outside for profiles which were never federated outside if we send for example
    SELF or SITE profile retractions.

    This must be called as a pre_delete signal or it will fail.
    """
    if profile.visibility not in (Visibility.PUBLIC,
                                  Visibility.LIMITED) or not profile.is_local:
        return
    entity = make_federable_retraction(profile)
    if entity:
        if settings.DEBUG:
            # Don't send in development mode
            return
        if profile.visibility == Visibility.PUBLIC:
            recipients = [settings.SOCIALHOME_RELAY_ID]
        else:
            recipients = []
        recipients.extend(_get_remote_followers(profile))
        logger.debug("send_profile_retraction - sending to recipients: %s",
                     recipients)
        handle_send(entity, profile.federable, recipients)
    else:
        logger.warning("send_profile_retraction - No retraction entity for %s",
                       profile)
Пример #2
0
def send_content_retraction(content, author_id):
    """
    Handle sending of retractions for content.
    """
    if content.visibility not in (Visibility.PUBLIC,
                                  Visibility.LIMITED) or not content.local:
        return
    author = Profile.objects.get(id=author_id)
    entity = make_federable_retraction(content, author)
    if entity:
        if settings.DEBUG:
            # Don't send in development mode
            return
        if content.visibility == Visibility.PUBLIC:
            recipients = [settings.SOCIALHOME_RELAY_ID]
            recipients.extend(_get_remote_followers(author))
        else:
            recipients = _get_limited_recipients(author.uuid, content)

        logger.debug("send_content_retraction - sending to recipients: %s",
                     recipients)
        handle_send(entity, author.federable, recipients)
    else:
        logger.warning("send_content_retraction - No retraction entity for %s",
                       content)
Пример #3
0
def send_content_retraction(content, author_id):
    """
    Handle sending of retractions for content.
    """
    if content.visibility not in (Visibility.PUBLIC, Visibility.LIMITED) or not content.local:
        return
    author = Profile.objects.get(id=author_id)
    entity = make_federable_retraction(content, author)
    if entity:
        if settings.DEBUG:
            # Don't send in development mode
            return
        if content.visibility == Visibility.PUBLIC:
            recipients = [{
                "endpoint": settings.SOCIALHOME_RELAY_ID,
                "fid": "",
                "public": True,
                "protocol": "diaspora"
            }]
            recipients.extend(
                _get_remote_followers(author, content.visibility)
            )
        else:
            recipients = _get_limited_recipients(author.fid, content)

        logger.debug("send_content_retraction - sending to recipients: %s", recipients)
        # Queue to the background since sending could take a while
        django_rq.enqueue(handle_send, entity, author.federable, recipients)
    else:
        logger.warning("send_content_retraction - No retraction entity for %s", content)
Пример #4
0
 def test_returns_none_on_exception(self, mock_post):
     entity = make_federable_retraction(Mock(), Mock())
     self.assertIsNone(entity)
Пример #5
0
 def test_returns_entity(self):
     content = ContentFactory()
     entity = make_federable_retraction(content, content.author)
     self.assertEqual(entity.entity_type, "Post")
     self.assertEqual(entity.target_id, content.fid)
     self.assertEqual(entity.actor_id, content.author.fid)
Пример #6
0
 def test_returns_none_on_exception(self, mock_post):
     entity = make_federable_retraction(Mock(), Mock())
     self.assertIsNone(entity)
Пример #7
0
 def test_returns_entity(self):
     content = ContentFactory()
     entity = make_federable_retraction(content, content.author)
     self.assertEqual(entity.entity_type, "Post")
     self.assertEqual(entity.target_id, content.fid)
     self.assertEqual(entity.actor_id, content.author.fid)