kopia lustrzana https://github.com/snarfed/bridgy-fed
AP: handle opted out users in following/ers, outbox collections
rodzic
fe8b710cce
commit
8f0d2d8650
2
pages.py
2
pages.py
|
@ -80,7 +80,7 @@ def load_user(protocol, id):
|
||||||
elif user and id != user.key.id(): # use_instead redirect
|
elif user and id != user.key.id(): # use_instead redirect
|
||||||
error('', status=302, location=user.user_page_path())
|
error('', status=302, location=user.user_page_path())
|
||||||
|
|
||||||
if not user or not user.direct or user.status == 'opt-out':
|
if not user or not user.direct:
|
||||||
# TODO: switch back to USER_NOT_FOUND_HTML
|
# TODO: switch back to USER_NOT_FOUND_HTML
|
||||||
# not easy via exception/abort because this uses Werkzeug's built in
|
# not easy via exception/abort because this uses Werkzeug's built in
|
||||||
# NotFound exception subclass, and we'd need to make it implement
|
# NotFound exception subclass, and we'd need to make it implement
|
||||||
|
|
|
@ -204,7 +204,7 @@ class Protocol:
|
||||||
return proto.key_for(id) if proto else None
|
return proto.key_for(id) if proto else None
|
||||||
|
|
||||||
# load user so that we follow use_instead
|
# load user so that we follow use_instead
|
||||||
existing = cls.get_by_id(id)
|
existing = cls.get_by_id(id, allow_opt_out=True)
|
||||||
if existing:
|
if existing:
|
||||||
if existing.status == 'opt-out':
|
if existing.status == 'opt-out':
|
||||||
return None
|
return None
|
||||||
|
@ -598,7 +598,7 @@ class Protocol:
|
||||||
logger.warning(f"actor {actor} isn't authed user {authed_as}")
|
logger.warning(f"actor {actor} isn't authed user {authed_as}")
|
||||||
|
|
||||||
from_user = from_cls.get_or_create(id=actor)
|
from_user = from_cls.get_or_create(id=actor)
|
||||||
if not from_user or from_user.status == 'opt-out':
|
if not from_user:
|
||||||
error(f'Actor {actor} is opted out', status=204)
|
error(f'Actor {actor} is opted out', status=204)
|
||||||
|
|
||||||
# update copy ids to originals
|
# update copy ids to originals
|
||||||
|
|
|
@ -1589,6 +1589,13 @@ class ActivityPubTest(TestCase):
|
||||||
self.assertEqual(200, resp.status_code)
|
self.assertEqual(200, resp.status_code)
|
||||||
self.assertEqual('', resp.get_data(as_text=True))
|
self.assertEqual('', resp.get_data(as_text=True))
|
||||||
|
|
||||||
|
def test_following_collection_opted_out(self, *_):
|
||||||
|
self.user.obj.our_as1['summary'] = '#nobridge'
|
||||||
|
self.user.obj.put()
|
||||||
|
self.user.put()
|
||||||
|
resp = self.client.get(f'/user.com/following', base_url='https://web.brid.gy')
|
||||||
|
self.assertEqual(404, resp.status_code)
|
||||||
|
|
||||||
def test_outbox_fake_empty(self, *_):
|
def test_outbox_fake_empty(self, *_):
|
||||||
self.make_user('fake:foo', cls=Fake)
|
self.make_user('fake:foo', cls=Fake)
|
||||||
resp = self.client.get(f'/ap/fake:foo/outbox',
|
resp = self.client.get(f'/ap/fake:foo/outbox',
|
||||||
|
@ -1677,6 +1684,14 @@ class ActivityPubTest(TestCase):
|
||||||
self.assertEqual(200, resp.status_code)
|
self.assertEqual(200, resp.status_code)
|
||||||
self.assertEqual('', resp.get_data(as_text=True))
|
self.assertEqual('', resp.get_data(as_text=True))
|
||||||
|
|
||||||
|
def test_outbox_opted_out(self, *_):
|
||||||
|
self.user.obj.our_as1['summary'] = '#nobridge'
|
||||||
|
self.user.obj.put()
|
||||||
|
self.user.put()
|
||||||
|
resp = self.client.get(f'/ap/user.com/outbox',
|
||||||
|
base_url='https://web.brid.gy')
|
||||||
|
self.assertEqual(404, resp.status_code)
|
||||||
|
|
||||||
|
|
||||||
class ActivityPubUtilsTest(TestCase):
|
class ActivityPubUtilsTest(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
Ładowanie…
Reference in New Issue