1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
6#[serde(rename_all = "lowercase")]
7pub enum SignIn {
8 Email,
9 Code,
10 Oidc,
11}
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
15#[serde(rename_all = "lowercase")]
16pub enum Role {
17 Admin,
19 Member,
21 Viewer,
23}
24
25impl Role {
26 pub fn as_str(self) -> &'static str {
27 match self {
28 Role::Admin => "admin",
29 Role::Member => "member",
30 Role::Viewer => "viewer",
31 }
32 }
33
34 fn rank(self) -> u8 {
35 match self {
36 Role::Admin => 2,
37 Role::Member => 1,
38 Role::Viewer => 0,
39 }
40 }
41
42 pub fn at_least(self, other: Role) -> bool {
44 self.rank() >= other.rank()
45 }
46}
47
48#[derive(Debug, Clone, Copy, PartialEq, Eq)]
50pub enum Via {
51 Session,
52 AdminToken,
53 Token,
55}
56
57#[derive(Debug, Serialize, Deserialize)]
58pub struct Member {
59 pub email: String,
60 pub role: Role,
61 pub fixed: bool,
62 pub created: String,
63 pub last_seen: Option<String>,
64}
65
66#[derive(Debug, Serialize, Deserialize)]
67pub struct Invite {
68 pub email: String,
69 pub role: Role,
70 pub created_by: String,
71 pub expires: String,
72}
73
74#[derive(Debug, Serialize, Deserialize)]
75pub struct AccessToken {
76 pub id: String,
77 pub name: String,
78 pub created: String,
79 pub last_used: Option<String>,
80 pub expires: Option<String>,
82 pub expired: bool,
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
87pub struct AuditEntry {
88 pub at: String,
89 pub actor: String,
90 pub action: String,
91 pub detail: String,
92}
93
94#[derive(Debug, Default, Serialize, Deserialize)]
96pub struct AuditQuery {
97 pub limit: Option<usize>,
98 pub before: Option<String>,
99 pub actor: Option<String>,
100 pub action: Option<String>,
101}
102
103#[derive(Debug, Serialize, Deserialize)]
104pub struct AuditPage {
105 pub entries: Vec<AuditEntry>,
106 pub next: Option<String>,
108}
109
110#[derive(Debug, Serialize, Deserialize)]
112pub struct SecretInfo {
113 pub name: String,
114 pub source: String,
115 pub hint: Option<String>,
116 pub updated: Option<String>,
117 pub updated_by: Option<String>,
118}
119
120#[derive(Debug, Clone, Serialize, Deserialize)]
122pub struct DeviceRequest {
123 pub client: String,
124 pub expires: String,
125}
126
127#[derive(Debug, Clone, PartialEq, Eq)]
129pub enum DevicePoll {
130 Pending,
131 Approved {
132 token: String,
133 email: String,
134 expires: Option<String>,
135 },
136 Denied,
137 Expired,
138}
139
140pub const TOKEN_DAYS: u32 = 90;