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
1 changed files with 53 additions and 53 deletions

View File

@ -1868,7 +1868,14 @@ pub fn get_state_events_route(
) -> MatrixResult<get_state_events::Response> {
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 {
room_state: db
.rooms
@ -1878,13 +1885,6 @@ pub fn get_state_events_route(
.map(|pdu| pdu.to_state_event())
.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(
@ -1900,7 +1900,14 @@ pub fn get_state_events_for_key_route(
) -> MatrixResult<get_state_events_for_key::Response> {
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
.rooms
.room_state(&body.room_id)
@ -1914,14 +1921,7 @@ pub fn get_state_events_for_key_route(
MatrixResult(Err(Error {
kind: ErrorKind::NotFound,
message: "State event not found.".to_owned(),
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,
status_code: http::StatusCode::NOT_FOUND,
}))
}
}
@ -1938,7 +1938,14 @@ pub fn get_state_events_for_empty_key_route(
) -> MatrixResult<get_state_events_for_key::Response> {
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
.rooms
.room_state(&body.room_id)
@ -1955,13 +1962,6 @@ pub fn get_state_events_for_empty_key_route(
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>")]