diff --git a/zerver/openapi/python_examples.py b/zerver/openapi/python_examples.py index 15134d79a6..682fe35d3d 100644 --- a/zerver/openapi/python_examples.py +++ b/zerver/openapi/python_examples.py @@ -449,8 +449,8 @@ def add_realm_filter(client: Client) -> None: @openapi_test_function("/realm/filters/{filter_id}:patch") def update_realm_filter(client: Client) -> None: # {code_example|start} - # Update the linkifier (realm_filter) with ID 1 - filter_id = 1 + # Update the linkifier (realm_filter) with ID 4 + filter_id = 4 request = { "pattern": "#(?P[0-9]+)", "url_template": "https://github.com/zulip/zulip/issues/{id}", @@ -467,8 +467,8 @@ def update_realm_filter(client: Client) -> None: @openapi_test_function("/realm/filters/{filter_id}:delete") def remove_realm_filter(client: Client) -> None: # {code_example|start} - # Remove the linkifier (realm_filter) with ID 1 - result = client.remove_realm_filter(1) + # Remove the linkifier (realm_filter) with ID 4 + result = client.remove_realm_filter(4) # {code_example|end} validate_against_openapi_schema(result, "/realm/filters/{filter_id}", "delete", "200") diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml index 43b2bc2000..3ec6515a6c 100644 --- a/zerver/openapi/zulip.yaml +++ b/zerver/openapi/zulip.yaml @@ -10710,7 +10710,7 @@ paths: The ID of the linkifier that you want to update. schema: type: integer - example: 2 + example: 5 required: true - $ref: "#/components/parameters/LinkifierPattern" - $ref: "#/components/parameters/LinkifierURLTemplate" diff --git a/zerver/tests/test_event_system.py b/zerver/tests/test_event_system.py index 1e38591636..a86ebb728d 100644 --- a/zerver/tests/test_event_system.py +++ b/zerver/tests/test_event_system.py @@ -772,9 +772,9 @@ class FetchInitialStateDataTest(ZulipTestCase): linkifier_url_template=True, ) self.assertEqual(result["realm_filters"], []) - self.assertEqual(result["realm_linkifiers"][0]["pattern"], "#(?P[123])") + self.assertEqual(result["realm_linkifiers"][-1]["pattern"], "#(?P[123])") self.assertEqual( - result["realm_linkifiers"][0]["url_template"], + result["realm_linkifiers"][-1]["url_template"], "https://realm.com/my_realm_filter/{id}", ) diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py index 20abdbb9a8..62bab3c048 100644 --- a/zerver/tests/test_events.py +++ b/zerver/tests/test_events.py @@ -218,6 +218,7 @@ from zerver.models import ( Realm, RealmAuditLog, RealmDomain, + RealmFilter, RealmPlayground, RealmUserDefault, Service, @@ -2166,8 +2167,10 @@ class NormalActionsTest(BaseAction): ) check_realm_linkifiers("events[0]", events[0]) + linkifier_id = events[0]["realm_linkifiers"][-1]["id"] + self.assertEqual(RealmFilter.objects.get(id=linkifier_id).pattern, regex) + regex = "#(?P[0-9]+)" - linkifier_id = events[0]["realm_linkifiers"][0]["id"] events = self.verify_action( lambda: do_update_linkifier( self.user_profile.realm, linkifier_id, regex, url, acting_user=None diff --git a/zerver/tests/test_markdown.py b/zerver/tests/test_markdown.py index eb6452d5ff..bf4525b272 100644 --- a/zerver/tests/test_markdown.py +++ b/zerver/tests/test_markdown.py @@ -1453,6 +1453,7 @@ class MarkdownTest(ZulipTestCase): def test_linkifier_precedence(self) -> None: realm = self.example_user("hamlet").realm + RealmFilter.objects.filter(realm=realm).delete() # The insertion order should not affect the fact that the linkifiers are ordered by id. # Note that we might later switch to a different field to order the linkifiers. sequence = (10, 3, 11, 2, 4, 5, 6) diff --git a/zerver/tests/test_realm_linkifiers.py b/zerver/tests/test_realm_linkifiers.py index 26d5222af1..1fe625ae4f 100644 --- a/zerver/tests/test_realm_linkifiers.py +++ b/zerver/tests/test_realm_linkifiers.py @@ -7,6 +7,11 @@ from zerver.models import RealmFilter, url_template_validator class RealmFilterTest(ZulipTestCase): + def setUp(self) -> None: + super().setUp() + iago = self.example_user("iago") + RealmFilter.objects.filter(realm=iago.realm).delete() + def test_list(self) -> None: self.login("iago") data = { diff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.py index 114b5d459e..c3b358d778 100644 --- a/zilencer/management/commands/populate_db.py +++ b/zilencer/management/commands/populate_db.py @@ -26,6 +26,7 @@ from zerver.actions.custom_profile_fields import ( ) from zerver.actions.message_send import build_message_send_dict, do_send_messages from zerver.actions.realm_emoji import check_add_realm_emoji +from zerver.actions.realm_linkifiers import do_add_linkifier from zerver.actions.scheduled_messages import check_schedule_message from zerver.actions.streams import bulk_add_subscriptions from zerver.actions.user_groups import create_user_group_in_database @@ -795,6 +796,24 @@ class Command(BaseCommand): deliver_at=timezone_now() + timedelta(days=365), realm=zulip_realm, ) + do_add_linkifier( + zulip_realm, + "#D(?P[0-9]{2,8})", + "https://github.com/zulip/zulip-desktop/pull/{id}", + acting_user=None, + ) + do_add_linkifier( + zulip_realm, + "zulip-mobile#(?P[0-9]{2,8})", + "https://github.com/zulip/zulip-mobile/pull/{id}", + acting_user=None, + ) + do_add_linkifier( + zulip_realm, + "zulip-(?P[a-zA-Z-_0-9]+)#(?P[0-9]{2,8})", + "https://github.com/zulip/{repo}/pull/{id}", + acting_user=None, + ) else: zulip_realm = get_realm("zulip") recipient_streams = [