Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 2d82cda

Browse files
authored
expose whether a room is a space in the Admin API (#13208)
1 parent f14c632 commit 2d82cda

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

changelog.d/13208.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add a `room_type` field in the responses for the list room and room details admin API. Contributed by @andrewdoh.

docs/admin_api/rooms.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ The following fields are possible in the JSON response body:
5959
- `guest_access` - Whether guests can join the room. One of: ["can_join", "forbidden"].
6060
- `history_visibility` - Who can see the room history. One of: ["invited", "joined", "shared", "world_readable"].
6161
- `state_events` - Total number of state_events of a room. Complexity of the room.
62+
- `room_type` - The type of the room taken from the room's creation event; for example "m.space" if the room is a space. If the room does not define a type, the value will be `null`.
6263
* `offset` - The current pagination offset in rooms. This parameter should be
6364
used instead of `next_token` for room offset as `next_token` is
6465
not intended to be parsed.
@@ -101,7 +102,8 @@ A response body like the following is returned:
101102
"join_rules": "invite",
102103
"guest_access": null,
103104
"history_visibility": "shared",
104-
"state_events": 93534
105+
"state_events": 93534,
106+
"room_type": "m.space"
105107
},
106108
... (8 hidden items) ...
107109
{
@@ -118,7 +120,8 @@ A response body like the following is returned:
118120
"join_rules": "invite",
119121
"guest_access": null,
120122
"history_visibility": "shared",
121-
"state_events": 8345
123+
"state_events": 8345,
124+
"room_type": null
122125
}
123126
],
124127
"offset": 0,
@@ -151,7 +154,8 @@ A response body like the following is returned:
151154
"join_rules": "invite",
152155
"guest_access": null,
153156
"history_visibility": "shared",
154-
"state_events": 8
157+
"state_events": 8,
158+
"room_type": null
155159
}
156160
],
157161
"offset": 0,
@@ -184,7 +188,8 @@ A response body like the following is returned:
184188
"join_rules": "invite",
185189
"guest_access": null,
186190
"history_visibility": "shared",
187-
"state_events": 93534
191+
"state_events": 93534,
192+
"room_type": null
188193
},
189194
... (98 hidden items) ...
190195
{
@@ -201,7 +206,8 @@ A response body like the following is returned:
201206
"join_rules": "invite",
202207
"guest_access": null,
203208
"history_visibility": "shared",
204-
"state_events": 8345
209+
"state_events": 8345,
210+
"room_type": "m.space"
205211
}
206212
],
207213
"offset": 0,
@@ -238,7 +244,9 @@ A response body like the following is returned:
238244
"join_rules": "invite",
239245
"guest_access": null,
240246
"history_visibility": "shared",
241-
"state_events": 93534
247+
"state_events": 93534,
248+
"room_type": "m.space"
249+
242250
},
243251
... (48 hidden items) ...
244252
{
@@ -255,7 +263,9 @@ A response body like the following is returned:
255263
"join_rules": "invite",
256264
"guest_access": null,
257265
"history_visibility": "shared",
258-
"state_events": 8345
266+
"state_events": 8345,
267+
"room_type": null
268+
259269
}
260270
],
261271
"offset": 100,
@@ -290,6 +300,8 @@ The following fields are possible in the JSON response body:
290300
* `guest_access` - Whether guests can join the room. One of: ["can_join", "forbidden"].
291301
* `history_visibility` - Who can see the room history. One of: ["invited", "joined", "shared", "world_readable"].
292302
* `state_events` - Total number of state_events of a room. Complexity of the room.
303+
* `room_type` - The type of the room taken from the room's creation event; for example "m.space" if the room is a space.
304+
If the room does not define a type, the value will be `null`.
293305

294306
The API is:
295307

@@ -317,7 +329,8 @@ A response body like the following is returned:
317329
"join_rules": "invite",
318330
"guest_access": null,
319331
"history_visibility": "shared",
320-
"state_events": 93534
332+
"state_events": 93534,
333+
"room_type": "m.space"
321334
}
322335
```
323336

synapse/storage/databases/main/room.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def get_room_with_stats_txn(
175175
rooms.creator, state.encryption, state.is_federatable AS federatable,
176176
rooms.is_public AS public, state.join_rules, state.guest_access,
177177
state.history_visibility, curr.current_state_events AS state_events,
178-
state.avatar, state.topic
178+
state.avatar, state.topic, state.room_type
179179
FROM rooms
180180
LEFT JOIN room_stats_state state USING (room_id)
181181
LEFT JOIN room_stats_current curr USING (room_id)
@@ -596,7 +596,8 @@ async def get_rooms_paginate(
596596
SELECT state.room_id, state.name, state.canonical_alias, curr.joined_members,
597597
curr.local_users_in_room, rooms.room_version, rooms.creator,
598598
state.encryption, state.is_federatable, rooms.is_public, state.join_rules,
599-
state.guest_access, state.history_visibility, curr.current_state_events
599+
state.guest_access, state.history_visibility, curr.current_state_events,
600+
state.room_type
600601
FROM room_stats_state state
601602
INNER JOIN room_stats_current curr USING (room_id)
602603
INNER JOIN rooms USING (room_id)
@@ -646,6 +647,7 @@ def _get_rooms_paginate_txn(
646647
"guest_access": room[11],
647648
"history_visibility": room[12],
648649
"state_events": room[13],
650+
"room_type": room[14],
649651
}
650652
)
651653

tests/rest/admin/test_room.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from twisted.test.proto_helpers import MemoryReactor
2222

2323
import synapse.rest.admin
24-
from synapse.api.constants import EventTypes, Membership
24+
from synapse.api.constants import EventTypes, Membership, RoomTypes
2525
from synapse.api.errors import Codes
2626
from synapse.handlers.pagination import PaginationHandler
2727
from synapse.rest.client import directory, events, login, room
@@ -1130,6 +1130,8 @@ def test_list_rooms(self) -> None:
11301130
self.assertIn("guest_access", r)
11311131
self.assertIn("history_visibility", r)
11321132
self.assertIn("state_events", r)
1133+
self.assertIn("room_type", r)
1134+
self.assertIsNone(r["room_type"])
11331135

11341136
# Check that the correct number of total rooms was returned
11351137
self.assertEqual(channel.json_body["total_rooms"], total_rooms)
@@ -1229,7 +1231,11 @@ def test_list_rooms_pagination(self) -> None:
12291231
def test_correct_room_attributes(self) -> None:
12301232
"""Test the correct attributes for a room are returned"""
12311233
# Create a test room
1232-
room_id = self.helper.create_room_as(self.admin_user, tok=self.admin_user_tok)
1234+
room_id = self.helper.create_room_as(
1235+
self.admin_user,
1236+
tok=self.admin_user_tok,
1237+
extra_content={"creation_content": {"type": RoomTypes.SPACE}},
1238+
)
12331239

12341240
test_alias = "#test:test"
12351241
test_room_name = "something"
@@ -1306,6 +1312,7 @@ def test_correct_room_attributes(self) -> None:
13061312
self.assertEqual(room_id, r["room_id"])
13071313
self.assertEqual(test_room_name, r["name"])
13081314
self.assertEqual(test_alias, r["canonical_alias"])
1315+
self.assertEqual(RoomTypes.SPACE, r["room_type"])
13091316

13101317
def test_room_list_sort_order(self) -> None:
13111318
"""Test room list sort ordering. alphabetical name versus number of members,
@@ -1630,7 +1637,7 @@ def test_single_room(self) -> None:
16301637
self.assertIn("guest_access", channel.json_body)
16311638
self.assertIn("history_visibility", channel.json_body)
16321639
self.assertIn("state_events", channel.json_body)
1633-
1640+
self.assertIn("room_type", channel.json_body)
16341641
self.assertEqual(room_id_1, channel.json_body["room_id"])
16351642

16361643
def test_single_room_devices(self) -> None:

0 commit comments

Comments
 (0)