kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
8b3881dfe3
commit
fefcbbb77e
14
protocol.py
14
protocol.py
|
@ -340,15 +340,11 @@ class Protocol:
|
||||||
return (None, None)
|
return (None, None)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def actor_key(cls, obj, default_g_user=True):
|
def actor_key(cls, obj):
|
||||||
"""Returns the :class:`User`: key for a given object's author or actor.
|
"""Returns the :class:`User`: key for a given object's author or actor.
|
||||||
|
|
||||||
If obj has no author or actor, defaults to g.user if it's set and
|
|
||||||
``default_g_user`` is True, otherwise None.
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
obj (models.Object)
|
obj (models.Object)
|
||||||
default_g_user (bool)
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
google.cloud.ndb.key.Key or None:
|
google.cloud.ndb.key.Key or None:
|
||||||
|
@ -356,8 +352,6 @@ class Protocol:
|
||||||
owner = as1.get_owner(obj.as1)
|
owner = as1.get_owner(obj.as1)
|
||||||
if owner:
|
if owner:
|
||||||
return cls.key_for(owner)
|
return cls.key_for(owner)
|
||||||
elif default_g_user and g.user and g.user.status != 'opt-out':
|
|
||||||
return g.user.key
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def send(to_cls, obj, url, orig_obj=None):
|
def send(to_cls, obj, url, orig_obj=None):
|
||||||
|
@ -614,7 +608,7 @@ class Protocol:
|
||||||
|
|
||||||
# add owner(s)
|
# add owner(s)
|
||||||
# (actor_key returns None if the user is opted out)
|
# (actor_key returns None if the user is opted out)
|
||||||
actor_key = from_cls.actor_key(obj, default_g_user=False)
|
actor_key = from_cls.actor_key(obj)
|
||||||
if actor_key:
|
if actor_key:
|
||||||
obj.add('users', actor_key)
|
obj.add('users', actor_key)
|
||||||
if not g.user:
|
if not g.user:
|
||||||
|
@ -991,7 +985,7 @@ class Protocol:
|
||||||
|
|
||||||
logger.info(f'Target for {id} is {target}')
|
logger.info(f'Target for {id} is {target}')
|
||||||
targets[Target(protocol=protocol.LABEL, uri=target)] = orig_obj
|
targets[Target(protocol=protocol.LABEL, uri=target)] = orig_obj
|
||||||
orig_user = protocol.actor_key(orig_obj, default_g_user=False)
|
orig_user = protocol.actor_key(orig_obj)
|
||||||
if orig_user:
|
if orig_user:
|
||||||
logger.info(f'Recipient is {orig_user}')
|
logger.info(f'Recipient is {orig_user}')
|
||||||
obj.add('notify', orig_user)
|
obj.add('notify', orig_user)
|
||||||
|
@ -999,7 +993,7 @@ class Protocol:
|
||||||
logger.info(f'Direct targets: {targets.keys()}')
|
logger.info(f'Direct targets: {targets.keys()}')
|
||||||
|
|
||||||
# deliver to followers, if appropriate
|
# deliver to followers, if appropriate
|
||||||
user_key = cls.actor_key(obj, default_g_user=False)
|
user_key = cls.actor_key(obj)
|
||||||
if not user_key:
|
if not user_key:
|
||||||
logger.info("Can't tell who this is from! Skipping followers.")
|
logger.info("Can't tell who this is from! Skipping followers.")
|
||||||
return targets
|
return targets
|
||||||
|
|
|
@ -339,12 +339,7 @@ class ProtocolTest(TestCase):
|
||||||
]:
|
]:
|
||||||
self.assertEqual(expected, Fake.actor_key(obj))
|
self.assertEqual(expected, Fake.actor_key(obj))
|
||||||
|
|
||||||
g.user = user
|
self.assertIsNone(Fake.actor_key(Object()))
|
||||||
self.assertEqual(a_key, Fake.actor_key(Object()))
|
|
||||||
self.assertIsNone(Fake.actor_key(Object(), default_g_user=False))
|
|
||||||
|
|
||||||
g.user.obj.our_as1 = {'summary': '#nobot'}
|
|
||||||
self.assertIsNone(Fake.actor_key(Object(), default_g_user=True))
|
|
||||||
|
|
||||||
def test_key_for(self):
|
def test_key_for(self):
|
||||||
self.assertEqual(self.user.key, Protocol.key_for(self.user.key.id()))
|
self.assertEqual(self.user.key, Protocol.key_for(self.user.key.id()))
|
||||||
|
|
Ładowanie…
Reference in New Issue