follow UI: specific error message for trying to follow bridged accounts

thanks for the nudge @campegg!
pull/804/head
Ryan Barrett 2024-01-24 19:20:54 -08:00
rodzic 131f9322f9
commit 3bcef0d37d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
7 zmienionych plików z 38 dodań i 14 usunięć

Wyświetl plik

@ -63,6 +63,7 @@ class ActivityPub(User, Protocol):
Key id is AP/AS2 actor id URL. (*Not* fediverse/WebFinger @-@ handle!)
"""
ABBREV = 'ap'
PHRASE = 'the fediverse'
LOGO_HTML = '<img src="/static/fediverse_logo.svg">'
CONTENT_TYPE = as2.CONTENT_TYPE
HAS_FOLLOW_ACCEPTS = True

Wyświetl plik

@ -57,6 +57,7 @@ class ATProto(User, Protocol):
https://atproto.com/specs/did
"""
ABBREV = 'atproto'
PHRASE = 'Bluesky'
LOGO_HTML = '<img src="/static/atproto_logo.png">'
PDS_URL = f'https://{ABBREV}{common.SUPERDOMAIN}/'
CONTENT_TYPE = 'application/json'

Wyświetl plik

@ -16,6 +16,7 @@ from activitypub import ActivityPub
from flask_app import app
import common
from models import Follower, Object, PROTOCOLS
from protocol import Protocol
from web import Web
import webfinger
@ -98,17 +99,19 @@ class FollowCallback(indieauth.Callback):
addr = state
if util.is_web(addr):
as2_url = addr
if ActivityPub.owns_id(as2_url) is False:
flash(f"{as2_url} isn't a native fediverse account")
return redirect(user.user_page_path('following'))
else: # it's an @-@ handle
if ActivityPub.owns_handle(addr) is False:
flash(f"{addr} isn't a native fediverse account")
return redirect(user.user_page_path('following'))
# if ActivityPub.owns_handle(addr) is False:
# flash(f"{addr} isn't a native fediverse account")
# return redirect(user.user_page_path('following'))
as2_url = webfinger.fetch_actor_url(addr)
if ActivityPub.owns_id(as2_url) is False:
flash(f"{addr} isn't a native fediverse account")
return redirect(user.user_page_path('following'))
if util.domain_or_parent_in(util.domain_from_link(as2_url), common.DOMAINS):
proto = Protocol.for_id(as2_url)
flash(f"{addr} is a bridged account. Try following them on {proto.PHRASE}!")
return redirect(user.user_page_path('following'))
elif ActivityPub.owns_id(as2_url) is False:
flash(f"{addr} isn't a native fediverse account")
return redirect(user.user_page_path('following'))
# TODO(#512): follower will always be Web here, but we should generalize
# followee support in UI and here across protocols

Wyświetl plik

@ -57,6 +57,8 @@ class Protocol:
LABEL (str): human-readable lower case name
OTHER_LABELS (list of str): label aliases
ABBREV (str): lower case abbreviation, used in URL paths
PHRASE (str): human-readable name or phrase. Used in phrases like
``Follow this person on {PHRASE}``
LOGO_HTML (str): logo emoji or ``<img>`` tag
CONTENT_TYPE (str): MIME type of this protocol's native data format,
appropriate for the ``Content-Type`` HTTP header.
@ -64,6 +66,7 @@ class Protocol:
accept/reject activities in response to follows, eg ActivityPub
"""
ABBREV = None
PHRASE = None
OTHER_LABELS = ()
LOGO_HTML = ''
CONTENT_TYPE = None

Wyświetl plik

@ -246,15 +246,28 @@ class FollowTest(TestCase):
def test_callback_bridged_account_error(self, mock_get, mock_post):
mock_post.return_value = requests_response('me=https://alice.com')
mock_get.side_effect = [
requests_response(''), # indieauth https://alice.com fetch for user json
requests_response({ # webfinger
'subject': 'acct:bob.com@web.brid.gy',
'aliases': ['https://bob.com/'],
'links': [{
'rel': 'self',
'type': as2.CONTENT_TYPE,
'href': 'https://web.brid.gy/bob.com',
}],
}),
]
self.state['state'] = '@example.com@web.brid.gy'
self.state['state'] = '@bob.com@web.brid.gy'
state = util.encode_oauth_state(self.state)
resp = self.client.get(f'/follow/callback?code=my_code&state={state}')
self.assertEqual(302, resp.status_code)
self.assertEqual('/web/alice.com/following', resp.headers['Location'])
self.assertEqual(["@example.com@web.brid.gy isn't a native fediverse account"],
get_flashed_messages())
self.assertEqual(
["@bob.com@web.brid.gy is a bridged account. Try following them on the web!"],
get_flashed_messages())
def test_callback_upgraded_bridged_account_error(self, mock_get, mock_post):
mock_post.return_value = requests_response('me=https://alice.com')
@ -279,8 +292,9 @@ class FollowTest(TestCase):
self.assertEqual(302, resp.status_code)
self.assertEqual('/web/alice.com/following', resp.headers['Location'])
self.assertEqual(["@bob.com@bob.com isn't a native fediverse account"],
get_flashed_messages())
self.assertEqual(
["@bob.com@bob.com is a bridged account. Try following them on the web!"],
get_flashed_messages())
def check(self, input, resp, expected_follow, mock_get, mock_post,
fetched_followee=True):

Wyświetl plik

@ -66,6 +66,7 @@ COMMENT = {
class Fake(User, protocol.Protocol):
ABBREV = 'fa'
PHRASE = 'fake-phrase'
CONTENT_TYPE = 'fa/ke'
# maps string ids to dict AS1 objects that can be fetched

1
web.py
Wyświetl plik

@ -92,6 +92,7 @@ class Web(User, Protocol):
The key name is the domain.
"""
ABBREV = 'web'
PHRASE = 'the web'
OTHER_LABELS = ('webmention',)
LOGO_HTML = '🌐' # used to be 🕸️
CONTENT_TYPE = common.CONTENT_TYPE_HTML