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 11 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/12624.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove use of constantly library and switch to enums for EventRedactBehaviour. Contributed by @andrewdoh.
andrewdoh marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions changelog.d/13208.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add room_type to response in list room and room details API. Contributed by @andrewdoh.
andrewdoh marked this conversation as resolved.
Show resolved Hide resolved
andrewdoh marked this conversation as resolved.
Show resolved Hide resolved
28 changes: 20 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.
* `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,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.
andrewdoh marked this conversation as resolved.
Show resolved Hide resolved

The API is:

Expand Down Expand Up @@ -317,7 +328,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
5 changes: 3 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,7 @@ 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
andrewdoh marked this conversation as resolved.
Show resolved Hide resolved
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 +646,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: 9 additions & 4 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,7 +1130,7 @@ 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
# 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 +1229,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 +1310,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 +1635,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