fc-common: add user management models and DTOs

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ieac472b29092b38be1d6c0af3173e8d26a6a6964
This commit is contained in:
raf 2026-02-02 22:37:24 +03:00
commit 1af7b5c82e
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF

View file

@ -156,6 +156,7 @@ pub struct ApiKey {
pub name: String,
pub key_hash: String,
pub role: String,
pub user_id: Option<Uuid>,
pub created_at: DateTime<Utc>,
pub last_used_at: Option<DateTime<Utc>>,
}
@ -223,6 +224,66 @@ pub struct RemoteBuilder {
pub created_at: DateTime<Utc>,
}
// --- 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<String>,
pub password_hash: Option<String>,
pub user_type: UserType,
pub role: String,
pub enabled: bool,
pub email_verified: bool,
pub public_dashboard: bool,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
pub last_login_at: Option<DateTime<Utc>>,
}
#[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<Uuid>,
pub job_name: String,
pub created_at: DateTime<Utc>,
}
/// 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<Utc>,
}
/// 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<Utc>,
pub created_at: DateTime<Utc>,
pub last_used_at: Option<DateTime<Utc>>,
}
// --- 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<String>,
pub password: String,
pub role: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateUser {
pub email: Option<String>,
pub full_name: Option<String>,
pub password: Option<String>,
pub role: Option<String>,
pub enabled: Option<bool>,
pub public_dashboard: Option<bool>,
}
#[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<Uuid>,
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<String>,
}