]> Untitled Git - lemmy.git/blob - crates/db_schema/src/source/community.rs
Implement restricted community (only mods can post) (fixes #187) (#2235)
[lemmy.git] / crates / db_schema / src / source / community.rs
1 use crate::{
2   newtypes::{CommunityId, DbUrl, PersonId},
3   schema::{community, community_follower, community_moderator, community_person_ban},
4 };
5 use serde::{Deserialize, Serialize};
6
7 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
8 #[table_name = "community"]
9 pub struct Community {
10   pub id: CommunityId,
11   pub name: String,
12   pub title: String,
13   pub description: Option<String>,
14   pub removed: bool,
15   pub published: chrono::NaiveDateTime,
16   pub updated: Option<chrono::NaiveDateTime>,
17   pub deleted: bool,
18   pub nsfw: bool,
19   pub actor_id: DbUrl,
20   pub local: bool,
21   pub private_key: Option<String>,
22   pub public_key: String,
23   pub last_refreshed_at: chrono::NaiveDateTime,
24   pub icon: Option<DbUrl>,
25   pub banner: Option<DbUrl>,
26   pub followers_url: DbUrl,
27   pub inbox_url: DbUrl,
28   pub shared_inbox_url: Option<DbUrl>,
29   pub hidden: bool,
30   pub posting_restricted_to_mods: bool,
31 }
32
33 /// A safe representation of community, without the sensitive info
34 #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
35 #[table_name = "community"]
36 pub struct CommunitySafe {
37   pub id: CommunityId,
38   pub name: String,
39   pub title: String,
40   pub description: Option<String>,
41   pub removed: bool,
42   pub published: chrono::NaiveDateTime,
43   pub updated: Option<chrono::NaiveDateTime>,
44   pub deleted: bool,
45   pub nsfw: bool,
46   pub actor_id: DbUrl,
47   pub local: bool,
48   pub icon: Option<DbUrl>,
49   pub banner: Option<DbUrl>,
50   pub hidden: bool,
51   pub posting_restricted_to_mods: bool,
52 }
53
54 #[derive(Insertable, AsChangeset, Debug, Default)]
55 #[table_name = "community"]
56 pub struct CommunityForm {
57   pub name: String,
58   pub title: String,
59   pub description: Option<String>,
60   pub removed: Option<bool>,
61   pub published: Option<chrono::NaiveDateTime>,
62   pub updated: Option<chrono::NaiveDateTime>,
63   pub deleted: Option<bool>,
64   pub nsfw: Option<bool>,
65   pub actor_id: Option<DbUrl>,
66   pub local: Option<bool>,
67   pub private_key: Option<Option<String>>,
68   pub public_key: String,
69   pub last_refreshed_at: Option<chrono::NaiveDateTime>,
70   pub icon: Option<Option<DbUrl>>,
71   pub banner: Option<Option<DbUrl>>,
72   pub followers_url: Option<DbUrl>,
73   pub inbox_url: Option<DbUrl>,
74   pub shared_inbox_url: Option<Option<DbUrl>>,
75   pub hidden: Option<bool>,
76   pub posting_restricted_to_mods: Option<bool>,
77 }
78
79 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
80 #[belongs_to(Community)]
81 #[table_name = "community_moderator"]
82 pub struct CommunityModerator {
83   pub id: i32,
84   pub community_id: CommunityId,
85   pub person_id: PersonId,
86   pub published: chrono::NaiveDateTime,
87 }
88
89 #[derive(Insertable, AsChangeset, Clone)]
90 #[table_name = "community_moderator"]
91 pub struct CommunityModeratorForm {
92   pub community_id: CommunityId,
93   pub person_id: PersonId,
94 }
95
96 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
97 #[belongs_to(Community)]
98 #[table_name = "community_person_ban"]
99 pub struct CommunityPersonBan {
100   pub id: i32,
101   pub community_id: CommunityId,
102   pub person_id: PersonId,
103   pub published: chrono::NaiveDateTime,
104   pub expires: Option<chrono::NaiveDateTime>,
105 }
106
107 #[derive(Insertable, AsChangeset, Clone)]
108 #[table_name = "community_person_ban"]
109 pub struct CommunityPersonBanForm {
110   pub community_id: CommunityId,
111   pub person_id: PersonId,
112   pub expires: Option<Option<chrono::NaiveDateTime>>,
113 }
114
115 #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)]
116 #[belongs_to(Community)]
117 #[table_name = "community_follower"]
118 pub struct CommunityFollower {
119   pub id: i32,
120   pub community_id: CommunityId,
121   pub person_id: PersonId,
122   pub published: chrono::NaiveDateTime,
123   pub pending: Option<bool>,
124 }
125
126 #[derive(Insertable, AsChangeset, Clone)]
127 #[table_name = "community_follower"]
128 pub struct CommunityFollowerForm {
129   pub community_id: CommunityId,
130   pub person_id: PersonId,
131   pub pending: bool,
132 }