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