apply new rustfmt.toml changes, fix some clippy lints
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
0317cc8cc5
commit
77e0b76408
296 changed files with 7147 additions and 4300 deletions
|
@ -31,7 +31,8 @@ use crate::{Ruma, RumaResponse};
|
|||
/// allowed
|
||||
/// - If event is new `canonical_alias`: Rejects if alias is incorrect
|
||||
pub(crate) async fn send_state_event_for_key_route(
|
||||
State(services): State<crate::State>, body: Ruma<send_state_event::v3::Request>,
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<send_state_event::v3::Request>,
|
||||
) -> Result<send_state_event::v3::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
|
@ -63,7 +64,8 @@ pub(crate) async fn send_state_event_for_key_route(
|
|||
/// allowed
|
||||
/// - If event is new `canonical_alias`: Rejects if alias is incorrect
|
||||
pub(crate) async fn send_state_event_for_empty_key_route(
|
||||
State(services): State<crate::State>, body: Ruma<send_state_event::v3::Request>,
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<send_state_event::v3::Request>,
|
||||
) -> Result<RumaResponse<send_state_event::v3::Response>> {
|
||||
send_state_event_for_key_route(State(services), body)
|
||||
.await
|
||||
|
@ -77,7 +79,8 @@ pub(crate) async fn send_state_event_for_empty_key_route(
|
|||
/// - If not joined: Only works if current room history visibility is world
|
||||
/// readable
|
||||
pub(crate) async fn get_state_events_route(
|
||||
State(services): State<crate::State>, body: Ruma<get_state_events::v3::Request>,
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_state_events::v3::Request>,
|
||||
) -> Result<get_state_events::v3::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
|
@ -111,7 +114,8 @@ pub(crate) async fn get_state_events_route(
|
|||
/// - If not joined: Only works if current room history visibility is world
|
||||
/// readable
|
||||
pub(crate) async fn get_state_events_for_key_route(
|
||||
State(services): State<crate::State>, body: Ruma<get_state_events_for_key::v3::Request>,
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_state_events_for_key::v3::Request>,
|
||||
) -> Result<get_state_events_for_key::v3::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
|
@ -157,7 +161,8 @@ pub(crate) async fn get_state_events_for_key_route(
|
|||
/// - If not joined: Only works if current room history visibility is world
|
||||
/// readable
|
||||
pub(crate) async fn get_state_events_for_empty_key_route(
|
||||
State(services): State<crate::State>, body: Ruma<get_state_events_for_key::v3::Request>,
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_state_events_for_key::v3::Request>,
|
||||
) -> Result<RumaResponse<get_state_events_for_key::v3::Response>> {
|
||||
get_state_events_for_key_route(State(services), body)
|
||||
.await
|
||||
|
@ -165,8 +170,13 @@ pub(crate) async fn get_state_events_for_empty_key_route(
|
|||
}
|
||||
|
||||
async fn send_state_event_for_key_helper(
|
||||
services: &Services, sender: &UserId, room_id: &RoomId, event_type: &StateEventType,
|
||||
json: &Raw<AnyStateEventContent>, state_key: String, timestamp: Option<ruma::MilliSecondsSinceUnixEpoch>,
|
||||
services: &Services,
|
||||
sender: &UserId,
|
||||
room_id: &RoomId,
|
||||
event_type: &StateEventType,
|
||||
json: &Raw<AnyStateEventContent>,
|
||||
state_key: String,
|
||||
timestamp: Option<ruma::MilliSecondsSinceUnixEpoch>,
|
||||
) -> Result<Arc<EventId>> {
|
||||
allowed_to_send_state_event(services, room_id, event_type, json).await?;
|
||||
let state_lock = services.rooms.state.mutex.lock(room_id).await;
|
||||
|
@ -191,20 +201,27 @@ async fn send_state_event_for_key_helper(
|
|||
}
|
||||
|
||||
async fn allowed_to_send_state_event(
|
||||
services: &Services, room_id: &RoomId, event_type: &StateEventType, json: &Raw<AnyStateEventContent>,
|
||||
services: &Services,
|
||||
room_id: &RoomId,
|
||||
event_type: &StateEventType,
|
||||
json: &Raw<AnyStateEventContent>,
|
||||
) -> Result {
|
||||
match event_type {
|
||||
// Forbid m.room.encryption if encryption is disabled
|
||||
StateEventType::RoomEncryption => {
|
||||
| StateEventType::RoomEncryption =>
|
||||
if !services.globals.allow_encryption() {
|
||||
return Err(Error::BadRequest(ErrorKind::forbidden(), "Encryption has been disabled"));
|
||||
}
|
||||
},
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::forbidden(),
|
||||
"Encryption has been disabled",
|
||||
));
|
||||
},
|
||||
// admin room is a sensitive room, it should not ever be made public
|
||||
StateEventType::RoomJoinRules => {
|
||||
| StateEventType::RoomJoinRules => {
|
||||
if let Ok(admin_room_id) = services.admin.get_admin_room().await {
|
||||
if admin_room_id == room_id {
|
||||
if let Ok(join_rule) = serde_json::from_str::<RoomJoinRulesEventContent>(json.json().get()) {
|
||||
if let Ok(join_rule) =
|
||||
serde_json::from_str::<RoomJoinRulesEventContent>(json.json().get())
|
||||
{
|
||||
if join_rule.join_rule == JoinRule::Public {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::forbidden(),
|
||||
|
@ -216,16 +233,20 @@ async fn allowed_to_send_state_event(
|
|||
}
|
||||
},
|
||||
// admin room is a sensitive room, it should not ever be made world readable
|
||||
StateEventType::RoomHistoryVisibility => {
|
||||
| StateEventType::RoomHistoryVisibility => {
|
||||
if let Ok(admin_room_id) = services.admin.get_admin_room().await {
|
||||
if admin_room_id == room_id {
|
||||
if let Ok(visibility_content) =
|
||||
serde_json::from_str::<RoomHistoryVisibilityEventContent>(json.json().get())
|
||||
if let Ok(visibility_content) = serde_json::from_str::<
|
||||
RoomHistoryVisibilityEventContent,
|
||||
>(json.json().get())
|
||||
{
|
||||
if visibility_content.history_visibility == HistoryVisibility::WorldReadable {
|
||||
if visibility_content.history_visibility
|
||||
== HistoryVisibility::WorldReadable
|
||||
{
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::forbidden(),
|
||||
"Admin room is not allowed to be made world readable (public room history).",
|
||||
"Admin room is not allowed to be made world readable (public \
|
||||
room history).",
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -233,8 +254,10 @@ async fn allowed_to_send_state_event(
|
|||
}
|
||||
},
|
||||
// TODO: allow alias if it previously existed
|
||||
StateEventType::RoomCanonicalAlias => {
|
||||
if let Ok(canonical_alias) = serde_json::from_str::<RoomCanonicalAliasEventContent>(json.json().get()) {
|
||||
| StateEventType::RoomCanonicalAlias => {
|
||||
if let Ok(canonical_alias) =
|
||||
serde_json::from_str::<RoomCanonicalAliasEventContent>(json.json().get())
|
||||
{
|
||||
let mut aliases = canonical_alias.alt_aliases.clone();
|
||||
|
||||
if let Some(alias) = canonical_alias.alias {
|
||||
|
@ -243,7 +266,9 @@ async fn allowed_to_send_state_event(
|
|||
|
||||
for alias in aliases {
|
||||
if !services.globals.server_is_ours(alias.server_name()) {
|
||||
return Err!(Request(Forbidden("canonical_alias must be for this server")));
|
||||
return Err!(Request(Forbidden(
|
||||
"canonical_alias must be for this server"
|
||||
)));
|
||||
}
|
||||
|
||||
if !services
|
||||
|
@ -255,13 +280,14 @@ async fn allowed_to_send_state_event(
|
|||
// Make sure it's the right room
|
||||
{
|
||||
return Err!(Request(Forbidden(
|
||||
"You are only allowed to send canonical_alias events when its aliases already exist"
|
||||
"You are only allowed to send canonical_alias events when its \
|
||||
aliases already exist"
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
| _ => (),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue