kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
9eaab23bcc
commit
ae315a4257
20
pages.py
20
pages.py
|
|
@ -73,20 +73,18 @@ def load_user(protocol, id):
|
|||
id = '@' + id
|
||||
user = cls.get_by_id(id)
|
||||
|
||||
if cls.ABBREV != 'web':
|
||||
if not user:
|
||||
user = cls.query(cls.handle == id, cls.status == None).get()
|
||||
if user and user.use_instead:
|
||||
user = user.use_instead.get()
|
||||
if not user and cls.ABBREV != 'web':
|
||||
# query by handle, except for web. Web.handle is custom username, which
|
||||
# isn't unique
|
||||
user = cls.query(cls.handle == id, cls.status == None).get()
|
||||
if user and user.use_instead:
|
||||
user = user.use_instead.get()
|
||||
|
||||
if user and id not in (user.key.id(), user.handle):
|
||||
error('', status=302, location=user.user_page_path())
|
||||
|
||||
elif user and id != user.key.id(): # use_instead redirect
|
||||
if user and id not in (user.key.id(), user.handle):
|
||||
error('', status=302, location=user.user_page_path())
|
||||
|
||||
if user and not user.status and (user.enabled_protocols
|
||||
or user.DEFAULT_ENABLED_PROTOCOLS):
|
||||
or user.DEFAULT_SERVE_USER_PAGES):
|
||||
assert not user.use_instead
|
||||
return user
|
||||
|
||||
|
|
@ -195,7 +193,7 @@ def update_profile(protocol, id):
|
|||
for label in list(user.DEFAULT_ENABLED_PROTOCOLS) + user.enabled_protocols:
|
||||
try:
|
||||
PROTOCOLS[label].set_username(user, id)
|
||||
except (ValueError, RuntimeError, NotImplementedError) as e:
|
||||
except (AssertionError, ValueError, RuntimeError, NotImplementedError):
|
||||
pass
|
||||
|
||||
return redir
|
||||
|
|
|
|||
|
|
@ -108,9 +108,13 @@ class Protocol:
|
|||
``User.status`` will be ``blocked``.
|
||||
DEFAULT_ENABLED_PROTOCOLS (sequence of str): labels of other protocols
|
||||
that are automatically enabled for this protocol to bridge into
|
||||
DEFAULT_SERVE_USER_PAGES (bool): whether to serve user pages for all of
|
||||
this protocol's users on the fed.brid.gy. If ``False``, user pages will
|
||||
only be served for users who have explictly opted in.
|
||||
SUPPORTED_AS1_TYPES (sequence of str): AS1 objectTypes and verbs that this
|
||||
protocol supports receiving and sending.
|
||||
SUPPORTS_DMS (bool): whether this protocol can receive DMs (chat messages)
|
||||
|
||||
"""
|
||||
ABBREV = None
|
||||
PHRASE = None
|
||||
|
|
@ -122,6 +126,7 @@ class Protocol:
|
|||
REQUIRES_NAME = False
|
||||
REQUIRES_OLD_ACCOUNT = False
|
||||
DEFAULT_ENABLED_PROTOCOLS = ()
|
||||
DEFAULT_SERVE_USER_PAGES = False
|
||||
SUPPORTED_AS1_TYPES = ()
|
||||
SUPPORTS_DMS = False
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,16 @@ from oauth_dropins.webutil.testutil import requests_response
|
|||
from requests import ConnectionError
|
||||
|
||||
# import first so that Fake is defined before URL routes are registered
|
||||
from .testutil import Fake, OtherFake, TestCase, ACTOR, COMMENT, MENTION, NOTE
|
||||
from .testutil import (
|
||||
Fake,
|
||||
ExplicitFake,
|
||||
OtherFake,
|
||||
TestCase,
|
||||
ACTOR,
|
||||
COMMENT,
|
||||
MENTION,
|
||||
NOTE,
|
||||
)
|
||||
|
||||
from activitypub import ActivityPub
|
||||
from atproto import ATProto
|
||||
|
|
@ -70,6 +79,7 @@ class PagesTest(TestCase):
|
|||
|
||||
def test_user_page_handle(self):
|
||||
user = self.make_user('http://fo/o', cls=ActivityPub,
|
||||
enabled_protocols=['fake'],
|
||||
obj_as1=ACTOR_WITH_PREFERRED_USERNAME)
|
||||
self.assertEqual('@me@fo', user.handle_as(ActivityPub))
|
||||
|
||||
|
|
@ -128,6 +138,16 @@ class PagesTest(TestCase):
|
|||
got = self.client.get('/fa/fake:handle:user')
|
||||
self.assert_equals(404, got.status_code)
|
||||
|
||||
def test_user_default_serve_false_no_enabled_protocols(self):
|
||||
self.make_user('other:foo', cls=OtherFake)
|
||||
got = self.client.get('/other/other:foo')
|
||||
self.assert_equals(404, got.status_code)
|
||||
|
||||
def test_user_default_serve_false_enabled_protocols(self):
|
||||
self.make_user('other:foo', cls=OtherFake, enabled_protocols=['fake'])
|
||||
got = self.client.get('/other/other:foo')
|
||||
self.assert_equals(200, got.status_code)
|
||||
|
||||
def test_user_web_redirect(self):
|
||||
got = self.client.get('/user/user.com')
|
||||
self.assert_equals(301, got.status_code)
|
||||
|
|
@ -394,6 +414,7 @@ class PagesTest(TestCase):
|
|||
|
||||
def test_followers_activitypub(self):
|
||||
user = self.make_user('https://inst/user', cls=ActivityPub,
|
||||
enabled_protocols=['fake'],
|
||||
obj_as1=ACTOR_WITH_PREFERRED_USERNAME)
|
||||
|
||||
got = self.client.get('/ap/@me@inst/followers')
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ class Fake(User, protocol.Protocol):
|
|||
DEFAULT_ENABLED_PROTOCOLS = ('other',)
|
||||
HAS_COPIES = True
|
||||
LOGO_HTML = '<img src="fake-logo">'
|
||||
DEFAULT_SERVE_USER_PAGES = True
|
||||
SUPPORTED_AS1_TYPES = frozenset(
|
||||
tuple(as1.ACTOR_TYPES)
|
||||
+ tuple(as1.POST_TYPES)
|
||||
|
|
@ -214,6 +215,7 @@ class OtherFake(Fake):
|
|||
PHRASE = 'other-phrase'
|
||||
CONTENT_TYPE = 'ot/her'
|
||||
DEFAULT_ENABLED_PROTOCOLS = ('fake',)
|
||||
DEFAULT_SERVE_USER_PAGES = False
|
||||
SUPPORTED_AS1_TYPES = Fake.SUPPORTED_AS1_TYPES - set(('accept',))
|
||||
SUPPORTS_DMS = True
|
||||
|
||||
|
|
@ -240,6 +242,7 @@ class ExplicitFake(Fake):
|
|||
PHRASE = 'efake-phrase'
|
||||
CONTENT_TYPE = 'un/known'
|
||||
DEFAULT_ENABLED_PROTOCOLS = ()
|
||||
DEFAULT_SERVE_USER_PAGES = False
|
||||
SUPPORTS_DMS = True
|
||||
|
||||
fetchable = {}
|
||||
|
|
|
|||
1
web.py
1
web.py
|
|
@ -104,6 +104,7 @@ class Web(User, Protocol):
|
|||
LOGO_HTML = '🌐' # used to be 🕸️
|
||||
CONTENT_TYPE = common.CONTENT_TYPE_HTML
|
||||
DEFAULT_ENABLED_PROTOCOLS = ('activitypub',)
|
||||
DEFAULT_SERVE_USER_PAGES = True
|
||||
SUPPORTED_AS1_TYPES = (
|
||||
tuple(as1.ACTOR_TYPES)
|
||||
+ tuple(as1.POST_TYPES)
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue