user.rs

 1use crate::db::UserId;
 2use chrono::NaiveDateTime;
 3use sea_orm::entity::prelude::*;
 4use serde::Serialize;
 5
 6/// A user model.
 7#[derive(Clone, Debug, Default, PartialEq, Eq, DeriveEntityModel, Serialize)]
 8#[sea_orm(table_name = "users")]
 9pub struct Model {
10    #[sea_orm(primary_key)]
11    pub id: UserId,
12    pub github_login: String,
13    pub github_user_id: i32,
14    pub github_user_created_at: Option<NaiveDateTime>,
15    pub email_address: Option<String>,
16    pub name: Option<String>,
17    pub admin: bool,
18    pub invite_code: Option<String>,
19    pub invite_count: i32,
20    pub inviter_id: Option<UserId>,
21    pub connected_once: bool,
22    pub metrics_id: Uuid,
23    pub created_at: NaiveDateTime,
24    pub accepted_tos_at: Option<NaiveDateTime>,
25    pub custom_llm_monthly_allowance_in_cents: Option<i32>,
26}
27
28#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
29pub enum Relation {
30    #[sea_orm(has_many = "super::access_token::Entity")]
31    AccessToken,
32    #[sea_orm(has_one = "super::billing_customer::Entity")]
33    BillingCustomer,
34    #[sea_orm(has_one = "super::room_participant::Entity")]
35    RoomParticipant,
36    #[sea_orm(has_many = "super::project::Entity")]
37    HostedProjects,
38    #[sea_orm(has_many = "super::channel_member::Entity")]
39    ChannelMemberships,
40    #[sea_orm(has_many = "super::user_feature::Entity")]
41    UserFeatures,
42    #[sea_orm(has_one = "super::contributor::Entity")]
43    Contributor,
44}
45
46impl Related<super::access_token::Entity> for Entity {
47    fn to() -> RelationDef {
48        Relation::AccessToken.def()
49    }
50}
51
52impl Related<super::billing_customer::Entity> for Entity {
53    fn to() -> RelationDef {
54        Relation::BillingCustomer.def()
55    }
56}
57
58impl Related<super::room_participant::Entity> for Entity {
59    fn to() -> RelationDef {
60        Relation::RoomParticipant.def()
61    }
62}
63
64impl Related<super::project::Entity> for Entity {
65    fn to() -> RelationDef {
66        Relation::HostedProjects.def()
67    }
68}
69
70impl Related<super::channel_member::Entity> for Entity {
71    fn to() -> RelationDef {
72        Relation::ChannelMemberships.def()
73    }
74}
75
76impl Related<super::user_feature::Entity> for Entity {
77    fn to() -> RelationDef {
78        Relation::UserFeatures.def()
79    }
80}
81
82impl ActiveModelBehavior for ActiveModel {}
83
84pub struct UserFlags;
85
86impl Linked for UserFlags {
87    type FromEntity = Entity;
88
89    type ToEntity = super::feature_flag::Entity;
90
91    fn link(&self) -> Vec<RelationDef> {
92        vec![
93            super::user_feature::Relation::User.def().rev(),
94            super::user_feature::Relation::Flag.def(),
95        ]
96    }
97}