fix and enable collapsible_if lint
Signed-off-by: June Strawberry <june@vern.cc>
This commit is contained in:
@@ -301,30 +301,26 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
||||
return None;
|
||||
}
|
||||
|
||||
if let Some(query) = search_room_id {
|
||||
if chunk.room_id.as_str().contains(query) {
|
||||
if let Some(query) = search_room_id
|
||||
&& chunk.room_id.as_str().contains(query) {
|
||||
return Some(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(query) = search_term.as_deref() {
|
||||
if let Some(name) = &chunk.name {
|
||||
if name.as_str().to_lowercase().contains(query) {
|
||||
if let Some(name) = &chunk.name
|
||||
&& name.as_str().to_lowercase().contains(query) {
|
||||
return Some(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(topic) = &chunk.topic {
|
||||
if topic.to_lowercase().contains(query) {
|
||||
if let Some(topic) = &chunk.topic
|
||||
&& topic.to_lowercase().contains(query) {
|
||||
return Some(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(canonical_alias) = &chunk.canonical_alias {
|
||||
if canonical_alias.as_str().to_lowercase().contains(query) {
|
||||
if let Some(canonical_alias) = &chunk.canonical_alias
|
||||
&& canonical_alias.as_str().to_lowercase().contains(query) {
|
||||
return Some(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -484,10 +484,10 @@ where
|
||||
{
|
||||
self_signing_keys.insert(user_id.to_owned(), self_signing_key);
|
||||
}
|
||||
if Some(user_id) == sender_user {
|
||||
if let Ok(user_signing_key) = services.users.get_user_signing_key(user_id).await {
|
||||
user_signing_keys.insert(user_id.to_owned(), user_signing_key);
|
||||
}
|
||||
if Some(user_id) == sender_user
|
||||
&& let Ok(user_signing_key) = services.users.get_user_signing_key(user_id).await
|
||||
{
|
||||
user_signing_keys.insert(user_id.to_owned(), user_signing_key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,11 +49,9 @@ pub(crate) async fn invite_user_route(
|
||||
if let Ok(target_user_membership) = services
|
||||
.state_accessor
|
||||
.get_member(room_id, user_id)
|
||||
.await
|
||||
.await && target_user_membership.membership == MembershipState::Ban
|
||||
{
|
||||
if target_user_membership.membership == MembershipState::Ban {
|
||||
return Err!(Request(Forbidden("User is banned from this room.")));
|
||||
}
|
||||
return Err!(Request(Forbidden("User is banned from this room.")));
|
||||
}
|
||||
|
||||
if recipient_ignored_by_sender {
|
||||
|
||||
@@ -48,14 +48,13 @@ pub(crate) async fn get_presence_route(
|
||||
.user_sees_user(body.sender_user(), &body.user_id)
|
||||
.await;
|
||||
|
||||
if has_shared_rooms {
|
||||
if let Ok(presence) = services
|
||||
if has_shared_rooms
|
||||
&& let Ok(presence) = services
|
||||
.presence
|
||||
.get_presence(&body.user_id)
|
||||
.await
|
||||
{
|
||||
presence_event = Some(presence);
|
||||
}
|
||||
{
|
||||
presence_event = Some(presence);
|
||||
}
|
||||
|
||||
match presence_event {
|
||||
|
||||
@@ -93,10 +93,10 @@ pub(crate) async fn get_register_available_route(
|
||||
return Err!(Request(UserInUse("User ID is not available.")));
|
||||
}
|
||||
|
||||
if let Some(ref info) = body.appservice_info {
|
||||
if !info.is_user_match(&user_id) {
|
||||
return Err!(Request(Exclusive("Username is not in an appservice namespace.")));
|
||||
}
|
||||
if let Some(ref info) = body.appservice_info
|
||||
&& !info.is_user_match(&user_id)
|
||||
{
|
||||
return Err!(Request(Exclusive("Username is not in an appservice namespace.")));
|
||||
}
|
||||
|
||||
if services
|
||||
|
||||
@@ -446,10 +446,10 @@ async fn create_create_event(
|
||||
))))
|
||||
})?;
|
||||
|
||||
if !services.config.federate_created_rooms {
|
||||
if !services.config.allow_federation || !content.contains_key("m.federate") {
|
||||
content.insert("m.federate".into(), json!(false).try_into()?);
|
||||
}
|
||||
if !services.config.federate_created_rooms
|
||||
&& (!services.config.allow_federation || !content.contains_key("m.federate"))
|
||||
{
|
||||
content.insert("m.federate".into(), json!(false).try_into()?);
|
||||
}
|
||||
|
||||
content.insert(
|
||||
@@ -578,10 +578,10 @@ async fn create_create_event_legacy(
|
||||
},
|
||||
}
|
||||
|
||||
if !services.config.federate_created_rooms {
|
||||
if !services.config.allow_federation || !content.contains_key("m.federate") {
|
||||
content.insert("m.federate".into(), json!(false).try_into()?);
|
||||
}
|
||||
if !services.config.federate_created_rooms
|
||||
&& (!services.config.allow_federation || !content.contains_key("m.federate"))
|
||||
{
|
||||
content.insert("m.federate".into(), json!(false).try_into()?);
|
||||
}
|
||||
|
||||
content.insert(
|
||||
|
||||
@@ -646,8 +646,9 @@ async fn try_user_id(
|
||||
|
||||
fn parse_user_id(server_name: &ServerName, username: &str) -> Result<OwnedUserId> {
|
||||
match UserId::parse_with_server_name(username, server_name) {
|
||||
| Err(e) =>
|
||||
Err!(Request(InvalidUsername(debug_error!("Username {username} is not valid: {e}")))),
|
||||
| Err(e) => {
|
||||
Err!(Request(InvalidUsername(debug_error!("Username {username} is not valid: {e}"))))
|
||||
},
|
||||
| Ok(user_id) => match user_id.validate_strict() {
|
||||
| Ok(()) => Ok(user_id),
|
||||
| Err(e) => Err!(Request(InvalidUsername(debug_error!(
|
||||
|
||||
@@ -45,12 +45,12 @@ pub(crate) async fn get_hierarchy_route(
|
||||
.and_then(|s| PaginationToken::from_str(s).ok());
|
||||
|
||||
// Should prevent unexpected behaviour in (bad) clients
|
||||
if let Some(ref token) = key {
|
||||
if token.suggested_only != body.suggested_only || token.max_depth != max_depth {
|
||||
return Err!(Request(InvalidParam(
|
||||
"suggested_only and max_depth cannot change on paginated requests"
|
||||
)));
|
||||
}
|
||||
if let Some(ref token) = key
|
||||
&& (token.suggested_only != body.suggested_only || token.max_depth != max_depth)
|
||||
{
|
||||
return Err!(Request(InvalidParam(
|
||||
"suggested_only and max_depth cannot change on paginated requests"
|
||||
)));
|
||||
}
|
||||
|
||||
get_client_hierarchy(
|
||||
|
||||
@@ -276,21 +276,21 @@ async fn allowed_to_send_state_event(
|
||||
},
|
||||
| StateEventType::RoomJoinRules => {
|
||||
// admin room is a sensitive room, it should not ever be made public
|
||||
if let Ok(admin_room_id) = services.admin.get_admin_room().await {
|
||||
if admin_room_id == room_id {
|
||||
match json.deserialize_as_unchecked::<RoomJoinRulesEventContent>() {
|
||||
| Ok(join_rule) =>
|
||||
if join_rule.join_rule == JoinRule::Public {
|
||||
return Err!(Request(Forbidden(
|
||||
"Admin room is a sensitive room, it cannot be made public"
|
||||
)));
|
||||
},
|
||||
| Err(e) => {
|
||||
return Err!(Request(BadJson(debug_warn!(
|
||||
"Room join rules event is invalid: {e}"
|
||||
))));
|
||||
if let Ok(admin_room_id) = services.admin.get_admin_room().await
|
||||
&& admin_room_id == room_id
|
||||
{
|
||||
match json.deserialize_as_unchecked::<RoomJoinRulesEventContent>() {
|
||||
| Ok(join_rule) =>
|
||||
if join_rule.join_rule == JoinRule::Public {
|
||||
return Err!(Request(Forbidden(
|
||||
"Admin room is a sensitive room, it cannot be made public"
|
||||
)));
|
||||
},
|
||||
}
|
||||
| Err(e) => {
|
||||
return Err!(Request(BadJson(debug_warn!(
|
||||
"Room join rules event is invalid: {e}"
|
||||
))));
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -51,14 +51,13 @@ pub(crate) async fn create_invite_route(
|
||||
));
|
||||
}
|
||||
|
||||
if let Some(server) = body.room_id.server_name() {
|
||||
if services
|
||||
if let Some(server) = body.room_id.server_name()
|
||||
&& services
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.is_match(server.host())
|
||||
{
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
{
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
if services
|
||||
|
||||
@@ -54,16 +54,15 @@ pub(crate) async fn create_join_event_template_route(
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
if let Some(server) = body.room_id.server_name() {
|
||||
if services
|
||||
if let Some(server) = body.room_id.server_name()
|
||||
&& services
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.is_match(server.host())
|
||||
{
|
||||
return Err!(Request(Forbidden(warn!(
|
||||
"Room ID server name {server} is banned on this homeserver."
|
||||
))));
|
||||
}
|
||||
{
|
||||
return Err!(Request(Forbidden(warn!(
|
||||
"Room ID server name {server} is banned on this homeserver."
|
||||
))));
|
||||
}
|
||||
|
||||
let room_version_id = services
|
||||
|
||||
@@ -46,14 +46,13 @@ pub(crate) async fn create_knock_event_template_route(
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
if let Some(server) = body.room_id.server_name() {
|
||||
if services
|
||||
if let Some(server) = body.room_id.server_name()
|
||||
&& services
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.is_match(server.host())
|
||||
{
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
{
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
let room_version = services
|
||||
@@ -80,17 +79,15 @@ pub(crate) async fn create_knock_event_template_route(
|
||||
if let Ok(membership) = services
|
||||
.state_accessor
|
||||
.get_member(&body.room_id, &body.user_id)
|
||||
.await
|
||||
.await && membership.membership == MembershipState::Ban
|
||||
{
|
||||
if membership.membership == MembershipState::Ban {
|
||||
debug_warn!(
|
||||
"Remote user {} is banned from {} but attempted to knock",
|
||||
&body.user_id,
|
||||
&body.room_id
|
||||
);
|
||||
debug_warn!(
|
||||
"Remote user {} is banned from {} but attempted to knock",
|
||||
&body.user_id,
|
||||
&body.room_id
|
||||
);
|
||||
|
||||
return Err!(Request(Forbidden("You cannot knock on a room you are banned from.")));
|
||||
}
|
||||
return Err!(Request(Forbidden("You cannot knock on a room you are banned from.")));
|
||||
}
|
||||
|
||||
let pdu_json = services
|
||||
|
||||
@@ -115,10 +115,10 @@ pub(crate) async fn send_transaction_message_route(
|
||||
"Finished txn",
|
||||
);
|
||||
for (id, result) in &results {
|
||||
if let Err(e) = result {
|
||||
if matches!(e, Error::BadRequest(ErrorKind::NotFound, _)) {
|
||||
warn!("Incoming PDU failed {id}: {e:?}");
|
||||
}
|
||||
if let Err(e) = result
|
||||
&& matches!(e, Error::BadRequest(ErrorKind::NotFound, _))
|
||||
{
|
||||
warn!("Incoming PDU failed {id}: {e:?}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -285,23 +285,22 @@ pub(crate) async fn create_join_event_v1_route(
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
if let Some(server) = body.room_id.server_name() {
|
||||
if services
|
||||
if let Some(server) = body.room_id.server_name()
|
||||
&& services
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.is_match(server.host())
|
||||
{
|
||||
warn!(
|
||||
"Server {} tried joining room ID {} through us which has a server name that is \
|
||||
globally forbidden. Rejecting.",
|
||||
body.origin(),
|
||||
&body.room_id,
|
||||
);
|
||||
{
|
||||
warn!(
|
||||
"Server {} tried joining room ID {} through us which has a server name that is \
|
||||
globally forbidden. Rejecting.",
|
||||
body.origin(),
|
||||
&body.room_id,
|
||||
);
|
||||
|
||||
return Err!(Request(Forbidden(warn!(
|
||||
"Room ID server name {server} is banned on this homeserver."
|
||||
))));
|
||||
}
|
||||
return Err!(Request(Forbidden(warn!(
|
||||
"Room ID server name {server} is banned on this homeserver."
|
||||
))));
|
||||
}
|
||||
|
||||
Ok(create_join_event::v1::Response {
|
||||
@@ -326,23 +325,22 @@ pub(crate) async fn create_join_event_v2_route(
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
if let Some(server) = body.room_id.server_name() {
|
||||
if services
|
||||
if let Some(server) = body.room_id.server_name()
|
||||
&& services
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.is_match(server.host())
|
||||
{
|
||||
warn!(
|
||||
"Server {} tried joining room ID {} through us which has a server name that is \
|
||||
globally forbidden. Rejecting.",
|
||||
body.origin(),
|
||||
&body.room_id,
|
||||
);
|
||||
{
|
||||
warn!(
|
||||
"Server {} tried joining room ID {} through us which has a server name that is \
|
||||
globally forbidden. Rejecting.",
|
||||
body.origin(),
|
||||
&body.room_id,
|
||||
);
|
||||
|
||||
return Err!(Request(Forbidden(warn!(
|
||||
"Room ID server name {server} is banned on this homeserver."
|
||||
))));
|
||||
}
|
||||
return Err!(Request(Forbidden(warn!(
|
||||
"Room ID server name {server} is banned on this homeserver."
|
||||
))));
|
||||
}
|
||||
|
||||
let create_join_event::v1::RoomState { auth_chain, state, event } =
|
||||
|
||||
@@ -39,20 +39,19 @@ pub(crate) async fn create_knock_event_v1_route(
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
if let Some(server) = body.room_id.server_name() {
|
||||
if services
|
||||
if let Some(server) = body.room_id.server_name()
|
||||
&& services
|
||||
.config
|
||||
.forbidden_remote_server_names
|
||||
.is_match(server.host())
|
||||
{
|
||||
warn!(
|
||||
"Server {} tried knocking room ID {} which has a server name that is globally \
|
||||
forbidden. Rejecting.",
|
||||
body.origin(),
|
||||
&body.room_id,
|
||||
);
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
{
|
||||
warn!(
|
||||
"Server {} tried knocking room ID {} which has a server name that is globally \
|
||||
forbidden. Rejecting.",
|
||||
body.origin(),
|
||||
&body.room_id,
|
||||
);
|
||||
return Err!(Request(Forbidden("Server is banned on this homeserver.")));
|
||||
}
|
||||
|
||||
if !services.metadata.exists(&body.room_id).await {
|
||||
|
||||
Reference in New Issue
Block a user