]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/local_site.rs
976516c5ff91ff03f88e922f7c90f3c5f2eb9eb6
[lemmy.git] / crates / db_schema / src / source / local_site.rs
1 use crate::newtypes::{LocalSiteId, SiteId};
2 #[cfg(feature = "full")]
3 use crate::schema::local_site;
4 use serde::{Deserialize, Serialize};
5 use typed_builder::TypedBuilder;
6
7 #[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]
8 #[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
9 #[cfg_attr(feature = "full", diesel(table_name = local_site))]
10 #[cfg_attr(feature = "full", diesel(belongs_to(crate::source::site::Site)))]
11 pub struct LocalSite {
12   pub id: LocalSiteId,
13   pub site_id: SiteId,
14   pub site_setup: bool,
15   pub enable_downvotes: bool,
16   pub enable_nsfw: bool,
17   pub community_creation_admin_only: bool,
18   pub require_email_verification: bool,
19   pub application_question: Option<String>,
20   pub private_instance: bool,
21   pub default_theme: String,
22   pub default_post_listing_type: String,
23   pub legal_information: Option<String>,
24   pub hide_modlog_mod_names: bool,
25   pub application_email_admins: bool,
26   pub slur_filter_regex: Option<String>,
27   pub actor_name_max_length: i32,
28   pub federation_enabled: bool,
29   pub federation_debug: bool,
30   pub federation_worker_count: i32,
31   pub captcha_enabled: bool,
32   pub captcha_difficulty: String,
33   pub registration_mode: RegistrationMode,
34   pub reports_email_admins: bool,
35   pub published: chrono::NaiveDateTime,
36   pub updated: Option<chrono::NaiveDateTime>,
37 }
38
39 #[derive(Clone, TypedBuilder)]
40 #[builder(field_defaults(default))]
41 #[cfg_attr(feature = "full", derive(Insertable))]
42 #[cfg_attr(feature = "full", diesel(table_name = local_site))]
43 pub struct LocalSiteInsertForm {
44   #[builder(!default)]
45   pub site_id: SiteId,
46   pub site_setup: Option<bool>,
47   pub enable_downvotes: Option<bool>,
48   pub enable_nsfw: Option<bool>,
49   pub community_creation_admin_only: Option<bool>,
50   pub require_email_verification: Option<bool>,
51   pub application_question: Option<String>,
52   pub private_instance: Option<bool>,
53   pub default_theme: Option<String>,
54   pub default_post_listing_type: Option<String>,
55   pub legal_information: Option<String>,
56   pub hide_modlog_mod_names: Option<bool>,
57   pub application_email_admins: Option<bool>,
58   pub slur_filter_regex: Option<String>,
59   pub actor_name_max_length: Option<i32>,
60   pub federation_enabled: Option<bool>,
61   pub federation_debug: Option<bool>,
62   pub federation_worker_count: Option<i32>,
63   pub captcha_enabled: Option<bool>,
64   pub captcha_difficulty: Option<String>,
65   pub registration_mode: Option<RegistrationMode>,
66   pub reports_email_admins: Option<bool>,
67 }
68
69 #[derive(Clone, TypedBuilder)]
70 #[builder(field_defaults(default))]
71 #[cfg_attr(feature = "full", derive(AsChangeset))]
72 #[cfg_attr(feature = "full", diesel(table_name = local_site))]
73 pub struct LocalSiteUpdateForm {
74   pub site_setup: Option<bool>,
75   pub enable_downvotes: Option<bool>,
76   pub enable_nsfw: Option<bool>,
77   pub community_creation_admin_only: Option<bool>,
78   pub require_email_verification: Option<bool>,
79   pub application_question: Option<Option<String>>,
80   pub private_instance: Option<bool>,
81   pub default_theme: Option<String>,
82   pub default_post_listing_type: Option<String>,
83   pub legal_information: Option<Option<String>>,
84   pub hide_modlog_mod_names: Option<bool>,
85   pub application_email_admins: Option<bool>,
86   pub slur_filter_regex: Option<Option<String>>,
87   pub actor_name_max_length: Option<i32>,
88   pub federation_enabled: Option<bool>,
89   pub federation_debug: Option<bool>,
90   pub federation_worker_count: Option<i32>,
91   pub captcha_enabled: Option<bool>,
92   pub captcha_difficulty: Option<String>,
93   pub registration_mode: Option<RegistrationMode>,
94   pub reports_email_admins: Option<bool>,
95   pub updated: Option<Option<chrono::NaiveDateTime>>,
96 }
97
98 #[cfg(feature = "full")]
99 #[derive(SqlType)]
100 #[diesel(postgres_type(name = "registration_mode_enum"))]
101 pub struct RegistrationModeType;
102
103 #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
104 #[cfg_attr(feature = "full", derive(FromSqlRow, AsExpression))]
105 #[cfg_attr(feature = "full", diesel(sql_type = RegistrationModeType))]
106 #[serde(rename_all = "lowercase")]
107 pub enum RegistrationMode {
108   Closed,
109   RequireApplication,
110   Open,
111 }