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