diff --git a/pages.py b/pages.py index d3c880c..3bb31d9 100644 --- a/pages.py +++ b/pages.py @@ -60,17 +60,16 @@ def load_user(protocol, id): :class:`werkzeug.exceptions.HTTPException` on error or redirect """ assert id - if protocol == 'ap' and not id.startswith('@'): - id = '@' + id cls = PROTOCOLS[protocol] + + if cls.ABBREV == 'ap' and not id.startswith('@'): + id = '@' + id user = cls.get_by_id(id) - if protocol != 'web': + if cls.ABBREV != 'web': if not user: - user = cls.query(OR(cls.handle == id, - cls.readable_id == id), - ).get() + user = cls.query(OR(cls.handle == id, cls.handle == id)).get() if user and user.use_instead: user = user.use_instead.get() @@ -80,7 +79,7 @@ def load_user(protocol, id): elif user and id != user.key.id(): # use_instead redirect error('', status=302, location=user.user_page_path()) - if user and (user.direct or protocol == 'web'): + if user and (user.direct or cls.ABBREV != 'ap'): assert not user.use_instead return user diff --git a/tests/test_pages.py b/tests/test_pages.py index 2202992..0596ef0 100644 --- a/tests/test_pages.py +++ b/tests/test_pages.py @@ -99,11 +99,12 @@ class PagesTest(TestCase): self.assert_equals(404, got.status_code) def test_user_not_direct(self): - fake = self.make_user('fake:foo', cls=Fake) - fake.direct = False - fake.put() - + fake = self.make_user('fake:foo', cls=Fake, direct=False) got = self.client.get('/fake/fake:foo') + self.assert_equals(200, got.status_code) + + fake = self.make_user('http://fo/o', cls=ActivityPub, direct=False) + got = self.client.get('/ap/@o@fo') self.assert_equals(404, got.status_code) def test_user_opted_out(self): diff --git a/tests/testutil.py b/tests/testutil.py index d28450b..0cc3e71 100644 --- a/tests/testutil.py +++ b/tests/testutil.py @@ -303,8 +303,8 @@ class TestCase(unittest.TestCase, testutil.Asserts): mf2=obj_mf2, source_protocol=cls.LABEL ).key + kwargs.setdefault('direct', True) user = cls(id=id, - direct=True, mod=global_user.mod, public_exponent=global_user.public_exponent, private_exponent=global_user.private_exponent,