feat(db/rooms): disable banning for last user and conduit user in admins room
This commit is contained in:
parent
912491cb28
commit
76f81ac201
1 changed files with 26 additions and 0 deletions
|
@ -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.",
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue