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,
7 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
8 #[table_name = "mod_remove_post"]
9 pub struct ModRemovePost {
13 pub reason: Option<String>,
14 pub removed: Option<bool>,
15 pub when_: chrono::NaiveDateTime,
18 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
19 #[table_name = "mod_remove_post"]
20 pub struct ModRemovePostForm {
23 pub reason: Option<String>,
24 pub removed: Option<bool>,
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)
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)
38 fn create(conn: &PgConnection, form: &ModRemovePostForm) -> Result<Self, Error> {
39 use crate::schema::mod_remove_post::dsl::*;
40 insert_into(mod_remove_post)
42 .get_result::<Self>(conn)
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))
49 .get_result::<Self>(conn)
53 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
54 #[table_name = "mod_lock_post"]
55 pub struct ModLockPost {
59 pub locked: Option<bool>,
60 pub when_: chrono::NaiveDateTime,
63 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
64 #[table_name = "mod_lock_post"]
65 pub struct ModLockPostForm {
68 pub locked: Option<bool>,
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)
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)
82 fn create(conn: &PgConnection, form: &ModLockPostForm) -> Result<Self, Error> {
83 use crate::schema::mod_lock_post::dsl::*;
84 insert_into(mod_lock_post)
86 .get_result::<Self>(conn)
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))
93 .get_result::<Self>(conn)
97 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
98 #[table_name = "mod_sticky_post"]
99 pub struct ModStickyPost {
101 pub mod_user_id: i32,
103 pub stickied: Option<bool>,
104 pub when_: chrono::NaiveDateTime,
107 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
108 #[table_name = "mod_sticky_post"]
109 pub struct ModStickyPostForm {
110 pub mod_user_id: i32,
112 pub stickied: Option<bool>,
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)
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)
126 fn create(conn: &PgConnection, form: &ModStickyPostForm) -> Result<Self, Error> {
127 use crate::schema::mod_sticky_post::dsl::*;
128 insert_into(mod_sticky_post)
130 .get_result::<Self>(conn)
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))
137 .get_result::<Self>(conn)
141 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
142 #[table_name = "mod_remove_comment"]
143 pub struct ModRemoveComment {
145 pub mod_user_id: i32,
147 pub reason: Option<String>,
148 pub removed: Option<bool>,
149 pub when_: chrono::NaiveDateTime,
152 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
153 #[table_name = "mod_remove_comment"]
154 pub struct ModRemoveCommentForm {
155 pub mod_user_id: i32,
157 pub reason: Option<String>,
158 pub removed: Option<bool>,
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)
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)
172 fn create(conn: &PgConnection, form: &ModRemoveCommentForm) -> Result<Self, Error> {
173 use crate::schema::mod_remove_comment::dsl::*;
174 insert_into(mod_remove_comment)
176 .get_result::<Self>(conn)
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))
183 .get_result::<Self>(conn)
187 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
188 #[table_name = "mod_remove_community"]
189 pub struct ModRemoveCommunity {
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,
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>,
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)
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)
220 fn create(conn: &PgConnection, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
221 use crate::schema::mod_remove_community::dsl::*;
222 insert_into(mod_remove_community)
224 .get_result::<Self>(conn)
230 form: &ModRemoveCommunityForm,
231 ) -> Result<Self, Error> {
232 use crate::schema::mod_remove_community::dsl::*;
233 diesel::update(mod_remove_community.find(from_id))
235 .get_result::<Self>(conn)
239 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
240 #[table_name = "mod_ban_from_community"]
241 pub struct ModBanFromCommunity {
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,
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>,
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)
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)
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)
278 .get_result::<Self>(conn)
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))
289 .get_result::<Self>(conn)
293 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
294 #[table_name = "mod_ban"]
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,
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>,
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)
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)
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)
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))
335 .get_result::<Self>(conn)
339 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
340 #[table_name = "mod_add_community"]
341 pub struct ModAddCommunity {
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,
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>,
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)
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)
370 fn create(conn: &PgConnection, form: &ModAddCommunityForm) -> Result<Self, Error> {
371 use crate::schema::mod_add_community::dsl::*;
372 insert_into(mod_add_community)
374 .get_result::<Self>(conn)
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))
381 .get_result::<Self>(conn)
385 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
386 #[table_name = "mod_add"]
389 pub mod_user_id: i32,
390 pub other_user_id: i32,
391 pub removed: Option<bool>,
392 pub when_: chrono::NaiveDateTime,
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>,
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)
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)
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)
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))
423 .get_result::<Self>(conn)
429 use super::super::comment::*;
430 use super::super::community::*;
431 use super::super::post::*;
432 use super::super::user::*;
437 let conn = establish_unpooled_connection();
439 let new_mod = UserForm {
440 name: "the mod".into(),
441 fedi_name: "rrf".into(),
442 preferred_username: None,
443 password_encrypted: "nope".into(),
445 matrix_user_id: None,
451 theme: "darkly".into(),
452 default_sort_type: SortType::Hot as i16,
453 default_listing_type: ListingType::Subscribed as i16,
454 lang: "browser".into(),
456 send_notifications_to_email: false,
459 let inserted_mod = User_::create(&conn, &new_mod).unwrap();
461 let new_user = UserForm {
463 fedi_name: "rrf".into(),
464 preferred_username: None,
465 password_encrypted: "nope".into(),
467 matrix_user_id: None,
473 theme: "darkly".into(),
474 default_sort_type: SortType::Hot as i16,
475 default_listing_type: ListingType::Subscribed as i16,
476 lang: "browser".into(),
478 send_notifications_to_email: false,
481 let inserted_user = User_::create(&conn, &new_user).unwrap();
483 let new_community = CommunityForm {
484 name: "mod_community".to_string(),
485 title: "nada".to_owned(),
488 creator_id: inserted_user.id,
495 let inserted_community = Community::create(&conn, &new_community).unwrap();
497 let new_post = PostForm {
498 name: "A test post thweep".into(),
501 creator_id: inserted_user.id,
502 community_id: inserted_community.id,
510 embed_description: None,
515 let inserted_post = Post::create(&conn, &new_post).unwrap();
517 let comment_form = CommentForm {
518 content: "A test comment".into(),
519 creator_id: inserted_user.id,
520 post_id: inserted_post.id,
528 let inserted_comment = Comment::create(&conn, &comment_form).unwrap();
530 // Now the actual tests
533 let mod_remove_post_form = ModRemovePostForm {
534 mod_user_id: inserted_mod.id,
535 post_id: inserted_post.id,
539 let inserted_mod_remove_post = ModRemovePost::create(&conn, &mod_remove_post_form).unwrap();
540 let read_mod_remove_post = ModRemovePost::read(&conn, inserted_mod_remove_post.id).unwrap();
541 let expected_mod_remove_post = ModRemovePost {
542 id: inserted_mod_remove_post.id,
543 post_id: inserted_post.id,
544 mod_user_id: inserted_mod.id,
547 when_: inserted_mod_remove_post.when_,
552 let mod_lock_post_form = ModLockPostForm {
553 mod_user_id: inserted_mod.id,
554 post_id: inserted_post.id,
557 let inserted_mod_lock_post = ModLockPost::create(&conn, &mod_lock_post_form).unwrap();
558 let read_mod_lock_post = ModLockPost::read(&conn, inserted_mod_lock_post.id).unwrap();
559 let expected_mod_lock_post = ModLockPost {
560 id: inserted_mod_lock_post.id,
561 post_id: inserted_post.id,
562 mod_user_id: inserted_mod.id,
564 when_: inserted_mod_lock_post.when_,
569 let mod_sticky_post_form = ModStickyPostForm {
570 mod_user_id: inserted_mod.id,
571 post_id: inserted_post.id,
574 let inserted_mod_sticky_post = ModStickyPost::create(&conn, &mod_sticky_post_form).unwrap();
575 let read_mod_sticky_post = ModStickyPost::read(&conn, inserted_mod_sticky_post.id).unwrap();
576 let expected_mod_sticky_post = ModStickyPost {
577 id: inserted_mod_sticky_post.id,
578 post_id: inserted_post.id,
579 mod_user_id: inserted_mod.id,
580 stickied: Some(true),
581 when_: inserted_mod_sticky_post.when_,
586 let mod_remove_comment_form = ModRemoveCommentForm {
587 mod_user_id: inserted_mod.id,
588 comment_id: inserted_comment.id,
592 let inserted_mod_remove_comment =
593 ModRemoveComment::create(&conn, &mod_remove_comment_form).unwrap();
594 let read_mod_remove_comment =
595 ModRemoveComment::read(&conn, inserted_mod_remove_comment.id).unwrap();
596 let expected_mod_remove_comment = ModRemoveComment {
597 id: inserted_mod_remove_comment.id,
598 comment_id: inserted_comment.id,
599 mod_user_id: inserted_mod.id,
602 when_: inserted_mod_remove_comment.when_,
607 let mod_remove_community_form = ModRemoveCommunityForm {
608 mod_user_id: inserted_mod.id,
609 community_id: inserted_community.id,
614 let inserted_mod_remove_community =
615 ModRemoveCommunity::create(&conn, &mod_remove_community_form).unwrap();
616 let read_mod_remove_community =
617 ModRemoveCommunity::read(&conn, inserted_mod_remove_community.id).unwrap();
618 let expected_mod_remove_community = ModRemoveCommunity {
619 id: inserted_mod_remove_community.id,
620 community_id: inserted_community.id,
621 mod_user_id: inserted_mod.id,
625 when_: inserted_mod_remove_community.when_,
628 // ban from community
630 let mod_ban_from_community_form = ModBanFromCommunityForm {
631 mod_user_id: inserted_mod.id,
632 other_user_id: inserted_user.id,
633 community_id: inserted_community.id,
638 let inserted_mod_ban_from_community =
639 ModBanFromCommunity::create(&conn, &mod_ban_from_community_form).unwrap();
640 let read_mod_ban_from_community =
641 ModBanFromCommunity::read(&conn, inserted_mod_ban_from_community.id).unwrap();
642 let expected_mod_ban_from_community = ModBanFromCommunity {
643 id: inserted_mod_ban_from_community.id,
644 community_id: inserted_community.id,
645 mod_user_id: inserted_mod.id,
646 other_user_id: inserted_user.id,
650 when_: inserted_mod_ban_from_community.when_,
655 let mod_ban_form = ModBanForm {
656 mod_user_id: inserted_mod.id,
657 other_user_id: inserted_user.id,
662 let inserted_mod_ban = ModBan::create(&conn, &mod_ban_form).unwrap();
663 let read_mod_ban = ModBan::read(&conn, inserted_mod_ban.id).unwrap();
664 let expected_mod_ban = ModBan {
665 id: inserted_mod_ban.id,
666 mod_user_id: inserted_mod.id,
667 other_user_id: inserted_user.id,
671 when_: inserted_mod_ban.when_,
676 let mod_add_community_form = ModAddCommunityForm {
677 mod_user_id: inserted_mod.id,
678 other_user_id: inserted_user.id,
679 community_id: inserted_community.id,
682 let inserted_mod_add_community =
683 ModAddCommunity::create(&conn, &mod_add_community_form).unwrap();
684 let read_mod_add_community =
685 ModAddCommunity::read(&conn, inserted_mod_add_community.id).unwrap();
686 let expected_mod_add_community = ModAddCommunity {
687 id: inserted_mod_add_community.id,
688 community_id: inserted_community.id,
689 mod_user_id: inserted_mod.id,
690 other_user_id: inserted_user.id,
691 removed: Some(false),
692 when_: inserted_mod_add_community.when_,
697 let mod_add_form = ModAddForm {
698 mod_user_id: inserted_mod.id,
699 other_user_id: inserted_user.id,
702 let inserted_mod_add = ModAdd::create(&conn, &mod_add_form).unwrap();
703 let read_mod_add = ModAdd::read(&conn, inserted_mod_add.id).unwrap();
704 let expected_mod_add = ModAdd {
705 id: inserted_mod_add.id,
706 mod_user_id: inserted_mod.id,
707 other_user_id: inserted_user.id,
708 removed: Some(false),
709 when_: inserted_mod_add.when_,
712 ModRemovePost::delete(&conn, inserted_mod_remove_post.id).unwrap();
713 ModLockPost::delete(&conn, inserted_mod_lock_post.id).unwrap();
714 ModStickyPost::delete(&conn, inserted_mod_sticky_post.id).unwrap();
715 ModRemoveComment::delete(&conn, inserted_mod_remove_comment.id).unwrap();
716 ModRemoveCommunity::delete(&conn, inserted_mod_remove_community.id).unwrap();
717 ModBanFromCommunity::delete(&conn, inserted_mod_ban_from_community.id).unwrap();
718 ModBan::delete(&conn, inserted_mod_ban.id).unwrap();
719 ModAddCommunity::delete(&conn, inserted_mod_add_community.id).unwrap();
720 ModAdd::delete(&conn, inserted_mod_add.id).unwrap();
722 Comment::delete(&conn, inserted_comment.id).unwrap();
723 Post::delete(&conn, inserted_post.id).unwrap();
724 Community::delete(&conn, inserted_community.id).unwrap();
725 User_::delete(&conn, inserted_user.id).unwrap();
726 User_::delete(&conn, inserted_mod.id).unwrap();
728 assert_eq!(expected_mod_remove_post, read_mod_remove_post);
729 assert_eq!(expected_mod_lock_post, read_mod_lock_post);
730 assert_eq!(expected_mod_sticky_post, read_mod_sticky_post);
731 assert_eq!(expected_mod_remove_comment, read_mod_remove_comment);
732 assert_eq!(expected_mod_remove_community, read_mod_remove_community);
733 assert_eq!(expected_mod_ban_from_community, read_mod_ban_from_community);
734 assert_eq!(expected_mod_ban, read_mod_ban);
735 assert_eq!(expected_mod_add_community, read_mod_add_community);
736 assert_eq!(expected_mod_add, read_mod_add);