Skip to content

Commit

Permalink
drop Object.labels
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Jan 31, 2025
1 parent 087ad6a commit 0f7289b
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 54 deletions.
5 changes: 2 additions & 3 deletions follow.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ def finish(self, auth_entity, state=None):
'object': followee_id,
}
followee_user = ActivityPub.get_or_create(followee_id, obj=followee)
follow_obj = Object(id=follow_id, our_as1=follow_as1, source_protocol='ui',
labels=['user'])
follow_obj = Object(id=follow_id, our_as1=follow_as1, source_protocol='ui')

resp = Web.receive(follow_obj, authed_as=domain, internal=True)
logger.info(f'Web.receive returned {resp}')
Expand Down Expand Up @@ -216,7 +215,7 @@ def finish(self, auth_entity, state=None):
# don't include the followee User who's being unfollowed in the users
# property, since we don't want to notify or show them. (standard social
# network etiquette.)
unfollow_obj = Object(id=unfollow_id, users=[user.key], labels=['user'],
unfollow_obj = Object(id=unfollow_id, users=[user.key],
source_protocol='ui', our_as1=unfollow_as1)
resp = Web.receive(unfollow_obj, authed_as=domain, internal=True)

Expand Down
12 changes: 4 additions & 8 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,8 +967,9 @@ class Object(StringIdModel):
# domains = ndb.StringProperty(repeated=True)

# DEPRECATED; replaced by :attr:`users`, :attr:`notify`, :attr:`feed`
labels = ndb.StringProperty(repeated=True,
choices=('activity', 'feed', 'notification', 'user'))
#
# labels = ndb.StringProperty(repeated=True,
# choices=('activity', 'feed', 'notification', 'user'))

@property
def as1(self):
Expand Down Expand Up @@ -1068,11 +1069,6 @@ def _pre_put_hook(self):
raise ValueError(
f'at:// URI ids must have DID repos; got {id}')

if self.as1 and self.as1.get('objectType') == 'activity':
self.add('labels', 'activity')
elif 'activity' in self.labels:
self.remove('labels', 'activity')

if self.as2:
self.as2.pop('@context', None)
for field in 'actor', 'attributedTo', 'author', 'object':
Expand Down Expand Up @@ -1163,7 +1159,7 @@ def get_or_create(cls, id, authed_as=None, **props):
dirty = False
for prop, val in props.items():
assert not isinstance(getattr(Object, prop), ndb.ComputedProperty)
if prop in ('feed', 'copies', 'labels', 'notify', 'users'):
if prop in ('feed', 'copies', 'notify', 'users'):
# merge repeated fields
for elem in val:
if obj.add(prop, elem):
Expand Down
2 changes: 0 additions & 2 deletions tests/test_follow.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ def check(self, input, resp, expected_follow, mock_get, mock_post,
self.assert_object(follow_id,
users=[self.user.key],
notify=[followee],
labels=['user', 'activity'],
source_protocol='ui',
our_as1=expected_follow_as1,
)
Expand Down Expand Up @@ -439,7 +438,6 @@ def test_callback_user_use_instead(self, mock_get, mock_post):
followee = ActivityPub(id='https://ba.r/id').key
follow_obj = self.assert_object(id, users=[user.key],
notify=[followee],
labels=['user', 'activity'],
source_protocol='ui',
our_as1=expected_follow_as1,
)
Expand Down
32 changes: 5 additions & 27 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,20 +646,19 @@ def check(obj1, obj2):
obj7 = Object.get_or_create('http://b.ee/ff', as2={'a': 'b'}, mf2={'c': 'd'},
source_protocol='web')
Object.get_or_create('http://b.ee/ff', authed_as='http://b.ee/ff',
users=[ndb.Key(Web, 'me')], labels=['feed'],
users=[ndb.Key(Web, 'me')],
copies=[Target(protocol='ui', uri='http://foo')])
self.assert_object('http://b.ee/ff', as2={'a': 'b'}, mf2={'c': 'd'},
users=[ndb.Key(Web, 'me')], labels=['feed'],
copies=[Target(protocol='ui', uri='http://foo')],
source_protocol='web')
users=[ndb.Key(Web, 'me')], source_protocol='web',
copies=[Target(protocol='ui', uri='http://foo')])

# repeated properties should merge, not overwrite
Object.get_or_create('http://b.ee/ff', authed_as='http://b.ee/ff',
users=[ndb.Key(Web, 'you')], labels=['user'],
users=[ndb.Key(Web, 'you')],
copies=[Target(protocol='ui', uri='http://bar')])
self.assert_object('http://b.ee/ff', as2={'a': 'b'}, mf2={'c': 'd'},
users=[ndb.Key(Web, 'me'), ndb.Key(Web, 'you')],
labels=['feed', 'user'], source_protocol='web',
source_protocol='web',
copies=[Target(protocol='ui', uri='http://foo'),
Target(protocol='ui', uri='http://bar')])

Expand Down Expand Up @@ -818,27 +817,6 @@ def test_expire(self):
obj.deleted = True
self.assertEqual(NOW + OBJECT_EXPIRE_AGE, obj.expire)

def test_put_adds_removes_activity_label(self):
obj = Object(id='x#y', our_as1={})
obj.put()
self.assertEqual([], obj.labels)

obj.our_as1 = {'objectType': 'activity'}
obj.put()
self.assertEqual(['activity'], obj.labels)

obj.labels = ['user']
obj.put()
self.assertEqual(['user', 'activity'], obj.labels)

obj.labels = ['activity', 'user']
obj.put()
self.assertEqual(['activity', 'user'], obj.labels)

obj.our_as1 = {'foo': 'bar'}
obj.put()
self.assertEqual(['user'], obj.labels)

def test_as1_from_as2(self):
self.assert_equals({
'objectType': 'person',
Expand Down
5 changes: 2 additions & 3 deletions tests/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,14 @@ def test_user_use_instead(self):
self.assert_equals(200, got.status_code)

def test_user_object_bare_string_id(self):
Object(id='a', users=[self.user.key], labels=['notification'],
as2=REPOST_AS2).put()
Object(id='a', users=[self.user.key], as2=REPOST_AS2).put()

got = self.client.get('/web/user.com')
self.assert_equals(200, got.status_code)

def test_user_object_url_object(self):
with self.request_context:
Object(id='a', users=[self.user.key], labels=['notification'], our_as1={
Object(id='a', users=[self.user.key], our_as1={
**REPOST_AS2,
'object': {
'id': 'https://mas.to/toot/id',
Expand Down
10 changes: 0 additions & 10 deletions tests/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,6 @@ def test_bad_target_url(self, mock_get, mock_post):
source_protocol='web',
type='comment',
users=[self.user.key],
labels=[],
ignore=['mf2', 'our_as1'],
)

Expand Down Expand Up @@ -1004,7 +1003,6 @@ def _test_repost(self, html, expected_as2, mock_get, mock_post):
source_protocol='web',
mf2=mf2,
type='share',
labels=['user', 'activity', 'notification', 'feed'],
ignore=['our_as1'],
)

Expand Down Expand Up @@ -1062,7 +1060,6 @@ def test_like_stored_object(self, mock_get, mock_post):
source_protocol='web',
mf2=LIKE_MF2,
type='like',
labels=['activity', 'user'],
ignore=['our_as1'],
)

Expand Down Expand Up @@ -1207,7 +1204,6 @@ def test_create_no_author(self, mock_get, mock_post):
source_protocol='web',
mf2=repost_mf2, # includes author https://user.com/
type='share',
labels=['activity', 'user'],
notify=[ndb.Key('ActivityPub', 'https://mas.to/author')],
ignore=['our_as1'],
)
Expand Down Expand Up @@ -1237,7 +1233,6 @@ def test_create_non_domain_author(self, mock_get, mock_post):
our_as1=NOTE_AS1,
type='note',
users=[self.user.key],
labels=['activity', 'user'],
ignore=['feed'],
)

Expand Down Expand Up @@ -1333,7 +1328,6 @@ def test_update_post(self, mock_get, mock_post):
},
type='note',
users=[self.user.key],
labels=['user'],
ignore=['feed'],
)

Expand Down Expand Up @@ -1390,7 +1384,6 @@ def test_follow(self, mock_get, mock_post):
source_protocol='web',
our_as1=follow_as1,
type='follow',
labels=['user', 'activity', 'notification'],
ignore=['our_as1'],
)

Expand Down Expand Up @@ -1489,7 +1482,6 @@ def test_follow_fragment(self, mock_get, mock_post):
source_protocol='web',
mf2=FOLLOW_FRAGMENT_MF2,
type='follow',
labels=['user', 'activity', 'notification'],
ignore=['our_as1'],
)

Expand Down Expand Up @@ -1554,7 +1546,6 @@ def test_follow_multiple(self, mock_get, mock_post):
source_protocol='web',
mf2=mf2,
type='follow',
labels=['user', 'activity', 'notification',],
ignore=['our_as1'],
)

Expand Down Expand Up @@ -1676,7 +1667,6 @@ def test_inbox_delivery_error(self, mock_get, mock_post):
source_protocol='web',
mf2=FOLLOW_MF2,
type='follow',
labels=['user', 'activity', 'notification',],
ignore=['our_as1'],
)

Expand Down
2 changes: 1 addition & 1 deletion tests/testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ def assert_object(self, id, **props):
got.mf2.pop('url', None)

self.assert_entities_equal(Object(id=id, **props), got,
ignore=['as1', 'created', 'expire', 'labels',
ignore=['as1', 'created', 'expire',
'type', 'updated'] + ignore)
return got

Expand Down

0 comments on commit 0f7289b

Please sign in to comment.