]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/local_user.rs
d6c9997131c446ef7486af426e159427d745d6e2
[lemmy.git] / crates / db_schema / src / source / local_user.rs
1 #[cfg(feature = "full")]
2 use crate::schema::local_user;
3 use crate::{
4   newtypes::{LocalUserId, PersonId},
5   ListingType,
6   SortType,
7 };
8 use serde::{Deserialize, Serialize};
9 use serde_with::skip_serializing_none;
10 #[cfg(feature = "full")]
11 use ts_rs::TS;
12 use typed_builder::TypedBuilder;
13
14 #[skip_serializing_none]
15 #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
16 #[cfg_attr(feature = "full", derive(Queryable, Identifiable, TS))]
17 #[cfg_attr(feature = "full", diesel(table_name = local_user))]
18 #[cfg_attr(feature = "full", ts(export))]
19 /// A local user.
20 pub struct LocalUser {
21   pub id: LocalUserId,
22   /// The person_id for the local user.
23   pub person_id: PersonId,
24   #[serde(skip)]
25   pub password_encrypted: String,
26   pub email: Option<String>,
27   /// Whether to show NSFW content.
28   pub show_nsfw: bool,
29   pub theme: String,
30   pub default_sort_type: SortType,
31   pub default_listing_type: ListingType,
32   pub interface_language: String,
33   /// Whether to show avatars.
34   pub show_avatars: bool,
35   pub send_notifications_to_email: bool,
36   /// A validation ID used in logging out sessions.
37   pub validator_time: chrono::NaiveDateTime,
38   /// Whether to show comment / post scores.
39   pub show_scores: bool,
40   /// Whether to show bot accounts.
41   pub show_bot_accounts: bool,
42   /// Whether to show read posts.
43   pub show_read_posts: bool,
44   /// Whether to show new posts as notifications.
45   pub show_new_post_notifs: bool,
46   /// Whether their email has been verified.
47   pub email_verified: bool,
48   /// Whether their registration application has been accepted.
49   pub accepted_application: bool,
50   #[serde(skip)]
51   pub totp_2fa_secret: Option<String>,
52   /// A URL to add their 2-factor auth.
53   pub totp_2fa_url: Option<String>,
54   /// Open links in a new tab.
55   pub open_links_in_new_tab: bool,
56 }
57
58 #[derive(Clone, TypedBuilder)]
59 #[builder(field_defaults(default))]
60 #[cfg_attr(feature = "full", derive(Insertable))]
61 #[cfg_attr(feature = "full", diesel(table_name = local_user))]
62 pub struct LocalUserInsertForm {
63   #[builder(!default)]
64   pub person_id: PersonId,
65   #[builder(!default)]
66   pub password_encrypted: String,
67   pub email: Option<String>,
68   pub show_nsfw: Option<bool>,
69   pub theme: Option<String>,
70   pub default_sort_type: Option<SortType>,
71   pub default_listing_type: Option<ListingType>,
72   pub interface_language: Option<String>,
73   pub show_avatars: Option<bool>,
74   pub send_notifications_to_email: Option<bool>,
75   pub show_bot_accounts: Option<bool>,
76   pub show_scores: Option<bool>,
77   pub show_read_posts: Option<bool>,
78   pub show_new_post_notifs: Option<bool>,
79   pub email_verified: Option<bool>,
80   pub accepted_application: Option<bool>,
81   pub totp_2fa_secret: Option<Option<String>>,
82   pub totp_2fa_url: Option<Option<String>>,
83   pub open_links_in_new_tab: Option<bool>,
84 }
85
86 #[derive(Clone, TypedBuilder)]
87 #[builder(field_defaults(default))]
88 #[cfg_attr(feature = "full", derive(AsChangeset))]
89 #[cfg_attr(feature = "full", diesel(table_name = local_user))]
90 pub struct LocalUserUpdateForm {
91   pub password_encrypted: Option<String>,
92   pub email: Option<Option<String>>,
93   pub show_nsfw: Option<bool>,
94   pub theme: Option<String>,
95   pub default_sort_type: Option<SortType>,
96   pub default_listing_type: Option<ListingType>,
97   pub interface_language: Option<String>,
98   pub show_avatars: Option<bool>,
99   pub send_notifications_to_email: Option<bool>,
100   pub show_bot_accounts: Option<bool>,
101   pub show_scores: Option<bool>,
102   pub show_read_posts: Option<bool>,
103   pub show_new_post_notifs: Option<bool>,
104   pub email_verified: Option<bool>,
105   pub accepted_application: Option<bool>,
106   pub totp_2fa_secret: Option<Option<String>>,
107   pub totp_2fa_url: Option<Option<String>>,
108   pub open_links_in_new_tab: Option<bool>,
109 }