Raise 404 when room doesn't exist
Raise 404 "Room not found" when changing or accessing room visibility settings (`GET` and `PUT /_matrix/client/r0/directory/list/room/{roomId}`). See issue #290
This commit is contained in:
parent
2627ca5e3d
commit
6fd39ae174
1 changed files with 17 additions and 0 deletions
|
@ -85,6 +85,14 @@ pub async fn set_room_visibility_route(
|
||||||
) -> Result<set_room_visibility::v3::Response> {
|
) -> Result<set_room_visibility::v3::Response> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
|
if !db.rooms.exists(&body.room_id)? {
|
||||||
|
// Return 404 if the room doesn't exist
|
||||||
|
return Err(Error::BadRequest(
|
||||||
|
ErrorKind::NotFound,
|
||||||
|
"Room not found",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
match &body.visibility {
|
match &body.visibility {
|
||||||
room::Visibility::Public => {
|
room::Visibility::Public => {
|
||||||
services().rooms.directory.set_public(&body.room_id)?;
|
services().rooms.directory.set_public(&body.room_id)?;
|
||||||
|
@ -108,6 +116,15 @@ pub async fn set_room_visibility_route(
|
||||||
pub async fn get_room_visibility_route(
|
pub async fn get_room_visibility_route(
|
||||||
body: Ruma<get_room_visibility::v3::IncomingRequest>,
|
body: Ruma<get_room_visibility::v3::IncomingRequest>,
|
||||||
) -> Result<get_room_visibility::v3::Response> {
|
) -> Result<get_room_visibility::v3::Response> {
|
||||||
|
|
||||||
|
if !db.rooms.exists(&body.room_id)? {
|
||||||
|
// Return 404 if the room doesn't exist
|
||||||
|
return Err(Error::BadRequest(
|
||||||
|
ErrorKind::NotFound,
|
||||||
|
"Room not found",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(get_room_visibility::v3::Response {
|
Ok(get_room_visibility::v3::Response {
|
||||||
visibility: if services().rooms.directory.is_public_room(&body.room_id)? {
|
visibility: if services().rooms.directory.is_public_room(&body.room_id)? {
|
||||||
room::Visibility::Public
|
room::Visibility::Public
|
||||||
|
|
Loading…
Add table
Reference in a new issue