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