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 admin: bool,
17    pub invite_code: Option<String>,
18    pub invite_count: i32,
19    pub inviter_id: Option<UserId>,
20    pub connected_once: bool,
21    pub metrics_id: Uuid,
22    pub created_at: NaiveDateTime,
23    pub accepted_tos_at: Option<NaiveDateTime>,
24    pub custom_llm_monthly_allowance_in_cents: Option<i32>,
25}
26
27#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
28pub enum Relation {
29    #[sea_orm(has_many = "super::access_token::Entity")]
30    AccessToken,
31    #[sea_orm(has_one = "super::billing_customer::Entity")]
32    BillingCustomer,
33    #[sea_orm(has_one = "super::room_participant::Entity")]
34    RoomParticipant,
35    #[sea_orm(has_many = "super::project::Entity")]
36    HostedProjects,
37    #[sea_orm(has_many = "super::channel_member::Entity")]
38    ChannelMemberships,
39    #[sea_orm(has_many = "super::user_feature::Entity")]
40    UserFeatures,
41    #[sea_orm(has_one = "super::contributor::Entity")]
42    Contributor,
43}
44
45impl Related<super::access_token::Entity> for Entity {
46    fn to() -> RelationDef {
47        Relation::AccessToken.def()
48    }
49}
50
51impl Related<super::billing_customer::Entity> for Entity {
52    fn to() -> RelationDef {
53        Relation::BillingCustomer.def()
54    }
55}
56
57impl Related<super::room_participant::Entity> for Entity {
58    fn to() -> RelationDef {
59        Relation::RoomParticipant.def()
60    }
61}
62
63impl Related<super::project::Entity> for Entity {
64    fn to() -> RelationDef {
65        Relation::HostedProjects.def()
66    }
67}
68
69impl Related<super::channel_member::Entity> for Entity {
70    fn to() -> RelationDef {
71        Relation::ChannelMemberships.def()
72    }
73}
74
75impl Related<super::user_feature::Entity> for Entity {
76    fn to() -> RelationDef {
77        Relation::UserFeatures.def()
78    }
79}
80
81impl ActiveModelBehavior for ActiveModel {}
82
83pub struct UserFlags;
84
85impl Linked for UserFlags {
86    type FromEntity = Entity;
87
88    type ToEntity = super::feature_flag::Entity;
89
90    fn link(&self) -> Vec<RelationDef> {
91        vec![
92            super::user_feature::Relation::User.def().rev(),
93            super::user_feature::Relation::Flag.def(),
94        ]
95    }
96}