1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//! Members.
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::addr::Handle;
use crate::id::Id;
use crate::time::Timestamp;
unit_enum! {
/// Whether a member is a person or an agent.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
pub enum MemberKind {
/// A human.
Person = "person",
/// A K2 agent.
Agent = "agent",
}
}
unit_enum! {
/// What kind of agent a member is.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
pub enum AgentKind {
/// A team member in its own right.
Coworker = "coworker",
/// Pinned to one person; acts within that person's access.
Assistant = "assistant",
}
}
unit_enum! {
/// Install-wide role. Separate from space roles.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
pub enum InstallRole {
/// All install admin, plus transfer.
Owner = "owner",
/// Spaces, policies, members, guests. No content access to private channels or DMs.
Admin = "admin",
/// A regular member.
Member = "member",
/// A guest.
Guest = "guest",
/// A meeting link guest: made by redeeming a meeting
/// link, bound to one meeting channel, capped by `LINK_GUEST_MASK`, never a K2
/// principal. Every guest rule applies, and only the link-guest allowlist passes.
LinkGuest = "link_guest",
}
}
impl InstallRole {
/// A guest of either kind (guest or link guest): every guest rule applies.
pub const fn is_guest_kind(self) -> bool {
matches!(self, InstallRole::Guest | InstallRole::LinkGuest)
}
}
/// A member of the install, person or agent.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[non_exhaustive]
pub struct Member {
/// The member id.
pub id: Id,
/// Person or agent.
pub kind: MemberKind,
/// For agents, coworker or assistant.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub agent_kind: Option<AgentKind>,
/// For assistants, the member id of their person.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub assistant_of: Option<Id>,
/// Install-wide role.
pub install_role: InstallRole,
/// The handle.
pub username: Handle,
/// The display name.
pub display_name: String,
/// Job title.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub title: Option<String>,
/// Pronouns.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub pronouns: Option<String>,
/// Signed avatar URL.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub avatar_url: Option<String>,
/// Whether the member is deactivated.
pub deactivated: bool,
/// When the member was created.
pub created_at: Timestamp,
/// Email address; sent only to the member themself.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub email: Option<String>,
/// Whether the member holds the compliance flag; sent only to the member themself.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub compliance: Option<bool>,
/// 64 px signed avatar URL.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub avatar_thumb_url: Option<String>,
/// IANA timezone.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub timezone: Option<String>,
/// Status; absent when none or expired.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub status: Option<crate::api::people::MemberStatus>,
/// Bumped by every change of this object; clients drop older events.
#[serde(default)]
pub profile_rev: u64,
/// Custom field values the viewer may see; only on `GET /members/{id}` and the self object.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub custom_fields: Option<Vec<crate::api::people::ProfileFieldValue>>,
/// Fields the client must show read-only; self only.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub managed_fields: Option<Vec<String>>,
/// The member's K2 id (`k2:principal:<uuid>`, `k2:workspace:<uuid>` for agents, ...;
/// additive). Only on a K2-identity install, and only when the caller's session sees a
/// Space or DM shared with the member (an App session counts only its App's Spaces), or
/// on the self object. Never for guests or link guests; never on standalone installs.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub external_id: Option<String>,
/// The account was erased (omitted when false): `display_name` is "Deleted user" (clients
/// localise it by this flag), `username` is `erased-<id>` and is not shown, and there is no
/// avatar, title, pronouns, email or `external_id`.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub erased: bool,
}
impl Member {
/// A member with its required fields: active, every optional field unset.
pub fn new(
id: Id,
kind: MemberKind,
install_role: InstallRole,
username: Handle,
display_name: String,
created_at: Timestamp,
) -> Member {
Member {
id,
kind,
agent_kind: None,
assistant_of: None,
install_role,
username,
display_name,
title: None,
pronouns: None,
avatar_url: None,
deactivated: false,
created_at,
email: None,
compliance: None,
avatar_thumb_url: None,
timezone: None,
status: None,
profile_rev: 0,
custom_fields: None,
managed_fields: None,
external_id: None,
erased: false,
}
}
}
/// `external_id` on the client `Member` (listed in [`crate::mgmt::FEATURES`]).
pub const FEATURE_MEMBER_EXTERNAL_ID: &str = "member_external_id";
// ---------------------------------------------------------------- install roles and space members
unit_enum! {
/// An install role the install owner may give.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
pub enum SettableInstallRole {
/// Install admin.
Admin = "admin",
/// Regular member.
Member = "member",
}
}
/// Body of `POST /api/v1/install/members/{id}/role` (install owner only).
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct SetInstallRoleRequest {
/// The new role.
pub install_role: SettableInstallRole,
}
impl crate::error::Validate for SetInstallRoleRequest {
fn validate(&self) -> Result<(), crate::error::ValidationError> {
crate::error::check_known("install_role", self.install_role)
}
}