synapse_admin_api/
users.rs

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