BlueGit

ict rusty-teams

Files

rusty-teams / crates / app-state / src / demo_profiles.rs

demo_profiles.rs

d39bdfed History
demo_profiles.rs 6.6 KiB Download Raw
1use std::sync::atomic::{AtomicBool, Ordering};
2use std::time::Duration;
3
4use teams_core::{
5 Availability, OrgPerson, PersonProfile, WorkLocation, WorkLocationKind, WorkLocationSource,
6};
7
8use crate::demo::{DEMO_USER_ID, JONAS_ID, LEA_ID, MARA_ID, PRIYA_ID, TOBIAS_ID};
9
10const DELAY_VARIABLE: &str = "TEAMS_DEMO_PROFILE_DELAY_MS";
11const DEFAULT_DELAY: Duration = Duration::from_millis(500);
12const HENRIK_ID: &str = "demo-henrik";
13const SOFIA_ID: &str = "demo-sofia";
14const OMAR_ID: &str = "demo-omar";
15const LONG_STATUS: &str = "Heads down on the Q4 roadmap review until Thursday. Please use the Product channel for anything that can wait and call my mobile only for production incidents. Back to normal office hours next week, and I will answer open threads then.";
16const OUT_OF_OFFICE: &str = "I am out of office until 20 October with limited access to email. For urgent customer matters please contact Tobias Klein.";
17
18static TOBIAS_FAILED_ONCE: AtomicBool = AtomicBool::new(false);
19
20fn person(id: &str, name: &str, title: &str) -> OrgPerson {
21 OrgPerson {
22 id: id.to_owned(),
23 display_name: Some(name.to_owned()),
24 job_title: Some(title.to_owned()),
25 }
26}
27
28fn base(id: &str, name: &str, title: &str, department: &str) -> PersonProfile {
29 let address = name.to_lowercase().replace(' ', ".");
30 PersonProfile {
31 user_id: id.to_owned(),
32 display_name: Some(name.to_owned()),
33 job_title: Some(title.to_owned()),
34 department: Some(department.to_owned()),
35 company: Some("Example Corp".to_owned()),
36 office_location: Some("Berlin, Building A".to_owned()),
37 email: Some(format!("{address}@example.com")),
38 work_phones: vec!["+49 30 5550 1000".to_owned()],
39 mobile_phone: Some("+49 151 5550 2000".to_owned()),
40 manager: None,
41 direct_reports: Vec::new(),
42 time_zone: Some("W. Europe Standard Time".to_owned()),
43 availability: Some(Availability::Available),
44 status_message: None,
45 out_of_office: None,
46 work_location: None,
47 }
48}
49
50fn henrik() -> OrgPerson {
51 person(HENRIK_ID, "Henrik Vogt", "VP Engineering")
52}
53
54fn priya() -> OrgPerson {
55 person(PRIYA_ID, "Priya Nair", "Engineering Manager")
56}
57
58pub fn profile(user_id: &str) -> Option<PersonProfile> {
59 Some(match user_id {
60 MARA_ID => PersonProfile {
61 manager: Some(henrik()),
62 availability: Some(Availability::Busy),
63 status_message: Some(LONG_STATUS.to_owned()),
64 work_location: Some(WorkLocation {
65 kind: WorkLocationKind::Office,
66 source: WorkLocationSource::Set,
67 }),
68 ..base(MARA_ID, "Mara Lindqvist", "Product Owner", "Product")
69 },
70 JONAS_ID => PersonProfile {
71 manager: Some(priya()),
72 work_phones: Vec::new(),
73 ..base(JONAS_ID, "Jonas Ortega", "Backend Engineer", "Engineering")
74 },
75 PRIYA_ID => PersonProfile {
76 manager: Some(henrik()),
77 direct_reports: vec![
78 person(JONAS_ID, "Jonas Ortega", "Backend Engineer"),
79 person(TOBIAS_ID, "Tobias Klein", "Support Engineer"),
80 person(DEMO_USER_ID, "Dana Demo", "Software Engineer"),
81 person(SOFIA_ID, "Sofia Marin", "QA Engineer"),
82 ],
83 availability: Some(Availability::DoNotDisturb),
84 status_message: Some("In the planning meeting, back at 3".to_owned()),
85 time_zone: Some("Pacific Standard Time".to_owned()),
86 ..base(PRIYA_ID, "Priya Nair", "Engineering Manager", "Engineering")
87 },
88 LEA_ID => PersonProfile {
89 manager: Some(person(OMAR_ID, "Omar Haddad", "Head of Customer Success")),
90 availability: Some(Availability::Offline),
91 out_of_office: Some(OUT_OF_OFFICE.to_owned()),
92 time_zone: Some("GMT Standard Time".to_owned()),
93 mobile_phone: None,
94 ..base(
95 LEA_ID,
96 "Lea Schneider",
97 "Customer Success Manager",
98 "Customer Success",
99 )
100 },
101 TOBIAS_ID => PersonProfile {
102 manager: Some(priya()),
103 availability: Some(Availability::Away),
104 work_location: Some(WorkLocation {
105 kind: WorkLocationKind::Remote,
106 source: WorkLocationSource::Set,
107 }),
108 time_zone: Some("AUS Eastern Standard Time".to_owned()),
109 office_location: None,
110 ..base(
111 TOBIAS_ID,
112 "Tobias Klein",
113 "Support Engineer",
114 "Customer Success",
115 )
116 },
117 DEMO_USER_ID => PersonProfile {
118 manager: Some(priya()),
119 ..base(
120 DEMO_USER_ID,
121 "Dana Demo",
122 "Software Engineer",
123 "Engineering",
124 )
125 },
126 HENRIK_ID => PersonProfile {
127 direct_reports: vec![priya(), person(MARA_ID, "Mara Lindqvist", "Product Owner")],
128 ..base(HENRIK_ID, "Henrik Vogt", "VP Engineering", "Engineering")
129 },
130 SOFIA_ID => PersonProfile {
131 manager: Some(priya()),
132 ..base(SOFIA_ID, "Sofia Marin", "QA Engineer", "Engineering")
133 },
134 OMAR_ID => PersonProfile {
135 direct_reports: vec![person(LEA_ID, "Lea Schneider", "Customer Success Manager")],
136 ..base(
137 OMAR_ID,
138 "Omar Haddad",
139 "Head of Customer Success",
140 "Customer Success",
141 )
142 },
143 _ => return None,
144 })
145}
146
147pub async fn load(user_id: String) -> Result<PersonProfile, String> {
148 tokio::time::sleep(delay()).await;
149 if user_id == TOBIAS_ID && !TOBIAS_FAILED_ONCE.swap(true, Ordering::SeqCst) {
150 return Err("demo failure".to_owned());
151 }
152 profile(&user_id).ok_or_else(|| "unknown demo person".to_owned())
153}
154
155fn delay() -> Duration {
156 std::env::var(DELAY_VARIABLE)
157 .ok()
158 .and_then(|value| value.parse().ok())
159 .map_or(DEFAULT_DELAY, Duration::from_millis)
160}
161
162#[cfg(test)]
163mod tests {
164 use super::*;
165
166 #[test]
167 fn every_demo_person_has_a_profile() {
168 let ids = [MARA_ID, JONAS_ID, PRIYA_ID, LEA_ID, TOBIAS_ID, DEMO_USER_ID];
169 for id in ids {
170 let profile = profile(id).expect("demo profile");
171 assert_eq!(profile.user_id, id);
172 }
173 }
174
175 #[test]
176 fn one_person_is_out_of_office_and_one_has_a_long_message() {
177 assert!(profile(LEA_ID).unwrap().out_of_office.is_some());
178 assert!(profile(MARA_ID).unwrap().status_message.unwrap().len() > 200);
179 }
180}