Skip to main content

max / makenotwork

3.8 KB · 133 lines History Blame Raw
1 //! SSH key, OAuth code, issue, and issue comment models.
2
3 use chrono::{DateTime, Utc};
4 use serde::Serialize;
5 use sqlx::FromRow;
6
7 use super::super::enums::CreatorTier;
8 use super::super::id_types::*;
9 use super::super::validated_types::*;
10
11 /// An SSH public key registered by a user for git push access.
12 #[derive(Debug, Clone, FromRow, Serialize)]
13 pub struct DbSshKey {
14 /// Database primary key.
15 pub id: SshKeyId,
16 /// User who owns this key.
17 pub user_id: UserId,
18 /// The SSH public key data (e.g., "ssh-ed25519 AAAA...").
19 pub public_key: String,
20 /// SHA-256 fingerprint (e.g., "SHA256:abc...").
21 pub fingerprint: String,
22 /// Human-readable label for the key (e.g., "laptop").
23 pub label: String,
24 /// When the key was registered.
25 pub created_at: DateTime<Utc>,
26 }
27
28 /// An SSH key joined with its owner's username, for authorized_keys rebuild.
29 #[derive(Debug, Clone, FromRow)]
30 pub struct SshKeyWithUsername {
31 /// SSH key primary key.
32 pub id: SshKeyId,
33 /// The SSH public key data.
34 pub public_key: String,
35 /// Owner's username.
36 pub username: String,
37 }
38
39 /// User info returned by SSH key fingerprint lookup (for CLI auth).
40 #[derive(Debug, Clone, FromRow, Serialize)]
41 pub struct SshKeyUserLookup {
42 pub user_id: UserId,
43 pub username: Username,
44 pub display_name: Option<String>,
45 pub email: Email,
46 pub creator_tier: Option<CreatorTier>,
47 pub can_create_projects: bool,
48 pub suspended: bool,
49 }
50
51 /// An OAuth2 authorization code for PKCE flow.
52 #[derive(Debug, Clone, FromRow)]
53 #[allow(dead_code)] // Fields read via sqlx queries and in route handlers
54 pub struct DbOAuthCode {
55 pub id: OAuthCodeId,
56 pub code: String,
57 pub app_id: SyncAppId,
58 pub user_id: UserId,
59 pub code_challenge: String,
60 pub code_challenge_method: String,
61 pub redirect_uri: String,
62 pub expires_at: DateTime<Utc>,
63 pub used_at: Option<DateTime<Utc>>,
64 pub created_at: DateTime<Utc>,
65 }
66
67 // ── Git Issue models ──
68
69 /// An issue filed against a git repository.
70 #[derive(Debug, Clone, FromRow, Serialize)]
71 pub struct DbIssue {
72 pub id: IssueId,
73 pub repo_id: GitRepoId,
74 pub number: i32,
75 pub author_user_id: UserId,
76 pub title: String,
77 pub body_markdown: String,
78 pub body_html: String,
79 pub status: super::super::IssueStatus,
80 pub created_at: DateTime<Utc>,
81 pub updated_at: DateTime<Utc>,
82 /// Multithreaded forum thread mirroring this issue. Populated by the
83 /// inbound issues handler when MT is configured; `None` otherwise.
84 pub mt_thread_id: Option<uuid::Uuid>,
85 }
86
87 /// An issue with joined metadata for list display.
88 #[derive(Debug, Clone, FromRow)]
89 pub struct DbIssueWithMeta {
90 pub id: IssueId,
91 pub repo_id: GitRepoId,
92 pub number: i32,
93 pub author_user_id: UserId,
94 pub title: String,
95 pub status: super::super::IssueStatus,
96 pub created_at: DateTime<Utc>,
97 pub updated_at: DateTime<Utc>,
98 pub author_username: String,
99 pub comment_count: i64,
100 }
101
102 /// A comment on an issue.
103 #[derive(Debug, Clone, FromRow, Serialize)]
104 pub struct DbIssueComment {
105 pub id: IssueCommentId,
106 pub issue_id: IssueId,
107 pub author_user_id: UserId,
108 pub body_markdown: String,
109 pub body_html: String,
110 pub created_at: DateTime<Utc>,
111 }
112
113 /// A comment with joined author username.
114 #[derive(Debug, Clone, FromRow)]
115 pub struct DbIssueCommentWithAuthor {
116 pub id: IssueCommentId,
117 pub issue_id: IssueId,
118 pub author_user_id: UserId,
119 pub body_markdown: String,
120 pub body_html: String,
121 pub created_at: DateTime<Utc>,
122 pub author_username: String,
123 }
124
125 /// A label that can be attached to issues within a repo.
126 #[derive(Debug, Clone, FromRow, Serialize)]
127 pub struct DbIssueLabel {
128 pub id: IssueLabelId,
129 pub repo_id: GitRepoId,
130 pub name: String,
131 pub color: String,
132 }
133