From 907e6e7aeb67309b2ba636e3041c549c4eac4a4c Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Mon, 22 Jan 2024 13:12:20 -0800 Subject: [PATCH] show Web user page even when direct is False not other protocols though --- pages.py | 16 ++++++++-------- tests/test_pages.py | 8 +++++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pages.py b/pages.py index 6fb136e..e9ebd0a 100644 --- a/pages.py +++ b/pages.py @@ -79,15 +79,15 @@ def load_user(protocol, id): elif user and id != user.key.id(): # use_instead redirect error('', status=302, location=user.user_page_path()) - if not user or not user.direct: - # TODO: switch back to USER_NOT_FOUND_HTML - # not easy via exception/abort because this uses Werkzeug's built in - # NotFound exception subclass, and we'd need to make it implement - # get_body to return arbitrary HTML. - error(f'{protocol} user {id} not found', status=404) + if user and (user.direct or protocol == 'web'): + assert not user.use_instead + return user - assert not user.use_instead - return user + # TODO: switch back to USER_NOT_FOUND_HTML + # not easy via exception/abort because this uses Werkzeug's built in + # NotFound exception subclass, and we'd need to make it implement + # get_body to return arbitrary HTML. + error(f'{protocol} user {id} not found', status=404) @app.route('/') diff --git a/tests/test_pages.py b/tests/test_pages.py index 65f406a..c84ffda 100644 --- a/tests/test_pages.py +++ b/tests/test_pages.py @@ -98,9 +98,11 @@ class PagesTest(TestCase): self.assert_equals(404, got.status_code) def test_user_not_direct(self): - self.user.direct = False - self.user.put() - got = self.client.get('/web/user.com') + fake = self.make_user('fake:foo', cls=Fake) + fake.direct = False + fake.put() + + got = self.client.get('/fake/fake:foo') self.assert_equals(404, got.status_code) def test_user_opted_out(self):