From 1af7b5c82e34b377b30254cecfa230fc50d91566 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Mon, 2 Feb 2026 22:37:24 +0300 Subject: [PATCH] fc-common: add user management models and DTOs Signed-off-by: NotAShelf Change-Id: Ieac472b29092b38be1d6c0af3173e8d26a6a6964 --- crates/common/src/models.rs | 106 ++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/crates/common/src/models.rs b/crates/common/src/models.rs index 690b672..f17cc07 100644 --- a/crates/common/src/models.rs +++ b/crates/common/src/models.rs @@ -156,6 +156,7 @@ pub struct ApiKey { pub name: String, pub key_hash: String, pub role: String, + pub user_id: Option, pub created_at: DateTime, pub last_used_at: Option>, } @@ -223,6 +224,66 @@ pub struct RemoteBuilder { pub created_at: DateTime, } +// --- User Management --- + +/// User account for authentication and personalization +#[derive(Debug, Clone, Serialize, Deserialize, FromRow)] +pub struct User { + pub id: Uuid, + pub username: String, + pub email: String, + pub full_name: Option, + pub password_hash: Option, + pub user_type: UserType, + pub role: String, + pub enabled: bool, + pub email_verified: bool, + pub public_dashboard: bool, + pub created_at: DateTime, + pub updated_at: DateTime, + pub last_login_at: Option>, +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, sqlx::Type)] +#[sqlx(type_name = "text", rename_all = "lowercase")] +pub enum UserType { + Local, + Github, + Google, +} + +/// Starred job for personalized dashboard +#[derive(Debug, Clone, Serialize, Deserialize, FromRow)] +pub struct StarredJob { + pub id: Uuid, + pub user_id: Uuid, + pub project_id: Uuid, + pub jobset_id: Option, + pub job_name: String, + pub created_at: DateTime, +} + +/// Project membership for per-project permissions +#[derive(Debug, Clone, Serialize, Deserialize, FromRow)] +pub struct ProjectMember { + pub id: Uuid, + pub project_id: Uuid, + pub user_id: Uuid, + pub role: String, + pub created_at: DateTime, +} + +/// User session for persistent authentication +#[derive(Debug, Clone, Serialize, Deserialize, FromRow)] +pub struct UserSession { + pub id: Uuid, + pub user_id: Uuid, + pub session_token_hash: String, + pub expires_at: DateTime, + pub created_at: DateTime, + pub last_used_at: Option>, +} + // --- Pagination --- #[derive(Debug, Clone, Serialize, Deserialize)] @@ -399,3 +460,48 @@ pub struct SystemStatus { pub remote_builders: i64, pub channels_count: i64, } + +// --- User DTOs --- + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct CreateUser { + pub username: String, + pub email: String, + pub full_name: Option, + pub password: String, + pub role: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct UpdateUser { + pub email: Option, + pub full_name: Option, + pub password: Option, + pub role: Option, + pub enabled: Option, + pub public_dashboard: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct LoginCredentials { + pub username: String, + pub password: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct CreateStarredJob { + pub project_id: Uuid, + pub jobset_id: Option, + pub job_name: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct CreateProjectMember { + pub user_id: Uuid, + pub role: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct UpdateProjectMember { + pub role: Option, +}