fix(service/rooms/timeline): fix validating for non-joined members

This commit is contained in:
AndSDev 2022-10-14 14:45:05 +03:00
parent d755a96c2c
commit e923f63c49

View file

@ -705,13 +705,17 @@ impl Service {
membership: MembershipState,
}
let target = pdu
.state_key()
.filter(|v| v.starts_with("@"))
.unwrap_or(sender.as_str());
let server_name = services().globals.server_name();
let server_user = format!("@conduit:{}", server_name);
let content = serde_json::from_str::<ExtractMembership>(pdu.content.get())
.map_err(|_| Error::bad_database("Invalid content in pdu."))?;
if content.membership == MembershipState::Leave {
let server_user = format!("@conduit:{}", server_name);
if sender == &server_user {
if target == &server_user {
warn!("Conduit user cannot leave from admins room");
return Err(Error::BadRequest(
ErrorKind::Forbidden,
@ -725,8 +729,9 @@ impl Service {
.room_members(room_id)
.filter_map(|m| m.ok())
.filter(|m| m.server_name() == server_name)
.filter(|m| m != target)
.count();
if count < 3 {
if count < 2 {
warn!("Last admin cannot leave from admins room");
return Err(Error::BadRequest(
ErrorKind::Forbidden,
@ -736,8 +741,7 @@ impl Service {
}
if content.membership == MembershipState::Ban && pdu.state_key().is_some() {
let server_user = format!("@conduit:{}", server_name);
if pdu.state_key().as_ref().unwrap() == &server_user {
if target == &server_user {
warn!("Conduit user cannot be banned in admins room");
return Err(Error::BadRequest(
ErrorKind::Forbidden,
@ -751,8 +755,9 @@ impl Service {
.room_members(room_id)
.filter_map(|m| m.ok())
.filter(|m| m.server_name() == server_name)
.filter(|m| m != target)
.count();
if count < 3 {
if count < 2 {
warn!("Last admin cannot be banned in admins room");
return Err(Error::BadRequest(
ErrorKind::Forbidden,