synapse_admin_api/users/create_or_modify/v2.rs
1//! [PUT /_synapse/admin/v2/users/:user_id](https://github.com/matrix-org/synapse/blob/master/docs/admin_api/user_admin_api.rst#create-or-modify-account)
2
3use ruma::{
4 api::{metadata, request, response, Metadata},
5 thirdparty::ThirdPartyIdentifier,
6 OwnedUserId,
7};
8
9pub use crate::users::{ExternalId, UserDetails};
10
11const METADATA: Metadata = metadata! {
12 method: PUT,
13 rate_limited: false,
14 authentication: AccessToken,
15 history: {
16 unstable => "/_synapse/admin/v2/users/:user_id",
17 }
18};
19
20#[request]
21pub struct Request {
22 /// User ID for the account to renew
23 #[ruma_api(path)]
24 pub user_id: OwnedUserId,
25
26 /// This is an optional parameter. Add this parameter to create an account or set this
27 /// password as new one for an existing account.
28 pub password: Option<String>,
29
30 // NOTE: Server explodes if attributes are not omitted but specified as null, like the default
31 // Serde case.
32 /// Defaults to user_id, or the current value if user already exists
33 /// Some("") is treated as setting it to null.
34 #[serde(skip_serializing_if = "Option::is_none")]
35 pub displayname: Option<String>,
36
37 /// Defaults to empty, or the current value if user already exists
38 #[serde(skip_serializing_if = "Option::is_none")]
39 pub threepids: Option<Vec<ThirdPartyIdentifier>>,
40
41 /// Defaults to empty, or the current value if user already exists
42 #[serde(skip_serializing_if = "Option::is_none")]
43 pub external_ids: Option<Vec<ExternalId>>,
44
45 /// The user's avatar URL, if set.
46 #[serde(skip_serializing_if = "Option::is_none")]
47 pub avatar_url: Option<String>,
48
49 /// Should the user be a server admin
50 /// defaults to false, or the current value if user already exists
51 #[serde(skip_serializing_if = "Option::is_none")]
52 pub admin: Option<bool>,
53
54 /// Should the user be deactivated
55 /// defaults to false, or the current value if user already exists
56 #[serde(skip_serializing_if = "Option::is_none")]
57 pub deactivated: Option<bool>,
58
59 /// Whether the user should be locked.
60 ///
61 /// Defaults to false, or the current value if user already exists.
62 #[serde(skip_serializing_if = "Option::is_none")]
63 pub locked: Option<bool>,
64}
65
66#[response]
67pub struct Response {
68 /// Details about the user.
69 #[ruma_api(body)]
70 pub details: UserDetails,
71}
72
73// todo following to does are from synadminctl
74// TODO: returns 200 if account-exist-and-was-updated,
75// but 201 CREATED if a new account was created.
76// However, ruma does throw away this information.
77
78// TODO: what do the EndpointErrors?
79// -> can I add custom code, which converts http::Response into ruma embedded error type
80// The error is necessary at least at all endpoints which need auth, because a invalid login
81// response such an error
82// TODO: Should this be the real error like at ruma client api error, is Void-Default enough?
83// TODO: ruma api serialisis Ok if status code < 400, alse error. That should be diskussed.
84// The redirect 300 area is Ok too.
85
86impl Request {
87 /// Creates a Request with the user ID and the optional password.
88 pub fn new(user_id: OwnedUserId, password: Option<String>) -> Self {
89 Self {
90 user_id,
91 password,
92 displayname: None,
93 threepids: None,
94 external_ids: None,
95 avatar_url: None,
96 admin: None,
97 deactivated: None,
98 locked: None,
99 }
100 }
101}
102
103impl Response {
104 /// Creates a new `Response` with the user details.
105 pub fn new(details: UserDetails) -> Self {
106 Self { details }
107 }
108}