def _get_body(self, request): result = { "version": "2.0", "software": { "name": "kepi", "version": __version__, }, "protocols": ['activitypub'], "services": { "inbound": [], "outbound": [], }, "openRegistrations": False, "usage": { "users": { # When this information is meaningful, # we can implement this more seriously. "total": 1, "activeMonth": 1, }, "localPosts": 0, "localComments": 0, }, "metadata": {}, } return HttpResponse( status = 200, reason = 'Here you go', content = bytes(as_json(result), encoding='utf-8'), content_type='application/json; '+\ 'profile=http://nodeinfo.diaspora.software/ns/schema/2.0#')
def test_sender_with_local_follower_boosts_unknown_status(self): self._remote_alice = create_remote_person( remote_url = REMOTE_ALICE, name = 'alice', auto_fetch = True, ) follow = trilby_models.Follow( follower = self._local_fred, following = self._remote_alice, ) follow.save() original_remote_form = { '@context': 'https://www.w3.org/ns/activitystreams', 'id': 'https://example.com/actor/hello-world', 'type': 'Note', 'attributedTo': 'https://example.com/actor', 'content': 'Hello world', 'to': 'http://example.com/followers', } create_remote_person( remote_url = 'https://example.com/actor', name = 'random', ) mock_remote_object( 'https://example.com/actor/hello-world', as_json( original_remote_form, ), ) boost_form = { '@context': 'https://www.w3.org/ns/activitystreams', 'id': 'foo', 'type': 'Announce', 'actor': REMOTE_ALICE, 'object': 'https://example.com/actor/hello-world', 'to': 'http://example.com/followers', } create(boost_form) original_status = trilby_models.Status.objects.get( remote_url = 'https://example.com/actor/hello-world', ) self.assertTrue( original_status.reblogged, msg = 'the status was reblogged at the end', ) self.assertEqual( original_status.content, 'Hello world', msg = 'the status was reblogged at the end', )
def get(self, request): logger.info('Returning nodeinfo.') result = { "links": [ { "rel": "http://nodeinfo.diaspora.software/ns/schema/2.0", "href": request.build_absolute_uri("/nodeinfo.json"), }, ], } return HttpResponse( status = 200, reason = 'Here you go', content = bytes(as_json(result), encoding='utf-8'), content_type='application/json; '+\ 'profile=http://nodeinfo.diaspora.software/ns/schema/2.0#')
def _get_body(self, request): try: user = request.GET['resource'] except: logger.info('webfinger request had no username specified') return HttpResponse( status=400, reason='no resource for webfinger', content='no resource for webfinger', content_type='text/plain', ) # Generally, user resources should be prefaced with "acct:", # per RFC7565. We support this, but we don't enforce it. user = re.sub(r'^acct:', '', user) logger.info('webfinger request for %s', user) if '@' not in user: logger.info(' -- no @ sign; bailing') return HttpResponse( status=404, reason='absolute name required', content='Please use the absolute form of the username.', content_type='text/plain', ) username, hostname = user.split('@', 2) if hostname not in settings.ALLOWED_HOSTS: logger.info(' -- %s is not local; bailing', hostname) return HttpResponse( status=404, reason='not this server', content='That user lives on another server.', content_type='text/plain', ) try: whoever = trilby_models.TrilbyUser.objects.get(username=username, ) except trilby_models.TrilbyUser.DoesNotExist: logger.info(' -- we don\'t have anyone called %s', username) return HttpResponse( status=404, reason='no such user', content='We don\'t have a user with that name.', content_type='text/plain', ) actor_url = configured_url( 'USER_LINK', username=username, ) result = { "subject": "acct:{}@{}".format(username, hostname), "aliases": [ actor_url, ], "links": [ { 'rel': 'http://webfinger.net/rel/profile-page', 'type': 'text/html', 'href': actor_url, }, #{ #'rel': 'http://schemas.google.com/g/2010#updates-from', #'type': 'application/atom+xml', #'href': 'FIXME', # FIXME whoever['feedURL'], #}, { 'rel': 'self', 'type': 'application/activity+json', 'href': actor_url, }, { 'rel': 'http://ostatus.org/schema/1.0/subscribe', 'template': configured_url('AUTHORIZE_FOLLOW_LINK'), }, ] } logger.debug(' -- webfinger for %s was successful', user) return HttpResponse(status=200, reason='Here you go', content=bytes(as_json(result), encoding='utf-8'), content_type='application/jrd+json; charset=utf-8')
def __repr__(self): return as_json(self.value)