synapse_admin_api/
users.rs

1//! Endpoints in the `/_synapse/admin/v<x>/users/` scope.
2
3pub mod create_or_modify;
4pub mod get_details;
5pub mod is_user_admin;
6pub mod list_joined_rooms;
7pub mod list_users;
8pub mod reset_password;
9
10use ruma::{thirdparty::ThirdPartyIdentifier, SecondsSinceUnixEpoch};
11use serde::{Deserialize, Serialize};
12
13/// User details
14#[derive(Serialize, Deserialize, Clone, Debug)]
15#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
16pub struct UserDetails {
17    /// The user's name.
18    pub name: String,
19
20    /// The password hash of the account
21    pub password_hash: Option<String>,
22
23    /// Is the account a guest
24    #[serde(deserialize_with = "crate::serde::bool_or_uint")]
25    pub is_guest: bool,
26
27    /// Is the user a server admin
28    #[serde(deserialize_with = "crate::serde::bool_or_uint")]
29    pub admin: bool,
30
31    /// todo: doc but I do not know what this is
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub consent_version: Option<String>,
34
35    /// todo: doc but I do not know what this is
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub consent_server_notice_sent: Option<bool>,
38
39    /// todo: doc but I do not know what this is
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub appservice_id: Option<String>,
42
43    /// creation date for the account
44    // todo: how to get rid of this option?
45    pub creation_ts: Option<SecondsSinceUnixEpoch>,
46
47    /// todo: doc but I do not know what this is
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub user_type: Option<String>,
50
51    /// Is the account deactivated
52    #[serde(deserialize_with = "crate::serde::bool_or_uint")]
53    pub deactivated: bool,
54
55    /// The user's display name, if set.
56    pub displayname: String,
57
58    /// The user's avatar URL, if set.
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub avatar_url: Option<String>,
61
62    /// A list of third party identifiers the homeserver has associated with the user.
63    #[serde(default, skip_serializing_if = "Vec::is_empty")]
64    pub threepids: Vec<ThirdPartyIdentifier>,
65
66    /// A list of external auth identifiers the homeserver has associated with the user.
67    #[serde(default, skip_serializing_if = "Vec::is_empty")]
68    pub external_ids: Vec<ExternalId>,
69
70    /// Is the account locked
71    #[serde(default, deserialize_with = "crate::serde::bool_or_uint")]
72    pub locked: bool,
73}
74
75impl UserDetails {
76    /// Construct a `UserDetails` with the given user name and all the other fields set to their
77    /// default value.
78    pub fn new(name: String) -> Self {
79        Self {
80            name,
81            password_hash: None,
82            is_guest: false,
83            admin: false,
84            consent_version: None,
85            consent_server_notice_sent: None,
86            appservice_id: None,
87            creation_ts: None,
88            user_type: None,
89            deactivated: false,
90            displayname: String::new(),
91            avatar_url: None,
92            threepids: Vec::new(),
93            external_ids: Vec::new(),
94            locked: false,
95        }
96    }
97}
98
99/// An external ID associated with a user
100#[derive(Clone, Debug, Deserialize, Serialize)]
101#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
102pub struct ExternalId {
103    /// The authentication provider to which the user is associated.
104    pub auth_provider: String,
105
106    /// The ID known to the auth provider associated with this user.
107    pub external_id: String,
108}
109
110impl ExternalId {
111    /// Construct an `ExternalId` with the given authentication provider and ID.
112    pub fn new(auth_provider: String, external_id: String) -> Self {
113        Self { auth_provider, external_id }
114    }
115}