1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
use async_trait::async_trait;
#[allow(clippy::module_inception)]
mod groups;
mod models;
pub use models::*;
use crate::{models::ListAllParams, DracoonClientError};
/// This trait provides all methods to manage groups.
/// All sorting and filtering is implemented and can be found using respective '*Filter` or
/// '*SortBy' enums.
///
#[async_trait]
pub trait Groups {
/// Get a list of all groups.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Groups, groups::{GroupsFilter, GroupsSortBy}, models::{ListAllParams, SortOrder}};
/// # #[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();
/// // Params are optional
/// let params = ListAllParams::builder()
/// .with_filter(GroupsFilter::name_contains("test"))
/// .with_sort(GroupsSortBy::name(SortOrder::Desc))
/// .build();
/// // pass None if you don't want to use any params
/// let groups = dracoon.groups().get_groups(Some(params)).await.unwrap();
///
/// # }
/// ```
async fn get_groups(
&self,
params: Option<ListAllParams>,
) -> Result<GroupList, DracoonClientError>;
/// Create a group.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Groups, groups::{CreateGroupRequest}};
/// # #[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();
/// // There's no builder - use new and set the required field
/// let group = CreateGroupRequest::new("test_group", None);
/// let group = dracoon.groups().create_group(group).await.unwrap();
/// # }
/// ```
async fn create_group(&self, group: CreateGroupRequest) -> Result<Group, DracoonClientError>;
/// Get a group by id.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Groups};
/// # #[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();
/// let group = dracoon.groups().get_group(123).await.unwrap();
/// # }
/// ```
async fn get_group(&self, group_id: u64) -> Result<Group, DracoonClientError>;
/// Update a group by id.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Groups, groups::{UpdateGroupRequest}};
/// # #[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();
/// // There's no builder - use relevant methods to set the fields (name or expiration)
/// let update = UpdateGroupRequest::name("new_name");
/// let group = dracoon.groups().update_group(123, update).await.unwrap();
/// # }
/// ```
async fn update_group(
&self,
group_id: u64,
group: UpdateGroupRequest,
) -> Result<Group, DracoonClientError>;
/// Delete a group by id.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Groups};
/// # #[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();
/// dracoon.groups().delete_group(123).await.unwrap();
/// # }
/// ```
async fn delete_group(&self, group_id: u64) -> Result<(), DracoonClientError>;
/// Get a list of all groups.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Groups, groups::{GroupUsersFilter}, models::{ListAllParams, SortOrder}};
/// # #[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();
/// // Params are optional
/// let params = ListAllParams::builder()
/// .with_filter(GroupUsersFilter::user_contains("test"))
/// .build();
/// // pass None if you don't want to use any params
/// let groups = dracoon.groups().get_group_users(123, Some(params)).await.unwrap();
///
/// # }
/// ```
async fn get_group_users(
&self,
group_id: u64,
params: Option<ListAllParams>,
) -> Result<GroupUserList, DracoonClientError>;
/// Add users to a group.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Groups, groups::{ChangeGroupMembersRequest}};
/// # #[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 pass a vec and use into()
/// let user_ids = vec![1, 2, 3];
/// dracoon.groups().add_group_users(123, user_ids.into()).await.unwrap();
/// // or use the ChangeGroupMembersRequest
/// let user_ids = ChangeGroupMembersRequest::new(vec![1, 2, 3]);
/// dracoon.groups().add_group_users(123, user_ids).await.unwrap();
/// # }
/// ```
async fn add_group_users(
&self,
group_id: u64,
user_ids: ChangeGroupMembersRequest,
) -> Result<Group, DracoonClientError>;
/// Remove users from a group.
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Groups, groups::{ChangeGroupMembersRequest}};
/// # #[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 pass a vec and use into()
/// let user_ids = vec![1, 2, 3];
/// dracoon.groups().add_group_users(123, user_ids.into()).await.unwrap();
/// // or use the ChangeGroupMembersRequest
/// let user_ids = ChangeGroupMembersRequest::new(vec![1, 2, 3]);
/// dracoon.groups().remove_group_users(123, user_ids).await.unwrap();
/// # }
/// ```
async fn remove_group_users(
&self,
group_id: u64,
user_ids: ChangeGroupMembersRequest,
) -> Result<Group, DracoonClientError>;
/// Get group last admin rooms
/// ```no_run
/// # use dco3::{Dracoon, auth::OAuth2Flow, Groups};
/// # #[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();
/// let rooms = dracoon.groups().get_group_last_admin_rooms(123).await.unwrap();
/// # }
/// ```
async fn get_group_last_admin_rooms(
&self,
group_id: u64,
) -> Result<LastAdminGroupRoomList, DracoonClientError>;
}