]> Untitled Git - lemmy.git/blob - server/lemmy_db/src/moderator.rs
Translated using Weblate (Italian)
[lemmy.git] / server / lemmy_db / src / moderator.rs
1 use crate::{
2   schema::{
3     mod_add,
4     mod_add_community,
5     mod_ban,
6     mod_ban_from_community,
7     mod_lock_post,
8     mod_remove_comment,
9     mod_remove_community,
10     mod_remove_post,
11     mod_sticky_post,
12   },
13   Crud,
14 };
15 use diesel::{dsl::*, result::Error, *};
16 use serde::{Deserialize, Serialize};
17
18 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
19 #[table_name = "mod_remove_post"]
20 pub struct ModRemovePost {
21   pub id: i32,
22   pub mod_user_id: i32,
23   pub post_id: i32,
24   pub reason: Option<String>,
25   pub removed: Option<bool>,
26   pub when_: chrono::NaiveDateTime,
27 }
28
29 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
30 #[table_name = "mod_remove_post"]
31 pub struct ModRemovePostForm {
32   pub mod_user_id: i32,
33   pub post_id: i32,
34   pub reason: Option<String>,
35   pub removed: Option<bool>,
36 }
37
38 impl Crud<ModRemovePostForm> for ModRemovePost {
39   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
40     use crate::schema::mod_remove_post::dsl::*;
41     mod_remove_post.find(from_id).first::<Self>(conn)
42   }
43
44   fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
45     use crate::schema::mod_remove_post::dsl::*;
46     diesel::delete(mod_remove_post.find(from_id)).execute(conn)
47   }
48
49   fn create(conn: &PgConnection, form: &ModRemovePostForm) -> Result<Self, Error> {
50     use crate::schema::mod_remove_post::dsl::*;
51     insert_into(mod_remove_post)
52       .values(form)
53       .get_result::<Self>(conn)
54   }
55
56   fn update(conn: &PgConnection, from_id: i32, form: &ModRemovePostForm) -> Result<Self, Error> {
57     use crate::schema::mod_remove_post::dsl::*;
58     diesel::update(mod_remove_post.find(from_id))
59       .set(form)
60       .get_result::<Self>(conn)
61   }
62 }
63
64 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
65 #[table_name = "mod_lock_post"]
66 pub struct ModLockPost {
67   pub id: i32,
68   pub mod_user_id: i32,
69   pub post_id: i32,
70   pub locked: Option<bool>,
71   pub when_: chrono::NaiveDateTime,
72 }
73
74 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
75 #[table_name = "mod_lock_post"]
76 pub struct ModLockPostForm {
77   pub mod_user_id: i32,
78   pub post_id: i32,
79   pub locked: Option<bool>,
80 }
81
82 impl Crud<ModLockPostForm> for ModLockPost {
83   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
84     use crate::schema::mod_lock_post::dsl::*;
85     mod_lock_post.find(from_id).first::<Self>(conn)
86   }
87
88   fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
89     use crate::schema::mod_lock_post::dsl::*;
90     diesel::delete(mod_lock_post.find(from_id)).execute(conn)
91   }
92
93   fn create(conn: &PgConnection, form: &ModLockPostForm) -> Result<Self, Error> {
94     use crate::schema::mod_lock_post::dsl::*;
95     insert_into(mod_lock_post)
96       .values(form)
97       .get_result::<Self>(conn)
98   }
99
100   fn update(conn: &PgConnection, from_id: i32, form: &ModLockPostForm) -> Result<Self, Error> {
101     use crate::schema::mod_lock_post::dsl::*;
102     diesel::update(mod_lock_post.find(from_id))
103       .set(form)
104       .get_result::<Self>(conn)
105   }
106 }
107
108 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
109 #[table_name = "mod_sticky_post"]
110 pub struct ModStickyPost {
111   pub id: i32,
112   pub mod_user_id: i32,
113   pub post_id: i32,
114   pub stickied: Option<bool>,
115   pub when_: chrono::NaiveDateTime,
116 }
117
118 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
119 #[table_name = "mod_sticky_post"]
120 pub struct ModStickyPostForm {
121   pub mod_user_id: i32,
122   pub post_id: i32,
123   pub stickied: Option<bool>,
124 }
125
126 impl Crud<ModStickyPostForm> for ModStickyPost {
127   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
128     use crate::schema::mod_sticky_post::dsl::*;
129     mod_sticky_post.find(from_id).first::<Self>(conn)
130   }
131
132   fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
133     use crate::schema::mod_sticky_post::dsl::*;
134     diesel::delete(mod_sticky_post.find(from_id)).execute(conn)
135   }
136
137   fn create(conn: &PgConnection, form: &ModStickyPostForm) -> Result<Self, Error> {
138     use crate::schema::mod_sticky_post::dsl::*;
139     insert_into(mod_sticky_post)
140       .values(form)
141       .get_result::<Self>(conn)
142   }
143
144   fn update(conn: &PgConnection, from_id: i32, form: &ModStickyPostForm) -> Result<Self, Error> {
145     use crate::schema::mod_sticky_post::dsl::*;
146     diesel::update(mod_sticky_post.find(from_id))
147       .set(form)
148       .get_result::<Self>(conn)
149   }
150 }
151
152 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
153 #[table_name = "mod_remove_comment"]
154 pub struct ModRemoveComment {
155   pub id: i32,
156   pub mod_user_id: i32,
157   pub comment_id: i32,
158   pub reason: Option<String>,
159   pub removed: Option<bool>,
160   pub when_: chrono::NaiveDateTime,
161 }
162
163 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
164 #[table_name = "mod_remove_comment"]
165 pub struct ModRemoveCommentForm {
166   pub mod_user_id: i32,
167   pub comment_id: i32,
168   pub reason: Option<String>,
169   pub removed: Option<bool>,
170 }
171
172 impl Crud<ModRemoveCommentForm> for ModRemoveComment {
173   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
174     use crate::schema::mod_remove_comment::dsl::*;
175     mod_remove_comment.find(from_id).first::<Self>(conn)
176   }
177
178   fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
179     use crate::schema::mod_remove_comment::dsl::*;
180     diesel::delete(mod_remove_comment.find(from_id)).execute(conn)
181   }
182
183   fn create(conn: &PgConnection, form: &ModRemoveCommentForm) -> Result<Self, Error> {
184     use crate::schema::mod_remove_comment::dsl::*;
185     insert_into(mod_remove_comment)
186       .values(form)
187       .get_result::<Self>(conn)
188   }
189
190   fn update(conn: &PgConnection, from_id: i32, form: &ModRemoveCommentForm) -> Result<Self, Error> {
191     use crate::schema::mod_remove_comment::dsl::*;
192     diesel::update(mod_remove_comment.find(from_id))
193       .set(form)
194       .get_result::<Self>(conn)
195   }
196 }
197
198 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
199 #[table_name = "mod_remove_community"]
200 pub struct ModRemoveCommunity {
201   pub id: i32,
202   pub mod_user_id: i32,
203   pub community_id: i32,
204   pub reason: Option<String>,
205   pub removed: Option<bool>,
206   pub expires: Option<chrono::NaiveDateTime>,
207   pub when_: chrono::NaiveDateTime,
208 }
209
210 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
211 #[table_name = "mod_remove_community"]
212 pub struct ModRemoveCommunityForm {
213   pub mod_user_id: i32,
214   pub community_id: i32,
215   pub reason: Option<String>,
216   pub removed: Option<bool>,
217   pub expires: Option<chrono::NaiveDateTime>,
218 }
219
220 impl Crud<ModRemoveCommunityForm> for ModRemoveCommunity {
221   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
222     use crate::schema::mod_remove_community::dsl::*;
223     mod_remove_community.find(from_id).first::<Self>(conn)
224   }
225
226   fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
227     use crate::schema::mod_remove_community::dsl::*;
228     diesel::delete(mod_remove_community.find(from_id)).execute(conn)
229   }
230
231   fn create(conn: &PgConnection, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
232     use crate::schema::mod_remove_community::dsl::*;
233     insert_into(mod_remove_community)
234       .values(form)
235       .get_result::<Self>(conn)
236   }
237
238   fn update(
239     conn: &PgConnection,
240     from_id: i32,
241     form: &ModRemoveCommunityForm,
242   ) -> Result<Self, Error> {
243     use crate::schema::mod_remove_community::dsl::*;
244     diesel::update(mod_remove_community.find(from_id))
245       .set(form)
246       .get_result::<Self>(conn)
247   }
248 }
249
250 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
251 #[table_name = "mod_ban_from_community"]
252 pub struct ModBanFromCommunity {
253   pub id: i32,
254   pub mod_user_id: i32,
255   pub other_user_id: i32,
256   pub community_id: i32,
257   pub reason: Option<String>,
258   pub banned: Option<bool>,
259   pub expires: Option<chrono::NaiveDateTime>,
260   pub when_: chrono::NaiveDateTime,
261 }
262
263 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
264 #[table_name = "mod_ban_from_community"]
265 pub struct ModBanFromCommunityForm {
266   pub mod_user_id: i32,
267   pub other_user_id: i32,
268   pub community_id: i32,
269   pub reason: Option<String>,
270   pub banned: Option<bool>,
271   pub expires: Option<chrono::NaiveDateTime>,
272 }
273
274 impl Crud<ModBanFromCommunityForm> for ModBanFromCommunity {
275   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
276     use crate::schema::mod_ban_from_community::dsl::*;
277     mod_ban_from_community.find(from_id).first::<Self>(conn)
278   }
279
280   fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
281     use crate::schema::mod_ban_from_community::dsl::*;
282     diesel::delete(mod_ban_from_community.find(from_id)).execute(conn)
283   }
284
285   fn create(conn: &PgConnection, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
286     use crate::schema::mod_ban_from_community::dsl::*;
287     insert_into(mod_ban_from_community)
288       .values(form)
289       .get_result::<Self>(conn)
290   }
291
292   fn update(
293     conn: &PgConnection,
294     from_id: i32,
295     form: &ModBanFromCommunityForm,
296   ) -> Result<Self, Error> {
297     use crate::schema::mod_ban_from_community::dsl::*;
298     diesel::update(mod_ban_from_community.find(from_id))
299       .set(form)
300       .get_result::<Self>(conn)
301   }
302 }
303
304 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
305 #[table_name = "mod_ban"]
306 pub struct ModBan {
307   pub id: i32,
308   pub mod_user_id: i32,
309   pub other_user_id: i32,
310   pub reason: Option<String>,
311   pub banned: Option<bool>,
312   pub expires: Option<chrono::NaiveDateTime>,
313   pub when_: chrono::NaiveDateTime,
314 }
315
316 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
317 #[table_name = "mod_ban"]
318 pub struct ModBanForm {
319   pub mod_user_id: i32,
320   pub other_user_id: i32,
321   pub reason: Option<String>,
322   pub banned: Option<bool>,
323   pub expires: Option<chrono::NaiveDateTime>,
324 }
325
326 impl Crud<ModBanForm> for ModBan {
327   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
328     use crate::schema::mod_ban::dsl::*;
329     mod_ban.find(from_id).first::<Self>(conn)
330   }
331
332   fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
333     use crate::schema::mod_ban::dsl::*;
334     diesel::delete(mod_ban.find(from_id)).execute(conn)
335   }
336
337   fn create(conn: &PgConnection, form: &ModBanForm) -> Result<Self, Error> {
338     use crate::schema::mod_ban::dsl::*;
339     insert_into(mod_ban).values(form).get_result::<Self>(conn)
340   }
341
342   fn update(conn: &PgConnection, from_id: i32, form: &ModBanForm) -> Result<Self, Error> {
343     use crate::schema::mod_ban::dsl::*;
344     diesel::update(mod_ban.find(from_id))
345       .set(form)
346       .get_result::<Self>(conn)
347   }
348 }
349
350 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
351 #[table_name = "mod_add_community"]
352 pub struct ModAddCommunity {
353   pub id: i32,
354   pub mod_user_id: i32,
355   pub other_user_id: i32,
356   pub community_id: i32,
357   pub removed: Option<bool>,
358   pub when_: chrono::NaiveDateTime,
359 }
360
361 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
362 #[table_name = "mod_add_community"]
363 pub struct ModAddCommunityForm {
364   pub mod_user_id: i32,
365   pub other_user_id: i32,
366   pub community_id: i32,
367   pub removed: Option<bool>,
368 }
369
370 impl Crud<ModAddCommunityForm> for ModAddCommunity {
371   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
372     use crate::schema::mod_add_community::dsl::*;
373     mod_add_community.find(from_id).first::<Self>(conn)
374   }
375
376   fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
377     use crate::schema::mod_add_community::dsl::*;
378     diesel::delete(mod_add_community.find(from_id)).execute(conn)
379   }
380
381   fn create(conn: &PgConnection, form: &ModAddCommunityForm) -> Result<Self, Error> {
382     use crate::schema::mod_add_community::dsl::*;
383     insert_into(mod_add_community)
384       .values(form)
385       .get_result::<Self>(conn)
386   }
387
388   fn update(conn: &PgConnection, from_id: i32, form: &ModAddCommunityForm) -> Result<Self, Error> {
389     use crate::schema::mod_add_community::dsl::*;
390     diesel::update(mod_add_community.find(from_id))
391       .set(form)
392       .get_result::<Self>(conn)
393   }
394 }
395
396 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
397 #[table_name = "mod_add"]
398 pub struct ModAdd {
399   pub id: i32,
400   pub mod_user_id: i32,
401   pub other_user_id: i32,
402   pub removed: Option<bool>,
403   pub when_: chrono::NaiveDateTime,
404 }
405
406 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
407 #[table_name = "mod_add"]
408 pub struct ModAddForm {
409   pub mod_user_id: i32,
410   pub other_user_id: i32,
411   pub removed: Option<bool>,
412 }
413
414 impl Crud<ModAddForm> for ModAdd {
415   fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
416     use crate::schema::mod_add::dsl::*;
417     mod_add.find(from_id).first::<Self>(conn)
418   }
419
420   fn delete(conn: &PgConnection, from_id: i32) -> Result<usize, Error> {
421     use crate::schema::mod_add::dsl::*;
422     diesel::delete(mod_add.find(from_id)).execute(conn)
423   }
424
425   fn create(conn: &PgConnection, form: &ModAddForm) -> Result<Self, Error> {
426     use crate::schema::mod_add::dsl::*;
427     insert_into(mod_add).values(form).get_result::<Self>(conn)
428   }
429
430   fn update(conn: &PgConnection, from_id: i32, form: &ModAddForm) -> Result<Self, Error> {
431     use crate::schema::mod_add::dsl::*;
432     diesel::update(mod_add.find(from_id))
433       .set(form)
434       .get_result::<Self>(conn)
435   }
436 }
437
438 #[cfg(test)]
439 mod tests {
440   use crate::{
441     comment::*,
442     community::*,
443     moderator::*,
444     post::*,
445     tests::establish_unpooled_connection,
446     user::*,
447     ListingType,
448     SortType,
449   };
450
451   // use Crud;
452   #[test]
453   fn test_crud() {
454     let conn = establish_unpooled_connection();
455
456     let new_mod = UserForm {
457       name: "the mod".into(),
458       preferred_username: None,
459       password_encrypted: "nope".into(),
460       email: None,
461       matrix_user_id: None,
462       avatar: None,
463       admin: false,
464       banned: false,
465       updated: None,
466       show_nsfw: false,
467       theme: "darkly".into(),
468       default_sort_type: SortType::Hot as i16,
469       default_listing_type: ListingType::Subscribed as i16,
470       lang: "browser".into(),
471       show_avatars: true,
472       send_notifications_to_email: false,
473       actor_id: "changeme_829398".into(),
474       bio: None,
475       local: true,
476       private_key: None,
477       public_key: None,
478       last_refreshed_at: None,
479     };
480
481     let inserted_mod = User_::create(&conn, &new_mod).unwrap();
482
483     let new_user = UserForm {
484       name: "jim2".into(),
485       preferred_username: None,
486       password_encrypted: "nope".into(),
487       email: None,
488       matrix_user_id: None,
489       avatar: None,
490       admin: false,
491       banned: false,
492       updated: None,
493       show_nsfw: false,
494       theme: "darkly".into(),
495       default_sort_type: SortType::Hot as i16,
496       default_listing_type: ListingType::Subscribed as i16,
497       lang: "browser".into(),
498       show_avatars: true,
499       send_notifications_to_email: false,
500       actor_id: "changeme_82982738".into(),
501       bio: None,
502       local: true,
503       private_key: None,
504       public_key: None,
505       last_refreshed_at: None,
506     };
507
508     let inserted_user = User_::create(&conn, &new_user).unwrap();
509
510     let new_community = CommunityForm {
511       name: "mod_community".to_string(),
512       title: "nada".to_owned(),
513       description: None,
514       category_id: 1,
515       creator_id: inserted_user.id,
516       removed: None,
517       deleted: None,
518       updated: None,
519       nsfw: false,
520       actor_id: "changeme_283687".into(),
521       local: true,
522       private_key: None,
523       public_key: None,
524       last_refreshed_at: None,
525       published: None,
526     };
527
528     let inserted_community = Community::create(&conn, &new_community).unwrap();
529
530     let new_post = PostForm {
531       name: "A test post thweep".into(),
532       url: None,
533       body: None,
534       creator_id: inserted_user.id,
535       community_id: inserted_community.id,
536       removed: None,
537       deleted: None,
538       locked: None,
539       stickied: None,
540       updated: None,
541       nsfw: false,
542       embed_title: None,
543       embed_description: None,
544       embed_html: None,
545       thumbnail_url: None,
546       ap_id: "http://fake.com".into(),
547       local: true,
548       published: None,
549     };
550
551     let inserted_post = Post::create(&conn, &new_post).unwrap();
552
553     let comment_form = CommentForm {
554       content: "A test comment".into(),
555       creator_id: inserted_user.id,
556       post_id: inserted_post.id,
557       removed: None,
558       deleted: None,
559       read: None,
560       parent_id: None,
561       published: None,
562       updated: None,
563       ap_id: "http://fake.com".into(),
564       local: true,
565     };
566
567     let inserted_comment = Comment::create(&conn, &comment_form).unwrap();
568
569     // Now the actual tests
570
571     // remove post
572     let mod_remove_post_form = ModRemovePostForm {
573       mod_user_id: inserted_mod.id,
574       post_id: inserted_post.id,
575       reason: None,
576       removed: None,
577     };
578     let inserted_mod_remove_post = ModRemovePost::create(&conn, &mod_remove_post_form).unwrap();
579     let read_mod_remove_post = ModRemovePost::read(&conn, inserted_mod_remove_post.id).unwrap();
580     let expected_mod_remove_post = ModRemovePost {
581       id: inserted_mod_remove_post.id,
582       post_id: inserted_post.id,
583       mod_user_id: inserted_mod.id,
584       reason: None,
585       removed: Some(true),
586       when_: inserted_mod_remove_post.when_,
587     };
588
589     // lock post
590
591     let mod_lock_post_form = ModLockPostForm {
592       mod_user_id: inserted_mod.id,
593       post_id: inserted_post.id,
594       locked: None,
595     };
596     let inserted_mod_lock_post = ModLockPost::create(&conn, &mod_lock_post_form).unwrap();
597     let read_mod_lock_post = ModLockPost::read(&conn, inserted_mod_lock_post.id).unwrap();
598     let expected_mod_lock_post = ModLockPost {
599       id: inserted_mod_lock_post.id,
600       post_id: inserted_post.id,
601       mod_user_id: inserted_mod.id,
602       locked: Some(true),
603       when_: inserted_mod_lock_post.when_,
604     };
605
606     // sticky post
607
608     let mod_sticky_post_form = ModStickyPostForm {
609       mod_user_id: inserted_mod.id,
610       post_id: inserted_post.id,
611       stickied: None,
612     };
613     let inserted_mod_sticky_post = ModStickyPost::create(&conn, &mod_sticky_post_form).unwrap();
614     let read_mod_sticky_post = ModStickyPost::read(&conn, inserted_mod_sticky_post.id).unwrap();
615     let expected_mod_sticky_post = ModStickyPost {
616       id: inserted_mod_sticky_post.id,
617       post_id: inserted_post.id,
618       mod_user_id: inserted_mod.id,
619       stickied: Some(true),
620       when_: inserted_mod_sticky_post.when_,
621     };
622
623     // comment
624
625     let mod_remove_comment_form = ModRemoveCommentForm {
626       mod_user_id: inserted_mod.id,
627       comment_id: inserted_comment.id,
628       reason: None,
629       removed: None,
630     };
631     let inserted_mod_remove_comment =
632       ModRemoveComment::create(&conn, &mod_remove_comment_form).unwrap();
633     let read_mod_remove_comment =
634       ModRemoveComment::read(&conn, inserted_mod_remove_comment.id).unwrap();
635     let expected_mod_remove_comment = ModRemoveComment {
636       id: inserted_mod_remove_comment.id,
637       comment_id: inserted_comment.id,
638       mod_user_id: inserted_mod.id,
639       reason: None,
640       removed: Some(true),
641       when_: inserted_mod_remove_comment.when_,
642     };
643
644     // community
645
646     let mod_remove_community_form = ModRemoveCommunityForm {
647       mod_user_id: inserted_mod.id,
648       community_id: inserted_community.id,
649       reason: None,
650       removed: None,
651       expires: None,
652     };
653     let inserted_mod_remove_community =
654       ModRemoveCommunity::create(&conn, &mod_remove_community_form).unwrap();
655     let read_mod_remove_community =
656       ModRemoveCommunity::read(&conn, inserted_mod_remove_community.id).unwrap();
657     let expected_mod_remove_community = ModRemoveCommunity {
658       id: inserted_mod_remove_community.id,
659       community_id: inserted_community.id,
660       mod_user_id: inserted_mod.id,
661       reason: None,
662       removed: Some(true),
663       expires: None,
664       when_: inserted_mod_remove_community.when_,
665     };
666
667     // ban from community
668
669     let mod_ban_from_community_form = ModBanFromCommunityForm {
670       mod_user_id: inserted_mod.id,
671       other_user_id: inserted_user.id,
672       community_id: inserted_community.id,
673       reason: None,
674       banned: None,
675       expires: None,
676     };
677     let inserted_mod_ban_from_community =
678       ModBanFromCommunity::create(&conn, &mod_ban_from_community_form).unwrap();
679     let read_mod_ban_from_community =
680       ModBanFromCommunity::read(&conn, inserted_mod_ban_from_community.id).unwrap();
681     let expected_mod_ban_from_community = ModBanFromCommunity {
682       id: inserted_mod_ban_from_community.id,
683       community_id: inserted_community.id,
684       mod_user_id: inserted_mod.id,
685       other_user_id: inserted_user.id,
686       reason: None,
687       banned: Some(true),
688       expires: None,
689       when_: inserted_mod_ban_from_community.when_,
690     };
691
692     // ban
693
694     let mod_ban_form = ModBanForm {
695       mod_user_id: inserted_mod.id,
696       other_user_id: inserted_user.id,
697       reason: None,
698       banned: None,
699       expires: None,
700     };
701     let inserted_mod_ban = ModBan::create(&conn, &mod_ban_form).unwrap();
702     let read_mod_ban = ModBan::read(&conn, inserted_mod_ban.id).unwrap();
703     let expected_mod_ban = ModBan {
704       id: inserted_mod_ban.id,
705       mod_user_id: inserted_mod.id,
706       other_user_id: inserted_user.id,
707       reason: None,
708       banned: Some(true),
709       expires: None,
710       when_: inserted_mod_ban.when_,
711     };
712
713     // mod add community
714
715     let mod_add_community_form = ModAddCommunityForm {
716       mod_user_id: inserted_mod.id,
717       other_user_id: inserted_user.id,
718       community_id: inserted_community.id,
719       removed: None,
720     };
721     let inserted_mod_add_community =
722       ModAddCommunity::create(&conn, &mod_add_community_form).unwrap();
723     let read_mod_add_community =
724       ModAddCommunity::read(&conn, inserted_mod_add_community.id).unwrap();
725     let expected_mod_add_community = ModAddCommunity {
726       id: inserted_mod_add_community.id,
727       community_id: inserted_community.id,
728       mod_user_id: inserted_mod.id,
729       other_user_id: inserted_user.id,
730       removed: Some(false),
731       when_: inserted_mod_add_community.when_,
732     };
733
734     // mod add
735
736     let mod_add_form = ModAddForm {
737       mod_user_id: inserted_mod.id,
738       other_user_id: inserted_user.id,
739       removed: None,
740     };
741     let inserted_mod_add = ModAdd::create(&conn, &mod_add_form).unwrap();
742     let read_mod_add = ModAdd::read(&conn, inserted_mod_add.id).unwrap();
743     let expected_mod_add = ModAdd {
744       id: inserted_mod_add.id,
745       mod_user_id: inserted_mod.id,
746       other_user_id: inserted_user.id,
747       removed: Some(false),
748       when_: inserted_mod_add.when_,
749     };
750
751     ModRemovePost::delete(&conn, inserted_mod_remove_post.id).unwrap();
752     ModLockPost::delete(&conn, inserted_mod_lock_post.id).unwrap();
753     ModStickyPost::delete(&conn, inserted_mod_sticky_post.id).unwrap();
754     ModRemoveComment::delete(&conn, inserted_mod_remove_comment.id).unwrap();
755     ModRemoveCommunity::delete(&conn, inserted_mod_remove_community.id).unwrap();
756     ModBanFromCommunity::delete(&conn, inserted_mod_ban_from_community.id).unwrap();
757     ModBan::delete(&conn, inserted_mod_ban.id).unwrap();
758     ModAddCommunity::delete(&conn, inserted_mod_add_community.id).unwrap();
759     ModAdd::delete(&conn, inserted_mod_add.id).unwrap();
760
761     Comment::delete(&conn, inserted_comment.id).unwrap();
762     Post::delete(&conn, inserted_post.id).unwrap();
763     Community::delete(&conn, inserted_community.id).unwrap();
764     User_::delete(&conn, inserted_user.id).unwrap();
765     User_::delete(&conn, inserted_mod.id).unwrap();
766
767     assert_eq!(expected_mod_remove_post, read_mod_remove_post);
768     assert_eq!(expected_mod_lock_post, read_mod_lock_post);
769     assert_eq!(expected_mod_sticky_post, read_mod_sticky_post);
770     assert_eq!(expected_mod_remove_comment, read_mod_remove_comment);
771     assert_eq!(expected_mod_remove_community, read_mod_remove_community);
772     assert_eq!(expected_mod_ban_from_community, read_mod_ban_from_community);
773     assert_eq!(expected_mod_ban, read_mod_ban);
774     assert_eq!(expected_mod_add_community, read_mod_add_community);
775     assert_eq!(expected_mod_add, read_mod_add);
776   }
777 }