check if user is allowed to invite for restricted room join
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
5667884a6a
commit
7300103796
1 changed files with 28 additions and 11 deletions
|
@ -1024,7 +1024,10 @@ pub(crate) async fn join_room_by_id_helper(
|
||||||
|
|
||||||
let restriction_rooms = match join_rules_event_content {
|
let restriction_rooms = match join_rules_event_content {
|
||||||
Some(RoomJoinRulesEventContent {
|
Some(RoomJoinRulesEventContent {
|
||||||
join_rule: JoinRule::Restricted(restricted) | JoinRule::KnockRestricted(restricted),
|
join_rule: JoinRule::Restricted(restricted),
|
||||||
|
})
|
||||||
|
| Some(RoomJoinRulesEventContent {
|
||||||
|
join_rule: JoinRule::KnockRestricted(restricted),
|
||||||
}) => restricted
|
}) => restricted
|
||||||
.allow
|
.allow
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -1036,22 +1039,36 @@ pub(crate) async fn join_room_by_id_helper(
|
||||||
_ => Vec::new(),
|
_ => Vec::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let authorized_user = if restriction_rooms.iter().any(|restriction_room_id| {
|
let local_members = services()
|
||||||
|
.rooms
|
||||||
|
.state_cache
|
||||||
|
.room_members(room_id)
|
||||||
|
.filter_map(Result::ok)
|
||||||
|
.filter(|user| user.server_name() == services().globals.server_name())
|
||||||
|
.collect::<Vec<OwnedUserId>>();
|
||||||
|
|
||||||
|
let mut authorized_user: Option<OwnedUserId> = None;
|
||||||
|
|
||||||
|
if restriction_rooms.iter().any(|restriction_room_id| {
|
||||||
services()
|
services()
|
||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.is_joined(sender_user, restriction_room_id)
|
.is_joined(sender_user, restriction_room_id)
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
}) {
|
}) {
|
||||||
services()
|
for user in local_members {
|
||||||
.rooms
|
if services()
|
||||||
.state_cache
|
.rooms
|
||||||
.room_members(room_id)
|
.state_accessor
|
||||||
.filter_map(Result::ok)
|
.user_can_invite(room_id, &user, sender_user, &state_lock)
|
||||||
.find(|auth_user| auth_user.server_name() == services().globals.server_name())
|
.await
|
||||||
} else {
|
.unwrap_or(false)
|
||||||
None
|
{
|
||||||
};
|
authorized_user = Some(user);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let event = RoomMemberEventContent {
|
let event = RoomMemberEventContent {
|
||||||
membership: MembershipState::Join,
|
membership: MembershipState::Join,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue