chore(spaces): fix doc comments, design doc accuracy, consistent error style

- Fix doc comment referencing room_to_space instead of space_to_rooms
- Add space_to_rooms forward index to design doc index table
- Use Err! consistently for validation errors in admin commands
- Rename test to follow deserialize_ prefix convention

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
ember33 2026-03-18 12:35:35 +01:00
parent d569ef2e40
commit cee5aa476c
4 changed files with 10 additions and 17 deletions

View file

@ -160,9 +160,8 @@ existing `roomid_spacehierarchy_cache`.
| Space → roles defined | `com.continuwuity.space.roles` |
| Space → user → roles | `com.continuwuity.space.role.member` |
| Space → room → required roles| `com.continuwuity.space.role.room` |
| Room → parent Space | `m.space.child` (reverse lookup) |
The Space → child rooms mapping already exists.
| Room → parent Spaces | `m.space.child` (reverse lookup) |
| Space → child rooms | `m.space.child` (forward index) |
### Cache invalidation triggers

View file

@ -41,9 +41,7 @@ macro_rules! resolve_space {
.await,
Ok(ruma::room::RoomType::Space)
) {
return $self
.write_str("Error: The specified room is not a Space.")
.await;
return Err!("The specified room is not a Space.");
}
space_id
}};
@ -332,9 +330,7 @@ async fn assign(
.unwrap_or_default();
if !role_defs.roles.contains_key(&role_name) {
return self
.write_str(&format!("Error: Role '{role_name}' does not exist in this space."))
.await;
return Err!("Role '{role_name}' does not exist in this space.");
}
let member_event_type = StateEventType::from(SPACE_ROLE_MEMBER_EVENT_TYPE.to_owned());
@ -438,9 +434,7 @@ async fn require(
.unwrap_or_default();
if !role_defs.roles.contains_key(&role_name) {
return self
.write_str(&format!("Error: Role '{role_name}' does not exist in this space."))
.await;
return Err!("Role '{role_name}' does not exist in this space.");
}
let room_event_type = StateEventType::from(SPACE_ROLE_ROOM_EVENT_TYPE.to_owned());

View file

@ -176,7 +176,7 @@ mod tests {
}
#[test]
fn unknown_fields_ignored() {
fn deserialize_ignores_unknown_fields() {
let json = r#"{"roles":["nsfw"],"extra_field":"ignored"}"#;
let content: SpaceRoleMemberEventContent = serde_json::from_str(json).unwrap();
assert_eq!(content.roles, vec!["nsfw"]);

View file

@ -595,9 +595,9 @@ pub async fn sync_power_levels(&self, space_id: &RoomId, room_id: &RoomId) -> Re
/// Auto-join a user to all qualifying child rooms of a Space.
///
/// Iterates over all child rooms in the `room_to_space` reverse index that
/// belong to the given space, checks whether the user qualifies via their
/// assigned roles, and force-joins them if they are not already a member.
/// Iterates over all child rooms in the `space_to_rooms` forward index,
/// checks whether the user qualifies via their assigned roles, and
/// force-joins them if they are not already a member.
#[implement(Service)]
pub async fn auto_join_qualifying_rooms(
&self,
@ -614,7 +614,7 @@ pub async fn auto_join_qualifying_rooms(
return Ok(());
}
// Get all child rooms from the room_to_space reverse index
// Get all child rooms via the space_to_rooms forward index
let child_rooms = self.get_child_rooms(space_id).await;
for child_room_id in &child_rooms {