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