mas_handlers/graphql/model/
mod.rs1use async_graphql::{Enum, Interface, Object, SimpleObject};
8use chrono::{DateTime, Utc};
9
10mod browser_sessions;
11mod compat_sessions;
12mod cursor;
13mod matrix;
14mod node;
15mod oauth;
16mod site_config;
17mod upstream_oauth;
18mod users;
19mod viewer;
20
21pub use self::{
22 browser_sessions::{Authentication, BrowserSession},
23 compat_sessions::{CompatSession, CompatSsoLogin},
24 cursor::{Cursor, NodeCursor},
25 node::{Node, NodeType},
26 oauth::{OAuth2Client, OAuth2Session},
27 site_config::{SITE_CONFIG_ID, SiteConfig},
28 upstream_oauth::{UpstreamOAuth2Link, UpstreamOAuth2Provider},
29 users::{AppSession, User, UserEmail, UserEmailAuthentication, UserRecoveryTicket},
30 viewer::{Anonymous, Viewer, ViewerSession},
31};
32
33#[derive(Interface)]
35#[graphql(field(
36 name = "created_at",
37 desc = "When the object was created.",
38 ty = "DateTime<Utc>"
39))]
40pub enum CreationEvent {
41 Authentication(Box<Authentication>),
42 CompatSession(Box<CompatSession>),
43 BrowserSession(Box<BrowserSession>),
44 UserEmail(Box<UserEmail>),
45 UserEmailAuthentication(Box<UserEmailAuthentication>),
46 UserRecoveryTicket(Box<UserRecoveryTicket>),
47 UpstreamOAuth2Provider(Box<UpstreamOAuth2Provider>),
48 UpstreamOAuth2Link(Box<UpstreamOAuth2Link>),
49 OAuth2Session(Box<OAuth2Session>),
50}
51
52pub struct PreloadedTotalCount(pub Option<usize>);
53
54#[Object]
55impl PreloadedTotalCount {
56 async fn total_count(&self) -> Result<usize, async_graphql::Error> {
58 self.0
59 .ok_or_else(|| async_graphql::Error::new("total count not preloaded"))
60 }
61}
62
63#[derive(Enum, Copy, Clone, Eq, PartialEq)]
65pub enum SessionState {
66 Active,
68
69 Finished,
71}
72
73#[derive(Enum, Copy, Clone, Eq, PartialEq)]
75pub enum DeviceType {
76 Pc,
78
79 Mobile,
81
82 Tablet,
84
85 Unknown,
87}
88
89impl From<mas_data_model::DeviceType> for DeviceType {
90 fn from(device_type: mas_data_model::DeviceType) -> Self {
91 match device_type {
92 mas_data_model::DeviceType::Pc => Self::Pc,
93 mas_data_model::DeviceType::Mobile => Self::Mobile,
94 mas_data_model::DeviceType::Tablet => Self::Tablet,
95 mas_data_model::DeviceType::Unknown => Self::Unknown,
96 }
97 }
98}
99
100#[derive(SimpleObject)]
102pub struct UserAgent {
103 pub raw: String,
105
106 pub name: Option<String>,
108
109 pub version: Option<String>,
111
112 pub os: Option<String>,
114
115 pub os_version: Option<String>,
117
118 pub model: Option<String>,
120
121 pub device_type: DeviceType,
123}
124
125impl From<mas_data_model::UserAgent> for UserAgent {
126 fn from(ua: mas_data_model::UserAgent) -> Self {
127 Self {
128 raw: ua.raw,
129 name: ua.name,
130 version: ua.version,
131 os: ua.os,
132 os_version: ua.os_version,
133 model: ua.model,
134 device_type: ua.device_type.into(),
135 }
136 }
137}