-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//! Endpoints in the `/_synapse/admin/v<x>/join/` scope. | ||
pub mod join_room; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//! Different versions of the endpoint to place users into rooms. | ||
pub mod v1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
//! [POST /_synapse/admin/v1/join/:room_id_or_alias](https://github.com/element-hq/synapse/blob/master/docs/admin_api/room_membership.md) | ||
use ruma::{ | ||
api::{request, response, Metadata}, | ||
metadata, OwnedRoomId, OwnedRoomOrAliasId, OwnedUserId, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
const METADATA: Metadata = metadata! { | ||
method: POST, | ||
rate_limited: false, | ||
authentication: AccessToken, | ||
history: { | ||
unstable => "/_synapse/admin/v1/join/:room_id_or_alias", | ||
} | ||
}; | ||
|
||
#[request] | ||
#[derive(Serialize, Deserialize, PartialEq)] | ||
pub struct Request { | ||
/// Alias or ID of the room to join. | ||
#[ruma_api(path)] | ||
pub room_id_or_alias: OwnedRoomOrAliasId, | ||
|
||
/// User to join the room. | ||
pub user_id: OwnedUserId, | ||
} | ||
|
||
#[response] | ||
#[derive(Serialize, Deserialize, PartialEq)] | ||
pub struct Response { | ||
/// Room ID of the joined room. | ||
pub room_id: OwnedRoomId, | ||
} | ||
|
||
impl Request { | ||
/// Creates a new `Request` with the given room or alias ID and user id. | ||
pub fn new(room_id_or_alias: OwnedRoomOrAliasId, user_id: OwnedUserId) -> Self { | ||
Self { room_id_or_alias, user_id } | ||
} | ||
} | ||
|
||
impl Response { | ||
/// Creates a new `Response` with the given room id | ||
pub fn new(room_id: OwnedRoomId) -> Self { | ||
Self { room_id } | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_join_room() { | ||
use ruma::{owned_room_id, owned_user_id, OwnedRoomId, OwnedUserId}; | ||
|
||
let room_id: OwnedRoomId = owned_room_id!("!test:example.com"); | ||
let user_id: OwnedUserId = owned_user_id!("@carl:example.com"); | ||
|
||
// Check create request | ||
let request = Request::new(room_id.to_owned().into(), user_id.to_owned()); | ||
|
||
// Serialize | ||
let serialized_request = serde_json::to_string(&request).expect("Failed to serialize request"); | ||
assert_eq!( | ||
serialized_request, | ||
"{\"room_id_or_alias\":\"!test:example.com\",\"user_id\":\"@carl:example.com\"}" | ||
); | ||
|
||
// Deserialize | ||
let deserialized_request: Request = | ||
serde_json::from_str(&serialized_request).expect("Failed to deserialize request"); | ||
assert_eq!(deserialized_request, request); | ||
|
||
// Check create response | ||
let response = Response::new(room_id.to_owned()); | ||
|
||
// Serialize | ||
let serialized_response = | ||
serde_json::to_string(&response).expect("Failed to serialize response"); | ||
assert_eq!(serialized_response, "{\"room_id\":\"!test:example.com\"}"); | ||
|
||
// Deserialize | ||
let deserialized_response: Response = | ||
serde_json::from_str(&serialized_response).expect("Failed to deserialize response"); | ||
assert_eq!(deserialized_response, response); | ||
} |