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

expose whether a room is a space in the Admin API #13208

Merged
merged 18 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/13208.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a `room_type` field in the responses for the list room and room details admin API. Contributed by @andrewdoh.
29 changes: 21 additions & 8 deletions docs/admin_api/rooms.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ The following fields are possible in the JSON response body:
- `guest_access` - Whether guests can join the room. One of: ["can_join", "forbidden"].
- `history_visibility` - Who can see the room history. One of: ["invited", "joined", "shared", "world_readable"].
- `state_events` - Total number of state_events of a room. Complexity of the room.
- `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`.
* `offset` - The current pagination offset in rooms. This parameter should be
used instead of `next_token` for room offset as `next_token` is
not intended to be parsed.
Expand Down Expand Up @@ -101,7 +102,8 @@ A response body like the following is returned:
"join_rules": "invite",
"guest_access": null,
"history_visibility": "shared",
"state_events": 93534
"state_events": 93534,
"room_type": "m.space"
},
... (8 hidden items) ...
{
Expand All @@ -118,7 +120,8 @@ A response body like the following is returned:
"join_rules": "invite",
"guest_access": null,
"history_visibility": "shared",
"state_events": 8345
"state_events": 8345,
"room_type": null
}
],
"offset": 0,
Expand Down Expand Up @@ -151,7 +154,8 @@ A response body like the following is returned:
"join_rules": "invite",
"guest_access": null,
"history_visibility": "shared",
"state_events": 8
"state_events": 8,
"room_type": null
}
],
"offset": 0,
Expand Down Expand Up @@ -184,7 +188,8 @@ A response body like the following is returned:
"join_rules": "invite",
"guest_access": null,
"history_visibility": "shared",
"state_events": 93534
"state_events": 93534,
"room_type": null
},
... (98 hidden items) ...
{
Expand All @@ -201,7 +206,8 @@ A response body like the following is returned:
"join_rules": "invite",
"guest_access": null,
"history_visibility": "shared",
"state_events": 8345
"state_events": 8345,
"room_type": "m.space"
}
],
"offset": 0,
Expand Down Expand Up @@ -238,7 +244,9 @@ A response body like the following is returned:
"join_rules": "invite",
"guest_access": null,
"history_visibility": "shared",
"state_events": 93534
"state_events": 93534,
"room_type": "m.space"

},
... (48 hidden items) ...
{
Expand All @@ -255,7 +263,9 @@ A response body like the following is returned:
"join_rules": "invite",
"guest_access": null,
"history_visibility": "shared",
"state_events": 8345
"state_events": 8345,
"room_type": null

}
],
"offset": 100,
Expand Down Expand Up @@ -290,6 +300,8 @@ The following fields are possible in the JSON response body:
* `guest_access` - Whether guests can join the room. One of: ["can_join", "forbidden"].
* `history_visibility` - Who can see the room history. One of: ["invited", "joined", "shared", "world_readable"].
* `state_events` - Total number of state_events of a room. Complexity of the room.
* `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`.

The API is:

Expand Down Expand Up @@ -317,7 +329,8 @@ A response body like the following is returned:
"join_rules": "invite",
"guest_access": null,
"history_visibility": "shared",
"state_events": 93534
"state_events": 93534,
"room_type": "m.space"
}
```

Expand Down
6 changes: 1 addition & 5 deletions synapse/handlers/room_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import attr

from synapse.api.constants import (
EventContentFields,
EventTypes,
HistoryVisibility,
JoinRules,
Expand Down Expand Up @@ -706,9 +705,6 @@ async def _build_room_entry(self, room_id: str, for_federation: bool) -> JsonDic
current_state_ids = await self._storage_controllers.state.get_current_state_ids(
room_id
)
create_event = await self._store.get_event(
current_state_ids[(EventTypes.Create, "")]
)

entry = {
"room_id": stats["room_id"],
Expand All @@ -722,7 +718,7 @@ async def _build_room_entry(self, room_id: str, for_federation: bool) -> JsonDic
stats["history_visibility"] == HistoryVisibility.WORLD_READABLE
),
"guest_can_join": stats["guest_access"] == "can_join",
"room_type": create_event.content.get(EventContentFields.ROOM_TYPE),
"room_type": stats["room_type"],
}

if self._msc3266_enabled:
Expand Down
6 changes: 4 additions & 2 deletions synapse/storage/databases/main/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def get_room_with_stats_txn(
rooms.creator, state.encryption, state.is_federatable AS federatable,
rooms.is_public AS public, state.join_rules, state.guest_access,
state.history_visibility, curr.current_state_events AS state_events,
state.avatar, state.topic
state.avatar, state.topic, state.room_type
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
FROM rooms
LEFT JOIN room_stats_state state USING (room_id)
LEFT JOIN room_stats_current curr USING (room_id)
Expand Down Expand Up @@ -596,7 +596,8 @@ async def get_rooms_paginate(
SELECT state.room_id, state.name, state.canonical_alias, curr.joined_members,
curr.local_users_in_room, rooms.room_version, rooms.creator,
state.encryption, state.is_federatable, rooms.is_public, state.join_rules,
state.guest_access, state.history_visibility, curr.current_state_events
state.guest_access, state.history_visibility, curr.current_state_events,
state.room_type
FROM room_stats_state state
INNER JOIN room_stats_current curr USING (room_id)
INNER JOIN rooms USING (room_id)
Expand Down Expand Up @@ -646,6 +647,7 @@ def _get_rooms_paginate_txn(
"guest_access": room[11],
"history_visibility": room[12],
"state_events": room[13],
"room_type": room[14],
}
)

Expand Down
13 changes: 10 additions & 3 deletions tests/rest/admin/test_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from twisted.test.proto_helpers import MemoryReactor

import synapse.rest.admin
from synapse.api.constants import EventTypes, Membership
from synapse.api.constants import EventTypes, Membership, RoomTypes
from synapse.api.errors import Codes
from synapse.handlers.pagination import PaginationHandler
from synapse.rest.client import directory, events, login, room
Expand Down Expand Up @@ -1130,6 +1130,8 @@ def test_list_rooms(self) -> None:
self.assertIn("guest_access", r)
self.assertIn("history_visibility", r)
self.assertIn("state_events", r)
self.assertIn("room_type", r)
andrewdoh marked this conversation as resolved.
Show resolved Hide resolved
andrewdoh marked this conversation as resolved.
Show resolved Hide resolved
self.assertIsNone(r["room_type"])

# Check that the correct number of total rooms was returned
self.assertEqual(channel.json_body["total_rooms"], total_rooms)
Expand Down Expand Up @@ -1229,7 +1231,11 @@ def test_list_rooms_pagination(self) -> None:
def test_correct_room_attributes(self) -> None:
"""Test the correct attributes for a room are returned"""
# Create a test room
room_id = self.helper.create_room_as(self.admin_user, tok=self.admin_user_tok)
room_id = self.helper.create_room_as(
self.admin_user,
tok=self.admin_user_tok,
extra_content={"creation_content": {"type": RoomTypes.SPACE}},
)

test_alias = "#test:test"
test_room_name = "something"
Expand Down Expand Up @@ -1306,6 +1312,7 @@ def test_correct_room_attributes(self) -> None:
self.assertEqual(room_id, r["room_id"])
self.assertEqual(test_room_name, r["name"])
self.assertEqual(test_alias, r["canonical_alias"])
self.assertEqual(RoomTypes.SPACE, r["room_type"])

def test_room_list_sort_order(self) -> None:
"""Test room list sort ordering. alphabetical name versus number of members,
Expand Down Expand Up @@ -1630,7 +1637,7 @@ def test_single_room(self) -> None:
self.assertIn("guest_access", channel.json_body)
self.assertIn("history_visibility", channel.json_body)
self.assertIn("state_events", channel.json_body)

self.assertIn("room_type", channel.json_body)
self.assertEqual(room_id_1, channel.json_body["room_id"])

def test_single_room_devices(self) -> None:
Expand Down