diff --git a/convert.py b/convert.py index e769081..bd52f70 100644 --- a/convert.py +++ b/convert.py @@ -3,7 +3,7 @@ URL pattern is /convert/SOURCE/DEST , where SOURCE and DEST are the LABEL constants from the :class:`Protocol` subclasses. -Currently only supports /convert/activitypub/webmention/... +Currently only supports /convert/activitypub/web/... """ import logging import re @@ -78,4 +78,4 @@ def convert(src, dest, _): def render_redirect(): """Redirect from old /render?id=... endpoint to /convert/...""" id = flask_util.get_required_param('id') - return redirect(f'/convert/activitypub/webmention/{id}', code=301) + return redirect(f'/convert/activitypub/web/{id}', code=301) diff --git a/models.py b/models.py index 87ac173..9a87395 100644 --- a/models.py +++ b/models.py @@ -387,13 +387,13 @@ class Object(StringIdModel): """ assert '^^' not in self.key.id() id = self.key.id().replace('#', '^^') - return common.host_url(f'convert/{self.source_protocol}/webmention/{id}') + return common.host_url(f'convert/{self.source_protocol}/web/{id}') def actor_link(self): """Returns a pretty actor link with their name and profile picture.""" attrs = {'class': 'h-card u-author'} - if (self.source_protocol in ('webmention', 'ui') and g.user and + if (self.source_protocol in ('web', 'webmention', 'ui') and g.user and g.user.key.id() in self.domains): # outbound; show a nice link to the user return g.user.user_page_link() diff --git a/pages.py b/pages.py index b76f77c..9b3b033 100644 --- a/pages.py +++ b/pages.py @@ -314,10 +314,10 @@ def nodeinfo(): # 'activeMonth': # 'activeHalfyear': }, - 'localPosts': Object.query(Object.source_protocol == 'webmention', + 'localPosts': Object.query(Object.source_protocol.IN(('web', 'webmention')), Object.type.IN(['note', 'article']), ).count(), - 'localComments': Object.query(Object.source_protocol == 'webmention', + 'localComments': Object.query(Object.source_protocol.IN(('web', 'webmention')), Object.type == 'comment', ).count(), }, diff --git a/protocol.py b/protocol.py index fd165de..580074f 100644 --- a/protocol.py +++ b/protocol.py @@ -328,7 +328,7 @@ class Protocol: # send webmentions and update Object errors = [] # stores (code, body) tuples - targets = [Target(uri=uri, protocol='webmention') for uri in targets] + targets = [Target(uri=uri, protocol='web') for uri in targets] obj.populate( undelivered=targets, diff --git a/tests/test_activitypub.py b/tests/test_activitypub.py index 9404e3f..fb8fb65 100644 --- a/tests/test_activitypub.py +++ b/tests/test_activitypub.py @@ -244,7 +244,7 @@ class ActivityPubTest(TestCase): self.key_id_obj.put() def assert_object(self, id, **props): - return super().assert_object(id, delivered_protocol='webmention', **props) + return super().assert_object(id, delivered_protocol='web', **props) def sign(self, path, body): """Constructs HTTP Signature, returns headers.""" @@ -356,7 +356,7 @@ class ActivityPubTest(TestCase): headers={'Accept': '*/*'}, allow_redirects=False, data={ - 'source': f'http://localhost/convert/activitypub/webmention/{convert_id}', + 'source': f'http://localhost/convert/activitypub/web/{convert_id}', 'target': 'https://user.com/post', }, ) @@ -448,7 +448,7 @@ class ActivityPubTest(TestCase): headers={'Accept': '*/*'}, allow_redirects=False, data={ - 'source': f'http://localhost/convert/activitypub/webmention/{convert_id}', + 'source': f'http://localhost/convert/activitypub/web/{convert_id}', 'target': orig_url, }, ) @@ -573,7 +573,7 @@ class ActivityPubTest(TestCase): headers={'Accept': '*/*'}, allow_redirects=False, data={ - 'source': f'http://localhost/convert/activitypub/webmention/{convert_id}', + 'source': f'http://localhost/convert/activitypub/web/{convert_id}', 'target': 'https://tar.get/', }, ) @@ -607,7 +607,7 @@ class ActivityPubTest(TestCase): args, kwargs = mock_post.call_args self.assertEqual(('https://user.com/webmention',), args) self.assertEqual({ - 'source': 'http://localhost/convert/activitypub/webmention/http:/mas.to/like^^ok', + 'source': 'http://localhost/convert/activitypub/web/http:/mas.to/like^^ok', 'target': 'https://user.com/post', }, kwargs['data']) @@ -702,7 +702,7 @@ class ActivityPubTest(TestCase): args, kwargs = mock_post.call_args_list[1] self.assertEqual(('https://user.com/webmention',), args) self.assertEqual({ - 'source': 'http://localhost/convert/activitypub/webmention/https:/mas.to/6d1a', + 'source': 'http://localhost/convert/activitypub/web/https:/mas.to/6d1a', 'target': 'https://user.com/', }, kwargs['data']) @@ -1328,7 +1328,7 @@ class ActivityPubUtilsTest(TestCase): self.assert_equals(AS2_OBJ, got.as2) mock_get.assert_has_calls([self.as2_req(id)]) - self.assert_object(id, delivered_protocol='webmention', + self.assert_object(id, delivered_protocol='web', as2=AS2_OBJ, as1=AS2_OBJ, source_protocol='activitypub', # check that it reused our original Object diff --git a/tests/test_convert.py b/tests/test_convert.py index 86983d6..ffb01d1 100644 --- a/tests/test_convert.py +++ b/tests/test_convert.py @@ -64,7 +64,7 @@ EXPECTED_AUTHOR_HTML = """\ class ConvertTest(testutil.TestCase): def test_unknown_source(self): - resp = self.client.get('/convert/nope/webmention/http://foo') + resp = self.client.get('/convert/nope/web/http://foo') self.assertEqual(404, resp.status_code) def test_unknown_dest(self): @@ -72,11 +72,11 @@ class ConvertTest(testutil.TestCase): self.assertEqual(404, resp.status_code) def test_missing_url(self): - resp = self.client.get('/convert/activitypub/webmention/') + resp = self.client.get('/convert/activitypub/web/') self.assertEqual(404, resp.status_code) def test_url_not_web(self): - resp = self.client.get('/convert/activitypub/webmention/git+ssh://foo/bar') + resp = self.client.get('/convert/activitypub/web/git+ssh://foo/bar') self.assertEqual(400, resp.status_code) def test_activitypub_to_web_object(self): @@ -84,7 +84,7 @@ class ConvertTest(testutil.TestCase): with self.request_context: Object(id=url, our_as1=COMMENT).put() - resp = self.client.get('/convert/activitypub/webmention/https://user.com/bar?baz=baj&biff') + resp = self.client.get('/convert/activitypub/web/https://user.com/bar?baz=baj&biff') self.assertEqual(200, resp.status_code) self.assert_multiline_equals(EXPECTED_HTML, resp.get_data(as_text=True), ignore_blanks=True) @@ -93,7 +93,7 @@ class ConvertTest(testutil.TestCase): with self.request_context: Object(id='http://foo').put() - resp = self.client.get('/convert/activitypub/webmention/http://foo') + resp = self.client.get('/convert/activitypub/web/http://foo') self.assertEqual(404, resp.status_code) @patch('requests.get') @@ -101,7 +101,7 @@ class ConvertTest(testutil.TestCase): mock_get.return_value = self.as2_resp(as2.from_as1(COMMENT)) url = 'https://user.com/bar?baz=baj&biff' - resp = self.client.get(f'/convert/activitypub/webmention/{url}') + resp = self.client.get(f'/convert/activitypub/web/{url}') self.assertEqual(200, resp.status_code) self.assertEqual(CONTENT_TYPE_HTML, resp.content_type) self.assert_multiline_equals(EXPECTED_HTML, resp.get_data(as_text=True), @@ -113,7 +113,7 @@ class ConvertTest(testutil.TestCase): def test_activitypub_to_web_fetch_fails(self, mock_get): mock_get.side_effect = [requests_response('', status=405)] - resp = self.client.get('/convert/activitypub/webmention/http://foo') + resp = self.client.get('/convert/activitypub/web/http://foo') self.assertEqual(502, resp.status_code) mock_get.assert_has_calls((self.as2_req('http://foo'),)) @@ -124,7 +124,7 @@ class ConvertTest(testutil.TestCase): Object(id='http://bar', our_as1=ACTOR, source_protocol='activitypub').put() - resp = self.client.get('/convert/activitypub/webmention/http://foo') + resp = self.client.get('/convert/activitypub/web/http://foo') self.assertEqual(200, resp.status_code) self.assert_multiline_equals(EXPECTED_AUTHOR_HTML, resp.get_data(as_text=True), ignore_blanks=True) @@ -135,7 +135,7 @@ class ConvertTest(testutil.TestCase): with self.request_context: Object(id='http://foo', our_as1=comment).put() - resp = self.client.get('/convert/activitypub/webmention/http://foo') + resp = self.client.get('/convert/activitypub/web/http://foo') self.assertEqual(200, resp.status_code) expected = EXPECTED_HTML.replace( '\n', '' @@ -147,14 +147,14 @@ class ConvertTest(testutil.TestCase): with self.request_context: Object(id='http://foo', as2={'content': 'foo'}, deleted=True).put() - resp = self.client.get('/convert/activitypub/webmention/http://foo') + resp = self.client.get('/convert/activitypub/web/http://foo') self.assertEqual(410, resp.status_code) def test_activitypub_to_web_delete_activity(self): with self.request_context: Object(id='http://foo', our_as1=DELETE_OF_ID).put() - resp = self.client.get('/convert/activitypub/webmention/http://foo') + resp = self.client.get('/convert/activitypub/web/http://foo') self.assertEqual(410, resp.status_code) def test_activitypub_to_web_update_inner_obj_exists_redirect(self): @@ -163,9 +163,9 @@ class ConvertTest(testutil.TestCase): Object(id='http://foo', our_as1=UPDATE).put() Object(id=UPDATE['object']['id'], as2={'content': 'foo'}).put() - resp = self.client.get('/convert/activitypub/webmention/http://foo') + resp = self.client.get('/convert/activitypub/web/http://foo') self.assertEqual(301, resp.status_code) - self.assertEqual(f'/convert/activitypub/webmention/tag:fake.com:123456', + self.assertEqual(f'/convert/activitypub/web/tag:fake.com:123456', resp.headers['Location']) def test_activitypub_to_web_delete_inner_obj_exists_redirect(self): @@ -174,9 +174,9 @@ class ConvertTest(testutil.TestCase): Object(id='http://foo', our_as1=DELETE_OF_ID).put() Object(id=DELETE_OF_ID['object'], as2={'content': 'foo'}).put() - resp = self.client.get('/convert/activitypub/webmention/http://foo') + resp = self.client.get('/convert/activitypub/web/http://foo') self.assertEqual(301, resp.status_code) - self.assertEqual(f'/convert/activitypub/webmention/tag:fake.com:123456', + self.assertEqual(f'/convert/activitypub/web/tag:fake.com:123456', resp.headers['Location']) def test_activitypub_to_web_update_no_inner_obj_serve_as_is(self): @@ -184,7 +184,7 @@ class ConvertTest(testutil.TestCase): # UPDATE's object field is a full object Object(id='http://foo', our_as1=UPDATE).put() - resp = self.client.get('/convert/activitypub/webmention/http://foo') + resp = self.client.get('/convert/activitypub/web/http://foo') self.assertEqual(200, resp.status_code) self.assert_multiline_in("""\