refactor: small changes

This commit is contained in:
timokoesters 2020-06-03 16:24:00 +02:00
parent 19c9e4b916
commit 325e373684
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4

View file

@ -1868,7 +1868,14 @@ pub fn get_state_events_route(
) -> MatrixResult<get_state_events::Response> { ) -> MatrixResult<get_state_events::Response> {
let user_id = body.user_id.as_ref().expect("user is authenticated"); let user_id = body.user_id.as_ref().expect("user is authenticated");
if db.rooms.is_joined(user_id, &body.room_id).unwrap() { if !db.rooms.is_joined(user_id, &body.room_id).unwrap() {
return MatrixResult(Err(Error {
kind: ErrorKind::Forbidden,
message: "You don't have permission to view the room state.".to_owned(),
status_code: http::StatusCode::FORBIDDEN,
}));
}
MatrixResult(Ok(get_state_events::Response { MatrixResult(Ok(get_state_events::Response {
room_state: db room_state: db
.rooms .rooms
@ -1878,13 +1885,6 @@ pub fn get_state_events_route(
.map(|pdu| pdu.to_state_event()) .map(|pdu| pdu.to_state_event())
.collect(), .collect(),
})) }))
} else {
MatrixResult(Err(Error {
kind: ErrorKind::Forbidden,
message: "You don't have permission to view the room state.".to_owned(),
status_code: http::StatusCode::BAD_REQUEST,
}))
}
} }
#[get( #[get(
@ -1900,7 +1900,14 @@ pub fn get_state_events_for_key_route(
) -> MatrixResult<get_state_events_for_key::Response> { ) -> MatrixResult<get_state_events_for_key::Response> {
let user_id = body.user_id.as_ref().expect("user is authenticated"); let user_id = body.user_id.as_ref().expect("user is authenticated");
if db.rooms.is_joined(user_id, &body.room_id).unwrap() { if !db.rooms.is_joined(user_id, &body.room_id).unwrap() {
return MatrixResult(Err(Error {
kind: ErrorKind::Forbidden,
message: "You don't have permission to view the room state.".to_owned(),
status_code: http::StatusCode::FORBIDDEN,
}));
}
if let Some(event) = db if let Some(event) = db
.rooms .rooms
.room_state(&body.room_id) .room_state(&body.room_id)
@ -1914,14 +1921,7 @@ pub fn get_state_events_for_key_route(
MatrixResult(Err(Error { MatrixResult(Err(Error {
kind: ErrorKind::NotFound, kind: ErrorKind::NotFound,
message: "State event not found.".to_owned(), message: "State event not found.".to_owned(),
status_code: http::StatusCode::BAD_REQUEST, status_code: http::StatusCode::NOT_FOUND,
}))
}
} else {
MatrixResult(Err(Error {
kind: ErrorKind::Forbidden,
message: "You don't have permission to view the room state.".to_owned(),
status_code: http::StatusCode::BAD_REQUEST,
})) }))
} }
} }
@ -1938,7 +1938,14 @@ pub fn get_state_events_for_empty_key_route(
) -> MatrixResult<get_state_events_for_key::Response> { ) -> MatrixResult<get_state_events_for_key::Response> {
let user_id = body.user_id.as_ref().expect("user is authenticated"); let user_id = body.user_id.as_ref().expect("user is authenticated");
if db.rooms.is_joined(user_id, &body.room_id).unwrap() { if !db.rooms.is_joined(user_id, &body.room_id).unwrap() {
return MatrixResult(Err(Error {
kind: ErrorKind::Forbidden,
message: "You don't have permission to view the room state.".to_owned(),
status_code: http::StatusCode::FORBIDDEN,
}));
}
if let Some(event) = db if let Some(event) = db
.rooms .rooms
.room_state(&body.room_id) .room_state(&body.room_id)
@ -1955,13 +1962,6 @@ pub fn get_state_events_for_empty_key_route(
status_code: http::StatusCode::BAD_REQUEST, status_code: http::StatusCode::BAD_REQUEST,
})) }))
} }
} else {
MatrixResult(Err(Error {
kind: ErrorKind::Forbidden,
message: "You don't have permission to view the room state.".to_owned(),
status_code: http::StatusCode::BAD_REQUEST,
}))
}
} }
#[get("/_matrix/client/r0/sync", data = "<body>")] #[get("/_matrix/client/r0/sync", data = "<body>")]