user.rs

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