kopia lustrzana https://github.com/snarfed/bridgy-fed
remove common.ENABLED_PROTOCOLS, use Protocol.DEFAULT_ENABLED_PROTOCOLS instead
also use is_enabled_to in user page templatepull/965/head
rodzic
8bcae4c09d
commit
2886ae180d
|
@ -96,7 +96,7 @@ class ATProto(User, Protocol):
|
|||
# need to update serviceEndpoint in all users' DID docs. :/
|
||||
PDS_URL = f'https://atproto{common.SUPERDOMAIN}/'
|
||||
CONTENT_TYPE = 'application/json'
|
||||
DEFAULT_ENABLED_PROTOCOLS = ('web',)
|
||||
DEFAULT_ENABLED_PROTOCOLS = ()
|
||||
|
||||
def _pre_put_hook(self):
|
||||
"""Validate id, require did:plc or non-blocklisted did:web."""
|
||||
|
|
|
@ -31,15 +31,6 @@ TLD_BLOCKLIST = ('7z', 'asp', 'aspx', 'gif', 'html', 'ico', 'jpg', 'jpeg', 'js',
|
|||
|
||||
CONTENT_TYPE_HTML = 'text/html; charset=utf-8'
|
||||
|
||||
# Protocol pairs that we currently support bridging between. Values must be
|
||||
# Protocol LABELs. Each pair must be lexicographically sorted!
|
||||
# TODO: remove in favor of Protocol.DEFAULT_ENABLED_PROTOCOLS and
|
||||
# User.enabled_protocols
|
||||
ENABLED_BRIDGES = frozenset((
|
||||
('activitypub', 'web'),
|
||||
('atproto', 'web'),
|
||||
))
|
||||
|
||||
PRIMARY_DOMAIN = 'fed.brid.gy'
|
||||
# protocol-specific subdomains are under this "super"domain
|
||||
SUPERDOMAIN = '.brid.gy'
|
||||
|
|
|
@ -181,7 +181,10 @@ class Protocol:
|
|||
elif to_label in user.enabled_protocols:
|
||||
return True
|
||||
|
||||
return tuple(sorted((from_label, to_label))) in common.ENABLED_BRIDGES
|
||||
if to_label in from_cls.DEFAULT_ENABLED_PROTOCOLS:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def owns_id(cls, id):
|
||||
|
|
|
@ -59,9 +59,8 @@
|
|||
|
||||
{% set copies = user.copies|map(attribute='protocol')|list %}
|
||||
{% for proto in set(PROTOCOLS.values()) %}
|
||||
{% if proto and not isinstance(user, proto)
|
||||
and proto.LABEL not in ('ui', 'web')
|
||||
and (proto.LABEL not in ids.COPIES_PROTOCOLS or proto.LABEL in copies) %}
|
||||
{% if proto and not isinstance(user, proto) and proto.LABEL not in ('ui', 'web')
|
||||
and user.is_enabled_to(proto, user=user) %}
|
||||
{% set url = proto.bridged_web_url_for(user) %}
|
||||
·
|
||||
<nobr title="{{ proto.__name__ }} (bridged)">
|
||||
|
|
|
@ -443,7 +443,6 @@ class ActivityPubTest(TestCase):
|
|||
got = self.client.get('/ap/did:plc:user', base_url='https://bsky.brid.gy/')
|
||||
self.assertEqual(404, got.status_code)
|
||||
|
||||
@patch('common.ENABLED_BRIDGES', new=[('activitypub', 'atproto')])
|
||||
def test_actor_atproto_no_handle(self, *_):
|
||||
self.store_object(id='did:plc:user', raw={'foo': 'bar'})
|
||||
self.store_object(id='at://did:plc:user/app.bsky.actor.profile/self', bsky={
|
||||
|
@ -451,7 +450,7 @@ class ActivityPubTest(TestCase):
|
|||
'displayName': 'Alice',
|
||||
})
|
||||
|
||||
self.make_user('did:plc:user', cls=ATProto)
|
||||
self.make_user('did:plc:user', cls=ATProto, enabled_protocols=['activitypub'])
|
||||
|
||||
got = self.client.get('/ap/did:plc:user', base_url='https://bsky.brid.gy/')
|
||||
self.assertEqual(200, got.status_code)
|
||||
|
|
|
@ -36,7 +36,6 @@ class IntegrationTests(TestCase):
|
|||
|
||||
@patch('requests.post')
|
||||
@patch('requests.get')
|
||||
@patch('common.ENABLED_BRIDGES', new=[('activitypub', 'atproto')])
|
||||
def test_atproto_notify_reply_to_activitypub(self, mock_get, mock_post):
|
||||
"""ATProto poll notifications, deliver reply to ActivityPub.
|
||||
|
||||
|
@ -55,6 +54,7 @@ class IntegrationTests(TestCase):
|
|||
id='http://inst/bob',
|
||||
cls=ActivityPub,
|
||||
copies=[Target(uri='did:plc:bob', protocol='atproto')],
|
||||
enabled_protocols=['atproto'],
|
||||
obj_as2={
|
||||
'id': 'http://inst/bob',
|
||||
'inbox': 'http://inst/bob/inbox',
|
||||
|
@ -145,7 +145,8 @@ class IntegrationTests(TestCase):
|
|||
storage = DatastoreStorage()
|
||||
Repo.create(storage, 'did:plc:bob', signing_key=ATPROTO_KEY)
|
||||
bob = self.make_user(id='bob.com', cls=Web,
|
||||
copies=[Target(uri='did:plc:bob', protocol='atproto')])
|
||||
copies=[Target(uri='did:plc:bob', protocol='atproto')],
|
||||
enabled_protocols=['atproto'])
|
||||
|
||||
mock_get.side_effect = [
|
||||
# ATProto listNotifications
|
||||
|
@ -223,13 +224,14 @@ class IntegrationTests(TestCase):
|
|||
ATProto user alice.com (did:plc:alice)
|
||||
Follow is HTML with mf2 u-follow-of of https://bsky.app/profile/alice.com
|
||||
"""
|
||||
bob = self.make_user(id='bob.com', cls=Web, obj_mf2={
|
||||
'type': ['h-card'],
|
||||
'properties': {
|
||||
'url': ['https://bob.com/'],
|
||||
'name': ['Bob'],
|
||||
},
|
||||
})
|
||||
bob = self.make_user(id='bob.com', cls=Web, enabled_protocols=['atproto'],
|
||||
obj_mf2={
|
||||
'type': ['h-card'],
|
||||
'properties': {
|
||||
'url': ['https://bob.com/'],
|
||||
'name': ['Bob'],
|
||||
},
|
||||
})
|
||||
|
||||
# send webmention
|
||||
resp = self.post('/webmention', data={
|
||||
|
|
|
@ -173,14 +173,13 @@ class ProtocolTest(TestCase):
|
|||
self.assertTrue(Web.is_enabled_to(ActivityPub))
|
||||
self.assertTrue(ActivityPub.is_enabled_to(Web))
|
||||
self.assertTrue(ActivityPub.is_enabled_to(ActivityPub))
|
||||
self.assertTrue(ATProto.is_enabled_to(Web))
|
||||
self.assertTrue(Web.is_enabled_to(ATProto))
|
||||
self.assertTrue(Fake.is_enabled_to(OtherFake))
|
||||
self.assertTrue(Fake.is_enabled_to(ExplicitEnableFake))
|
||||
|
||||
def test_is_enabled_to_not_default_enabled(self):
|
||||
self.assertFalse(ActivityPub.is_enabled_to(ATProto))
|
||||
self.assertFalse(ATProto.is_enabled_to(ActivityPub))
|
||||
self.assertFalse(ATProto.is_enabled_to(Web))
|
||||
self.assertFalse(Web.is_enabled_to(ATProto))
|
||||
self.assertFalse(ExplicitEnableFake.is_enabled_to(Fake))
|
||||
self.assertFalse(ExplicitEnableFake.is_enabled_to(Web))
|
||||
|
||||
|
|
2
web.py
2
web.py
|
@ -98,7 +98,7 @@ class Web(User, Protocol):
|
|||
OTHER_LABELS = ('webmention',)
|
||||
LOGO_HTML = '🌐' # used to be 🕸️
|
||||
CONTENT_TYPE = common.CONTENT_TYPE_HTML
|
||||
DEFAULT_ENABLED_PROTOCOLS = ('activitypub', 'atproto')
|
||||
DEFAULT_ENABLED_PROTOCOLS = ('activitypub',)
|
||||
|
||||
has_redirects = ndb.BooleanProperty()
|
||||
redirects_error = ndb.TextProperty()
|
||||
|
|
Ładowanie…
Reference in New Issue