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