Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/0.17.0 #44

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dco3"
version = "0.16.1"
version = "0.17.0"
edition = "2021"
authors = ["Octavio Simone"]
repository = "https://github.com/unbekanntes-pferd/dco3"
Expand Down
1 change: 1 addition & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub const ROOMS_ENCRYPT: &str = "encrypt";
pub const ROOMS_USERS: &str = "users";
pub const ROOMS_GROUPS: &str = "groups";
pub const ROOMS_POLICIES: &str = "policies";
pub const ROOMS_GUEST_USERS: &str = "guest_users";
// note: needed for NFS upload (DRACOON Server)
pub const UPLOADS_BASE: &str = "uploads";

Expand Down
25 changes: 25 additions & 0 deletions src/nodes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,31 @@ pub trait Rooms {
room_id: u64,
room_users_del_req: RoomUsersDeleteBatchRequest,
) -> Result<(), DracoonClientError>;
/// Deletes room users by id.
/// Gets groups of a room by id with optional params.
/// ```no_run
/// # use dco3::{Dracoon, OAuth2Flow, Rooms, nodes::RoomGuestUserInvitation};
/// # #[tokio::main]
/// # async fn main() {
/// # let dracoon = Dracoon::builder()
/// # .with_base_url("https://dracoon.team")
/// # .with_client_id("client_id")
/// # .with_client_secret("client_secret")
/// # .build()
/// # .unwrap()
/// # .connect(OAuth2Flow::PasswordFlow("username".into(), "password".into()))
/// # .await
/// # .unwrap();
/// // You can use a vec
/// let guest = RoomGuestUserInvitation::new("email", "first name", "last name");
/// dracoon.nodes().invite_guest_users(123, vec![guest].into()).await.unwrap();
/// # }
/// ```
async fn invite_guest_users(
&self,
room_id: u64,
invite_req: RoomGuestUserAddRequest,
) -> Result<(), DracoonClientError>;
}
/// This trait represents the download functionality and provides
/// a signle method to download a stream of bytes to a writer.
Expand Down
34 changes: 32 additions & 2 deletions src/nodes/rooms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
client::{errors::DracoonClientError, Connected},
constants::{
DRACOON_API_PREFIX, NODES_BASE, ROOMS_BASE, ROOMS_CONFIG, ROOMS_ENCRYPT, ROOMS_GROUPS,
ROOMS_POLICIES, ROOMS_USERS,
ROOMS_GUEST_USERS, ROOMS_POLICIES, ROOMS_USERS,
},
models::ListAllParams,
utils::FromResponse,
Expand All @@ -17,7 +17,7 @@ use self::models::{
RoomUserList, RoomUsersAddBatchRequest, RoomUsersDeleteBatchRequest, UpdateRoomRequest,
};

use super::{models::Node, NodesEndpoint, Rooms};
use super::{models::Node, NodesEndpoint, RoomGuestUserAddRequest, Rooms};

pub mod models;

Expand Down Expand Up @@ -343,4 +343,34 @@ impl Rooms for NodesEndpoint<Connected> {

Ok(())
}

async fn invite_guest_users(
&self,
room_id: u64,
invite_req: RoomGuestUserAddRequest,
) -> Result<(), DracoonClientError> {
let url_part = format!(
"/{DRACOON_API_PREFIX}/{NODES_BASE}/{ROOMS_BASE}/{room_id}/{ROOMS_GUEST_USERS}"
);
let api_url = self.client().build_api_url(&url_part);

let response = self
.client()
.http
.put(api_url)
.header(
header::AUTHORIZATION,
self.client().get_auth_header().await?,
)
.header(header::CONTENT_TYPE, "application/json")
.json(&invite_req)
.send()
.await?;

if response.status().is_client_error() || response.status().is_server_error() {
return Err(DracoonClientError::from_response(response).await?);
}

Ok(())
}
}
36 changes: 36 additions & 0 deletions src/nodes/rooms/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,3 +655,39 @@ impl From<Vec<u64>> for RoomUsersDeleteBatchRequest {
RoomUsersDeleteBatchRequest { ids }
}
}

#[derive(Debug, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct RoomGuestUserAddRequest {
room_guest_invitations: Vec<RoomGuestUserInvitation>,
}

#[derive(Debug, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct RoomGuestUserInvitation {
email: String,
first_name: String,
last_name: String,
}

impl RoomGuestUserInvitation {
pub fn new(
email: impl Into<String>,
first_name: impl Into<String>,
last_name: impl Into<String>,
) -> Self {
RoomGuestUserInvitation {
email: email.into(),
first_name: first_name.into(),
last_name: last_name.into(),
}
}
}

impl From<Vec<RoomGuestUserInvitation>> for RoomGuestUserAddRequest {
fn from(room_guest_invitations: Vec<RoomGuestUserInvitation>) -> Self {
RoomGuestUserAddRequest {
room_guest_invitations,
}
}
}
26 changes: 24 additions & 2 deletions src/tests/rooms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ mod tests {
use crate::{
nodes::{
ConfigRoomRequest, CreateRoomRequest, EncryptRoomRequest, GroupMemberAcceptance,
NodePermissions, RoomGroup, RoomGroupsAddBatchRequestItem, RoomPoliciesRequest,
RoomUser, RoomUsersAddBatchRequestItem, UpdateRoomRequest, UserType,
NodePermissions, RoomGroup, RoomGroupsAddBatchRequestItem, RoomGuestUserInvitation,
RoomPoliciesRequest, RoomUser, RoomUsersAddBatchRequestItem, UpdateRoomRequest,
UserType,
},
tests::{dracoon::get_connected_client, nodes::tests::assert_node},
ListAllParams, Rooms,
Expand Down Expand Up @@ -498,4 +499,25 @@ mod tests {

room_groups_mock.assert();
}

#[tokio::test]
async fn test_invite_guest_users() {
let (client, mut mock_server) = get_connected_client().await;

let room_guests_mock = mock_server
.mock("PUT", "/api/v4/nodes/rooms/123/guest_users")
.with_status(204)
.create();

let guest = RoomGuestUserInvitation::new("[email protected]", "first", "last");

let result = client
.nodes()
.invite_guest_users(123, vec![guest].into())
.await;

assert!(result.is_ok());

room_guests_mock.assert();
}
}
Loading