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, recipients) else: logger.warning("send_profile_retraction - No retraction entity for %s", profile)
def send_content_retraction(content, author_id): """Handle sending of retractions for content. Currently only for public content. """ if not content.visibility == Visibility.PUBLIC 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 recipients = [settings.SOCIALHOME_RELAY_ID] recipients.extend(_get_remote_followers(author)) logger.debug("send_content_retraction - sending to recipients: %s", recipients) handle_send(entity, author, recipients) else: logger.warning("send_content_retraction - No retraction entity for %s", content)
def send_content_retraction(content, author_id): """Handle sending of retractions. Currently only for public content. """ if not content.visibility == Visibility.PUBLIC: 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 payload = handle_create_payload(entity, 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 retraction entity for %s", content)
def test_returns_none_on_exception(self, mock_post): entity = make_federable_retraction(Mock(), Mock()) self.assertIsNone(entity)
def test_returns_entity(self): content = ContentFactory() entity = make_federable_retraction(content, content.author) self.assertEqual(entity.entity_type, "Post") self.assertEqual(entity.target_guid, content.guid) self.assertEqual(entity.handle, content.author.handle)