Skip to content

Commit

Permalink
DM to request bridging: require that requesting user is bridged
Browse files Browse the repository at this point in the history
for #966
  • Loading branch information
snarfed committed Aug 19, 2024
1 parent ff57074 commit a232cd4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 13 deletions.
5 changes: 5 additions & 0 deletions dms.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def receive(*, from_user, obj):
return 'OK', 200

elif to_proto.owns_handle(content) is not False:
if not from_user.is_enabled(to_proto):
maybe_send(from_proto=to_proto, to_user=from_user, text=f'Please bridge your account to {to_proto.PHRASE} by following this account before requesting another user.')
return 'OK', 200

if to_id := to_proto.handle_to_id(content):
if to_user := to_proto.get_or_create(to_id):
maybe_send(from_proto=from_user, to_user=to_user,
Expand All @@ -116,3 +120,4 @@ def receive(*, from_user, obj):
<p>Bridgy Fed will only send you this message once.""")
return 'OK', 200

return "Couldn't understand DM: foo bar", 304
61 changes: 48 additions & 13 deletions tests/test_dms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@

from .testutil import ExplicitEnableFake, Fake, OtherFake, TestCase

DM_EEFAKE_ALICE_REQUESTS_OTHER_BOB = {
'objectType': 'note',
'id': 'eefake:dm',
'actor': 'eefake:alice',
'to': ['other.brid.gy'],
'content': ' other:handle:bob ',
}


class DmsTest(TestCase):
def test_maybe_send(self):
Expand Down Expand Up @@ -56,7 +64,19 @@ def test_maybe_send_user_missing_obj(self):
self.assertEqual([], OtherFake.sent)
self.assertEqual([], user.sent_dms)

# def test_receive_unknown_text(self):
def test_receive_unknown_text(self):
self.make_user(id='other.brid.gy', cls=Web)
alice = self.make_user('eefake:alice', cls=ExplicitEnableFake,
enabled_protocols=['other'], obj_id='eefake:alice')

obj = Object(our_as1={
**DM_EEFAKE_ALICE_REQUESTS_OTHER_BOB,
'content': 'foo bar',
})
self.assertEqual(("Couldn't understand DM: foo bar", 304),
receive(from_user=alice, obj=obj))
self.assertEqual([], OtherFake.sent)
self.assertEqual([], Fake.sent)

def test_receive_no_yes_sets_enabled_protocols(self):
alice = self.make_user('fake:alice', cls=Fake, obj_id='fake:alice')
Expand Down Expand Up @@ -115,31 +135,46 @@ def test_receive_no_yes_sets_enabled_protocols(self):
Fake.sent)

def test_receive_handle_sends_request_dm(self):
self.make_user(id='other.brid.gy', cls=Web)
self.make_user(id='eefake.brid.gy', cls=Web)
alice = self.make_user(id='eefake:alice', cls=ExplicitEnableFake,
enabled_protocols=['other'], obj_as1={'x': 'y'})
bob = self.make_user(id='other:bob', cls=OtherFake, obj_as1={'x': 'y'})

dm = Object(our_as1={
'objectType': 'note',
'id': 'eefake:dm',
'actor': 'eefake:alice',
'to': ['other.brid.gy'],
'content': ' other:handle:bob ',
})
self.assertEqual(('OK', 200), receive(from_user=alice, obj=dm))
obj = Object(our_as1=DM_EEFAKE_ALICE_REQUESTS_OTHER_BOB)
self.assertEqual(('OK', 200), receive(from_user=alice, obj=obj))
self.assertEqual(
[('https://eefake.brid.gy/#request_bridging-dm-other:bob-2022-01-02T03:04:05+00:00',
'other:bob:target')],
OtherFake.sent)

# def test_receive_handle_from_user_not_bridged(self):
def test_receive_handle_from_user_not_bridged(self):
self.make_user(id='other.brid.gy', cls=Web)
# Alice isn't bridged into OtherFake
alice = self.make_user(id='eefake:alice', cls=ExplicitEnableFake,
enabled_protocols=['fake'], obj_as1={'x': 'y'})
self.make_user(id='other:bob', cls=OtherFake, obj_as1={'x': 'y'})

obj = Object(our_as1=DM_EEFAKE_ALICE_REQUESTS_OTHER_BOB)
self.assertEqual(('OK', 200), receive(from_user=alice, obj=obj))
self.assertEqual([], OtherFake.sent)
self.assertEqual([], Fake.sent)

# def test_receive_handle_already_bridged(self):

# def test_receive_handle_fetch_user(self):
# def test_receive_handle_already_requested(self):

def test_receive_handle_wrong_protocol(self):
self.make_user(id='other.brid.gy', cls=Web)

# def test_receive_handle_wrong_protocol(self):
obj = Object(our_as1={
**DM_EEFAKE_ALICE_REQUESTS_OTHER_BOB,
'content': 'fake:eve',
})
self.assertEqual(("Couldn't understand DM: foo bar", 304),
receive(from_user=Fake(id='fake:user'), obj=obj))
self.assertEqual([], OtherFake.sent)
self.assertEqual([], Fake.sent)

# def test_receive_handle_fetch_user(self):

# def test_receive_handle_user_doesnt_exist(self):

5 comments on commit a232cd4

@mackuba
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this requirement? I'm thinking that there might be e.g. some people on Mastodon who want to follow a bunch of Bluesky accounts, but don't want themselves to appear on Bluesky too?

@snarfed
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True! I don't have a strong argument, I guess the idea was equity. If you're asking someone to bridge their account, you should be comfortable bridging your account too, as a sign of good faith. I could reconsider though!

@mackuba
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don't have a strong feeling about this, that's also a good point. I just wanted to test the new feature from my Mastodon account, which I don't want to bridge because it's mostly cross-posting my Bluesky account which is already bridged :)

@mackuba
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think different people might use these platforms in very different ways, sometimes with multiple accounts on them for different purposes (I have no idea how (un)common this is though)

@snarfed
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alt accounts, definitely!

Please sign in to comment.