fixup! feat(federation): support /make_join and /send_join for restricted rooms
remove indents when getting authorized join user
This commit is contained in:
parent
ba4fa81620
commit
6565d3fa71
1 changed files with 73 additions and 73 deletions
|
@ -1533,22 +1533,34 @@ pub async fn create_join_event_template_route(
|
|||
})
|
||||
.transpose()?;
|
||||
|
||||
let join_authorized_via_users_server =
|
||||
if let Some(join_rules_event_content) = join_rules_event_content {
|
||||
if services()
|
||||
let join_authorized_via_users_server = || async {
|
||||
let join_rules_event_content = join_rules_event_content?;
|
||||
|
||||
if !services()
|
||||
.rooms
|
||||
.state_cache
|
||||
.is_left(&body.user_id, &body.room_id)
|
||||
.unwrap_or(true)
|
||||
|| services()
|
||||
&& !services()
|
||||
.rooms
|
||||
.state_cache
|
||||
.is_knocked(&body.user_id, &body.room_id)
|
||||
.unwrap_or(false)
|
||||
{
|
||||
if let JoinRule::Restricted(r) | JoinRule::KnockRestricted(r) =
|
||||
// If the user has any state other than leave or knock, either:
|
||||
// - the auth_check will deny them (ban)
|
||||
// - they are able to join via other methods (invite)
|
||||
// - they are already in the room (join)
|
||||
return None;
|
||||
};
|
||||
|
||||
let (JoinRule::Restricted(r) | JoinRule::KnockRestricted(r)) =
|
||||
join_rules_event_content.join_rule
|
||||
{
|
||||
else {
|
||||
// Room is not restricted
|
||||
return None;
|
||||
};
|
||||
|
||||
if r.allow
|
||||
.iter()
|
||||
.filter_map(|rule| {
|
||||
|
@ -1566,13 +1578,12 @@ pub async fn create_join_event_template_route(
|
|||
.unwrap_or(false)
|
||||
})
|
||||
{
|
||||
let members: Vec<_> = services()
|
||||
let members = services()
|
||||
.rooms
|
||||
.state_cache
|
||||
.room_members(&body.room_id)
|
||||
.filter_map(Result::ok)
|
||||
.filter(|user| user.server_name() == services().globals.server_name())
|
||||
.collect();
|
||||
.filter(|user| user.server_name() == services().globals.server_name());
|
||||
|
||||
let mut auth_user = None;
|
||||
|
||||
|
@ -1589,34 +1600,23 @@ pub async fn create_join_event_template_route(
|
|||
}
|
||||
}
|
||||
if auth_user.is_some() {
|
||||
auth_user
|
||||
Ok(auth_user).transpose()
|
||||
} else {
|
||||
return Err(Error::BadRequest(
|
||||
Some(Err(Error::BadRequest(
|
||||
ErrorKind::UnableToGrantJoin,
|
||||
"No user on this server is able to assist in joining.",
|
||||
));
|
||||
)))
|
||||
}
|
||||
} else {
|
||||
return Err(Error::BadRequest(
|
||||
Some(Err(Error::BadRequest(
|
||||
ErrorKind::UnableToAuthorizeJoin,
|
||||
"User is not known to be in any required room.",
|
||||
));
|
||||
)))
|
||||
}
|
||||
} else {
|
||||
// Room is not restricted
|
||||
None
|
||||
}
|
||||
} else {
|
||||
// If the user has any state other than leave or knock, either:
|
||||
// - the auth_check will deny them (ban)
|
||||
// - they are able to join via other methods (invite)
|
||||
// - they are already in the room (join)
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let join_authorized_via_users_server = join_authorized_via_users_server().await.transpose()?;
|
||||
|
||||
let room_version_id = services().rooms.state.get_room_version(&body.room_id)?;
|
||||
if !body.ver.contains(&room_version_id) {
|
||||
return Err(Error::BadRequest(
|
||||
|
|
Loading…
Add table
Reference in a new issue