kopia lustrzana https://github.com/snarfed/bridgy-fed
start clearing Object.our_as1 again on updates
fixes #778. bug was that when we fetched a web object, we'd populate the new `mf2` value, but still keep the old `our_as1`, which then overrode it in `as1`. ugh.
partially reverts commit 62ca4022fb
for #721.
pull/781/head
rodzic
178b5ccde3
commit
bab5270c3b
|
@ -756,6 +756,8 @@ class Object(StringIdModel):
|
|||
obj = Object(id=id)
|
||||
obj.new = True
|
||||
|
||||
if set(props.keys()) & set(('our_as2', 'bsky', 'mf2', 'raw')):
|
||||
obj.clear()
|
||||
obj.populate(**{
|
||||
k: v for k, v in props.items()
|
||||
if v and not isinstance(getattr(Object, k), ndb.ComputedProperty)
|
||||
|
@ -792,6 +794,11 @@ class Object(StringIdModel):
|
|||
with self.lock:
|
||||
getattr(self, prop).remove(val)
|
||||
|
||||
def clear(self):
|
||||
"""Clears the :attr:`Object.our_as1` properties."""
|
||||
with self.lock:
|
||||
self.our_as1 = None
|
||||
|
||||
def activity_changed(self, other_as1):
|
||||
"""Returns True if this activity is meaningfully changed from ``other_as1``.
|
||||
|
||||
|
|
|
@ -1128,6 +1128,7 @@ class Protocol:
|
|||
return obj
|
||||
|
||||
if obj:
|
||||
obj.clear()
|
||||
obj.new = False
|
||||
else:
|
||||
obj = Object(id=id)
|
||||
|
|
|
@ -1254,6 +1254,7 @@ class ActivityPubTest(TestCase):
|
|||
self.assertEqual(401, resp.status_code, resp.get_data(as_text=True))
|
||||
|
||||
# valid signature, Object has our_as1 instead of as2
|
||||
self.key_id_obj.clear()
|
||||
self.key_id_obj.our_as1 = as2.to_as1(actor_as2)
|
||||
self.key_id_obj.put()
|
||||
resp = self.client.post('/ap/sharedInbox', data=body, headers=headers)
|
||||
|
|
|
@ -29,7 +29,7 @@ from web import Web
|
|||
|
||||
from .test_activitypub import ACTOR
|
||||
from .test_atproto import DID_DOC
|
||||
from .test_web import ACTOR_HTML
|
||||
from .test_web import ACTOR_HTML_RESP, ACTOR_AS1_UNWRAPPED_URLS, ACTOR_MF2_REL_URLS
|
||||
|
||||
|
||||
class ProtocolTest(TestCase):
|
||||
|
@ -263,6 +263,23 @@ class ProtocolTest(TestCase):
|
|||
self.assertFalse(loaded.new)
|
||||
self.assertEqual(['foo'], Fake.fetched)
|
||||
|
||||
@patch('requests.get', return_value=ACTOR_HTML_RESP)
|
||||
def test_load_remote_true_clear_our_as1(self, _):
|
||||
self.store_object(id='https://foo', our_as1={'should': 'disappear'},
|
||||
source_protocol='web')
|
||||
|
||||
expected_mf2 = {
|
||||
**ACTOR_MF2_REL_URLS,
|
||||
'url': 'https://user.com/',
|
||||
}
|
||||
|
||||
loaded = Web.load('https://foo', remote=True)
|
||||
self.assertEqual(expected_mf2, loaded.mf2)
|
||||
self.assertIsNone(loaded.our_as1)
|
||||
self.assertEqual(ACTOR_AS1_UNWRAPPED_URLS, loaded.as1)
|
||||
self.assertTrue(loaded.changed)
|
||||
self.assertFalse(loaded.new)
|
||||
|
||||
def test_load_remote_false(self):
|
||||
self.assertIsNone(Fake.load('nope', remote=False))
|
||||
self.assertEqual([], Fake.fetched)
|
||||
|
|
|
@ -72,6 +72,10 @@ ACTOR_AS1_UNWRAPPED = {
|
|||
'url': 'https://user.com/',
|
||||
'displayName': 'Ms. ☕ Baz',
|
||||
}
|
||||
ACTOR_AS1_UNWRAPPED_URLS = {
|
||||
**ACTOR_AS1_UNWRAPPED,
|
||||
'urls': [{'value': 'https://user.com/', 'displayName': 'Ms. ☕ Baz'}],
|
||||
}
|
||||
ACTOR_AS2 = {
|
||||
'type': 'Person',
|
||||
'id': 'http://localhost/user.com',
|
||||
|
@ -662,7 +666,7 @@ class WebTest(TestCase):
|
|||
source_protocol='web',
|
||||
type='comment',
|
||||
labels=[],
|
||||
ignore=['our_as1', 'mf2'],
|
||||
ignore=['mf2', 'our_as1'],
|
||||
)
|
||||
self.assert_object('https://user.com/reply#bridgy-fed-create',
|
||||
source_protocol='web',
|
||||
|
@ -2425,10 +2429,7 @@ class WebUtilTest(TestCase):
|
|||
**ACTOR_MF2_REL_URLS,
|
||||
'url': 'https://user.com/',
|
||||
}, obj.mf2)
|
||||
self.assert_equals({
|
||||
**ACTOR_AS1_UNWRAPPED,
|
||||
'urls': [{'value': 'https://user.com/', 'displayName': 'Ms. ☕ Baz'}],
|
||||
}, obj.as1)
|
||||
self.assert_equals(ACTOR_AS1_UNWRAPPED_URLS, obj.as1)
|
||||
|
||||
def test_fetch_user_homepage_metaformats(self, mock_get, __):
|
||||
mock_get.return_value = requests_response(
|
||||
|
|
Ładowanie…
Reference in New Issue