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