From f5a3ea8a4b09c1bcea9982c0f168fe562fa7cd60 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Tue, 24 May 2022 14:23:25 +0100 Subject: [PATCH 1/4] Run msc3787 tests in complement --- scripts-dev/complement.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts-dev/complement.sh b/scripts-dev/complement.sh index ca476d9a5e61..3c472c576e70 100755 --- a/scripts-dev/complement.sh +++ b/scripts-dev/complement.sh @@ -45,7 +45,7 @@ docker build -t matrixdotorg/synapse -f "docker/Dockerfile" . extra_test_args=() -test_tags="synapse_blacklist,msc2716,msc3030" +test_tags="synapse_blacklist,msc2716,msc3030,msc3787" # If we're using workers, modify the docker files slightly. if [[ -n "$WORKERS" ]]; then From ee848f6b59e51acb5f3807a4dd49dd351bef20fd Mon Sep 17 00:00:00 2001 From: David Robertson Date: Tue, 24 May 2022 15:27:45 +0100 Subject: [PATCH 2/4] Include knock_restricted rooms in room directory, summary, and spaces heirarchy Missed in #12623. --- synapse/handlers/room_summary.py | 2 +- synapse/storage/databases/main/room.py | 35 +++++++++++++------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/synapse/handlers/room_summary.py b/synapse/handlers/room_summary.py index af83de319348..f8361c8b29d5 100644 --- a/synapse/handlers/room_summary.py +++ b/synapse/handlers/room_summary.py @@ -662,7 +662,7 @@ async def _is_remote_room_accessible( # The API doesn't return the room version so assume that a # join rule of knock is valid. if ( - room.get("join_rules") in (JoinRules.PUBLIC, JoinRules.KNOCK) + room.get("join_rules") in (JoinRules.PUBLIC, JoinRules.KNOCK, JoinRules.KNOCK_RESTRICTED) or room.get("world_readable") is True ): return True diff --git a/synapse/storage/databases/main/room.py b/synapse/storage/databases/main/room.py index ded15b92ef84..10f2ceb50b95 100644 --- a/synapse/storage/databases/main/room.py +++ b/synapse/storage/databases/main/room.py @@ -233,24 +233,23 @@ def _count_public_rooms_txn(txn: LoggingTransaction) -> int: UNION SELECT room_id from appservice_room_list """ - sql = """ + sql = f""" SELECT COUNT(*) FROM ( - %(published_sql)s + {published_sql} ) published INNER JOIN room_stats_state USING (room_id) INNER JOIN room_stats_current USING (room_id) WHERE ( - join_rules = 'public' OR join_rules = '%(knock_join_rule)s' + join_rules = '{JoinRules.PUBLIC}' + OR join_rules = '{JoinRules.KNOCK}' + OR join_rules = '{JoinRules.KNOCK_RESTRICTED}' OR history_visibility = 'world_readable' ) AND joined_members > 0 - """ % { - "published_sql": published_sql, - "knock_join_rule": JoinRules.KNOCK, - } + """ txn.execute(sql, query_args) return cast(Tuple[int], txn.fetchone())[0] @@ -369,29 +368,29 @@ async def get_largest_public_rooms( if where_clauses: where_clause = " AND " + " AND ".join(where_clauses) - sql = """ + dir = "DESC" if forwards else "ASC" + sql = f""" SELECT room_id, name, topic, canonical_alias, joined_members, avatar, history_visibility, guest_access, join_rules FROM ( - %(published_sql)s + {published_sql} ) published INNER JOIN room_stats_state USING (room_id) INNER JOIN room_stats_current USING (room_id) WHERE ( - join_rules = 'public' OR join_rules = '%(knock_join_rule)s' + join_rules = '{JoinRules.PUBLIC}' + OR join_rules = '{JoinRules.KNOCK}' + OR join_rules = '{JoinRules.KNOCK_RESTRICTED}' OR history_visibility = 'world_readable' ) AND joined_members > 0 - %(where_clause)s - ORDER BY joined_members %(dir)s, room_id %(dir)s - """ % { - "published_sql": published_sql, - "where_clause": where_clause, - "dir": "DESC" if forwards else "ASC", - "knock_join_rule": JoinRules.KNOCK, - } + {where_clause} + ORDER BY + joined_members {dir}, + room_id {dir} + """ if limit is not None: query_args.append(limit) From 52b6521c32b80726c1df0644b5babbed45b3392f Mon Sep 17 00:00:00 2001 From: David Robertson Date: Tue, 24 May 2022 16:08:52 +0100 Subject: [PATCH 3/4] Changelog --- changelog.d/12858.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/12858.bugfix diff --git a/changelog.d/12858.bugfix b/changelog.d/12858.bugfix new file mode 100644 index 000000000000..7a7ddc9a1343 --- /dev/null +++ b/changelog.d/12858.bugfix @@ -0,0 +1 @@ +Fix [MSC3878](https://github.com/matrix-org/matrix-spec-proposals/pull/3787) rooms being omitted from room directory, room summary and space hierarchy responses. From 0840327e4281a5002e8b90c72e24952a579a9451 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Tue, 24 May 2022 16:48:27 +0100 Subject: [PATCH 4/4] lint --- synapse/handlers/room_summary.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/synapse/handlers/room_summary.py b/synapse/handlers/room_summary.py index f8361c8b29d5..1dd74912fa95 100644 --- a/synapse/handlers/room_summary.py +++ b/synapse/handlers/room_summary.py @@ -662,7 +662,8 @@ async def _is_remote_room_accessible( # The API doesn't return the room version so assume that a # join rule of knock is valid. if ( - room.get("join_rules") in (JoinRules.PUBLIC, JoinRules.KNOCK, JoinRules.KNOCK_RESTRICTED) + room.get("join_rules") + in (JoinRules.PUBLIC, JoinRules.KNOCK, JoinRules.KNOCK_RESTRICTED) or room.get("world_readable") is True ): return True