de-global server_is_ours / user_is_local

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-22 07:43:51 +00:00
parent 010e4ee35a
commit 59efabbbc2
34 changed files with 179 additions and 169 deletions

View file

@ -7,7 +7,6 @@ use ruma::{
serde::JsonObject,
CanonicalJsonValue, EventId, OwnedUserId,
};
use service::server_is_ours;
use crate::Ruma;
@ -88,7 +87,7 @@ pub(crate) async fn create_invite_route(
)
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "state_key is not a user ID."))?;
if !server_is_ours(invited_user.server_name()) {
if !services.globals.server_is_ours(invited_user.server_name()) {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"User does not belong to this homeserver.",

View file

@ -1,4 +1,5 @@
use axum::extract::State;
use conduit::{Error, Result};
use get_profile_information::v1::ProfileField;
use rand::seq::SliceRandom;
use ruma::{
@ -9,7 +10,7 @@ use ruma::{
OwnedServerName,
};
use crate::{service::server_is_ours, Error, Result, Ruma};
use crate::Ruma;
/// # `GET /_matrix/federation/v1/query/directory`
///
@ -64,7 +65,7 @@ pub(crate) async fn get_profile_information_route(
));
}
if !server_is_ours(body.user_id.server_name()) {
if !services.globals.server_is_ours(body.user_id.server_name()) {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"User does not belong to this server.",

View file

@ -3,7 +3,7 @@
use std::collections::BTreeMap;
use axum::extract::State;
use conduit::{Error, Result};
use conduit::{pdu::gen_event_id_canonical_json, warn, Error, Result};
use ruma::{
api::{client::error::ErrorKind, federation::membership::create_join_event},
events::{
@ -13,9 +13,8 @@ use ruma::{
CanonicalJsonValue, OwnedServerName, OwnedUserId, RoomId, ServerName,
};
use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
use service::{pdu::gen_event_id_canonical_json, user_is_local, Services};
use service::Services;
use tokio::sync::RwLock;
use tracing::warn;
use crate::Ruma;
@ -126,7 +125,7 @@ async fn create_join_event(
if content
.join_authorized_via_users_server
.is_some_and(|user| user_is_local(&user))
.is_some_and(|user| services.globals.user_is_local(&user))
&& super::user_can_perform_restricted_join(services, &sender, room_id, &room_version_id).unwrap_or_default()
{
ruma::signatures::hash_and_sign_event(

View file

@ -3,6 +3,7 @@
use std::collections::BTreeMap;
use axum::extract::State;
use conduit::{Error, Result};
use ruma::{
api::{client::error::ErrorKind, federation::membership::create_leave_event},
events::{
@ -15,8 +16,8 @@ use serde_json::value::RawValue as RawJsonValue;
use tokio::sync::RwLock;
use crate::{
service::{pdu::gen_event_id_canonical_json, server_is_ours, Services},
Error, Result, Ruma,
service::{pdu::gen_event_id_canonical_json, Services},
Ruma,
};
/// # `PUT /_matrix/federation/v1/send_leave/{roomId}/{eventId}`
@ -174,7 +175,7 @@ async fn create_leave_event(
.state_cache
.room_servers(room_id)
.filter_map(Result::ok)
.filter(|server| !server_is_ours(server));
.filter(|server| !services.globals.server_is_ours(server));
services.sending.send_pdu_servers(servers, &pdu_id)?;

View file

@ -1,4 +1,5 @@
use axum::extract::State;
use conduit::{Error, Result};
use ruma::api::{
client::error::ErrorKind,
federation::{
@ -9,8 +10,7 @@ use ruma::api::{
use crate::{
client::{claim_keys_helper, get_keys_helper},
service::user_is_local,
Error, Result, Ruma,
Ruma,
};
/// # `GET /_matrix/federation/v1/user/devices/{userId}`
@ -19,7 +19,7 @@ use crate::{
pub(crate) async fn get_devices_route(
State(services): State<crate::State>, body: Ruma<get_devices::v1::Request>,
) -> Result<get_devices::v1::Response> {
if !user_is_local(&body.user_id) {
if !services.globals.user_is_local(&body.user_id) {
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Tried to access user from other server.",
@ -72,7 +72,11 @@ pub(crate) async fn get_devices_route(
pub(crate) async fn get_keys_route(
State(services): State<crate::State>, body: Ruma<get_keys::v1::Request>,
) -> Result<get_keys::v1::Response> {
if body.device_keys.iter().any(|(u, _)| !user_is_local(u)) {
if body
.device_keys
.iter()
.any(|(u, _)| !services.globals.user_is_local(u))
{
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"User does not belong to this server.",
@ -101,7 +105,11 @@ pub(crate) async fn get_keys_route(
pub(crate) async fn claim_keys_route(
State(services): State<crate::State>, body: Ruma<claim_keys::v1::Request>,
) -> Result<claim_keys::v1::Response> {
if body.one_time_keys.iter().any(|(u, _)| !user_is_local(u)) {
if body
.one_time_keys
.iter()
.any(|(u, _)| !services.globals.user_is_local(u))
{
return Err(Error::BadRequest(
ErrorKind::InvalidParam,
"Tried to access user from other server.",