feat(db/rooms): disable banning for last user and conduit user in admins room

This commit is contained in:
AndSDev 2022-09-06 11:32:33 +00:00
parent 912491cb28
commit 76f81ac201

View file

@ -733,6 +733,32 @@ impl Service {
));
}
}
if content.membership == MembershipState::Ban && pdu.state_key().is_some() {
let server_user = format!("@conduit:{}", services().globals.server_name());
if pdu.state_key().as_ref().unwrap() == &server_user {
warn!("Conduit user cannot be banned in admins room");
return Err(Error::BadRequest(
ErrorKind::Forbidden,
"Conduit user cannot be banned in admins room.",
));
}
let count = services()
.rooms
.state_cache
.room_members(room_id)
.filter_map(|m| m.ok())
.filter(|m| m.server_name() == services().globals.server_name())
.count();
if count < 3 {
warn!("Last admin cannot be banned in admins room");
return Err(Error::BadRequest(
ErrorKind::Forbidden,
"Last admin cannot be banned in admins room.",
));
}
}
}
_ => {}
}