Example #1
0
def send_profile(profile_id, recipients=None):
    """Handle sending a Profile object out via the federation layer.

    :param profile_id: Profile.id of profile to send
    :param recipients: Optional list of recipients, see `federation.outbound.handle_send` parameters
    """
    try:
        profile = Profile.objects.get(id=profile_id, user__isnull=False)
    except Profile.DoesNotExist:
        logger.warning("send_profile - No local profile found with id %s",
                       profile_id)
        return
    entity = make_federable_profile(profile)
    if not entity:
        logger.warning("send_profile - No entity for %s", profile)
        return
    if settings.DEBUG:
        # Don't send in development mode
        return
    if not recipients:
        # If we have Matrix support enabled, also add the appservice
        if settings.SOCIALHOME_MATRIX_ENABLED:
            recipients = [profile.get_recipient_for_matrix_appservice()]
        else:
            recipients = []
        recipients.extend(_get_remote_followers(profile, profile.visibility))

    logger.debug("send_profile - sending to recipients: %s", recipients)
    handle_send(entity,
                profile.federable,
                recipients,
                payload_logger=get_outbound_payload_logger())
Example #2
0
def send_profile(profile_id, recipients=None):
    """Handle sending a Profile object out via the federation layer.

    :param profile_id: Profile.id of profile to send
    :param recipients: Optional list of recipients, see `federation.outbound.handle_send` parameters
    """
    try:
        profile = Profile.objects.get(id=profile_id, user__isnull=False)
    except Profile.DoesNotExist:
        logger.warning("send_profile - No local profile found with id %s",
                       profile_id)
        return
    entity = make_federable_profile(profile)
    if not entity:
        logger.warning("send_profile - No entity for %s", profile)
        return
    if settings.DEBUG:
        # Don't send in development mode
        return
    if not recipients:
        recipients = _get_remote_followers(profile, profile.visibility)
    logger.debug("send_profile - sending to recipients: %s", recipients)
    handle_send(entity,
                profile.federable,
                recipients,
                payload_logger=get_outbound_payload_logger())
Example #3
0
 def test_make_federable_profile(self):
     profile = ProfileFactory(visibility=Visibility.SELF)
     entity = make_federable_profile(profile)
     self.assertTrue(isinstance(entity, base.Profile))
     self.assertEqual(entity.id, profile.fid)
     self.assertEqual(entity.raw_content, "")
     self.assertEqual(entity.public, False)
     self.assertEqual(entity.name, profile.name)
     self.assertEqual(entity.public_key, profile.rsa_public_key)
     self.assertEqual(entity.image_urls, {
         "small": profile.safer_image_url_small,
         "medium": profile.safer_image_url_medium,
         "large": profile.safer_image_url_large,
     })
     profile = ProfileFactory(visibility=Visibility.LIMITED)
     entity = make_federable_profile(profile)
     self.assertEqual(entity.public, False)
     profile = ProfileFactory(visibility=Visibility.SITE)
     entity = make_federable_profile(profile)
     self.assertEqual(entity.public, False)
     profile = ProfileFactory(visibility=Visibility.PUBLIC)
     entity = make_federable_profile(profile)
     self.assertEqual(entity.public, True)
Example #4
0
 def test_make_federable_profile(self):
     profile = ProfileFactory(visibility=Visibility.SELF)
     entity = make_federable_profile(profile)
     self.assertTrue(isinstance(entity, base.Profile))
     self.assertEqual(entity.id, profile.fid)
     self.assertEqual(entity.raw_content, "")
     self.assertEqual(entity.public, False)
     self.assertEqual(entity.name, profile.name)
     self.assertEqual(entity.public_key, profile.rsa_public_key)
     self.assertEqual(
         entity.image_urls, {
             "small": profile.safer_image_url_small,
             "medium": profile.safer_image_url_medium,
             "large": profile.safer_image_url_large,
         })
     profile = ProfileFactory(visibility=Visibility.LIMITED)
     entity = make_federable_profile(profile)
     self.assertEqual(entity.public, False)
     profile = ProfileFactory(visibility=Visibility.SITE)
     entity = make_federable_profile(profile)
     self.assertEqual(entity.public, False)
     profile = ProfileFactory(visibility=Visibility.PUBLIC)
     entity = make_federable_profile(profile)
     self.assertEqual(entity.public, True)
Example #5
0
 def test_make_federable_profile(self):
     user = SelfUserFactory()
     profile = user.profile
     entity = make_federable_profile(profile)
     self.assertTrue(isinstance(entity, base.Profile))
     self.assertEqual(entity.id, profile.fid)
     self.assertEqual(entity.raw_content, "")
     self.assertEqual(entity.public, True)
     self.assertEqual(entity.name, profile.name_or_handle)
     self.assertEqual(entity.public_key, profile.rsa_public_key)
     self.assertEqual(
         entity.image_urls, {
             "small": profile.safer_image_url_small,
             "medium": profile.safer_image_url_medium,
             "large": profile.safer_image_url_large,
         })
 def test_profile_returned(self):
     returned = get_profile(fid=self.profile.fid)
     maked = make_federable_profile(self.profile)
     self.assertEqual(returned.id, maked.id)
     self.assertTrue(isinstance(returned, base.Profile))