extend room banning to local+remote room invites

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-03-02 21:49:04 -05:00 committed by June
parent ea66bff46b
commit 34e8fd38cf
3 changed files with 34 additions and 1 deletions

View file

@ -201,6 +201,17 @@ pub async fn invite_user_route(
));
}
if services().rooms.metadata.is_banned(&body.room_id)? && !services().users.is_admin(sender_user)? {
info!(
"Local user {} who is not an admin attempted to send an invite for banned room {}.",
&sender_user, &body.room_id
);
return Err(Error::BadRequest(
ErrorKind::Forbidden,
"This room is banned on this homeserver.",
));
}
if let invite_user::v3::InvitationRecipient::UserId { user_id } = &body.recipient {
invite_helper(
sender_user,
@ -1285,6 +1296,16 @@ pub(crate) async fn invite_helper(
reason: Option<String>,
is_direct: bool,
) -> Result<()> {
if !services().users.is_admin(user_id)? && services().globals.block_non_admin_invites() {
info!(
"User {sender_user} is not an admin and attempted to send an invite to room {room_id}"
);
return Err(Error::BadRequest(
ErrorKind::Forbidden,
"Invites are not allowed on this server.",
));
}
if user_id.server_name() != services().globals.server_name() {
let (pdu, pdu_json, invite_room_state) = {
let mutex_state = Arc::clone(

View file

@ -1852,6 +1852,7 @@ pub async fn create_invite_route(
"This server does not allow room invites.",
));
}
services()
.rooms
.event_handler
@ -1921,6 +1922,17 @@ pub async fn create_invite_route(
)
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "state_key is not a user id."))?;
if services().rooms.metadata.is_banned(&body.room_id)? && !services().users.is_admin(&invited_user)? {
info!(
"Received remote invite from server {} for room {} and for user {invited_user}, but room is banned by us.",
&sender_servername, &body.room_id
);
return Err(Error::BadRequest(
ErrorKind::Forbidden,
"This room is banned on this homeserver.",
));
}
let mut invite_state = body.invite_room_state.clone();
let mut event: JsonObject = serde_json::from_str(body.event.get())

View file

@ -212,7 +212,7 @@ enum RoomCommand {
#[cfg_attr(test, derive(Debug))]
#[derive(Subcommand)]
enum RoomModeration {
/// - Bans a room from local users joining and evicts all our local users from the room.
/// - Bans a room from local users joining and evicts all our local users from the room. Also blocks any invites (local and remote) for the banned room.
///
/// Server admins (users in the conduwuit admin room) will not be evicted and server admins can still join the room.
/// To evict admins too, use --force (also ignores errors)