6 mod_ban_from_community,
15 use diesel::{dsl::*, result::Error, *};
16 use serde::{Deserialize, Serialize};
18 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
19 #[table_name = "mod_remove_post"]
20 pub struct ModRemovePost {
24 pub reason: Option<String>,
25 pub removed: Option<bool>,
26 pub when_: chrono::NaiveDateTime,
29 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
30 #[table_name = "mod_remove_post"]
31 pub struct ModRemovePostForm {
34 pub reason: Option<String>,
35 pub removed: Option<bool>,
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)
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)
49 fn create(conn: &PgConnection, form: &ModRemovePostForm) -> Result<Self, Error> {
50 use crate::schema::mod_remove_post::dsl::*;
51 insert_into(mod_remove_post)
53 .get_result::<Self>(conn)
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))
60 .get_result::<Self>(conn)
64 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
65 #[table_name = "mod_lock_post"]
66 pub struct ModLockPost {
70 pub locked: Option<bool>,
71 pub when_: chrono::NaiveDateTime,
74 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
75 #[table_name = "mod_lock_post"]
76 pub struct ModLockPostForm {
79 pub locked: Option<bool>,
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)
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)
93 fn create(conn: &PgConnection, form: &ModLockPostForm) -> Result<Self, Error> {
94 use crate::schema::mod_lock_post::dsl::*;
95 insert_into(mod_lock_post)
97 .get_result::<Self>(conn)
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))
104 .get_result::<Self>(conn)
108 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
109 #[table_name = "mod_sticky_post"]
110 pub struct ModStickyPost {
112 pub mod_user_id: i32,
114 pub stickied: Option<bool>,
115 pub when_: chrono::NaiveDateTime,
118 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
119 #[table_name = "mod_sticky_post"]
120 pub struct ModStickyPostForm {
121 pub mod_user_id: i32,
123 pub stickied: Option<bool>,
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)
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)
137 fn create(conn: &PgConnection, form: &ModStickyPostForm) -> Result<Self, Error> {
138 use crate::schema::mod_sticky_post::dsl::*;
139 insert_into(mod_sticky_post)
141 .get_result::<Self>(conn)
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))
148 .get_result::<Self>(conn)
152 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
153 #[table_name = "mod_remove_comment"]
154 pub struct ModRemoveComment {
156 pub mod_user_id: i32,
158 pub reason: Option<String>,
159 pub removed: Option<bool>,
160 pub when_: chrono::NaiveDateTime,
163 #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
164 #[table_name = "mod_remove_comment"]
165 pub struct ModRemoveCommentForm {
166 pub mod_user_id: i32,
168 pub reason: Option<String>,
169 pub removed: Option<bool>,
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)
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)
183 fn create(conn: &PgConnection, form: &ModRemoveCommentForm) -> Result<Self, Error> {
184 use crate::schema::mod_remove_comment::dsl::*;
185 insert_into(mod_remove_comment)
187 .get_result::<Self>(conn)
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))
194 .get_result::<Self>(conn)
198 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
199 #[table_name = "mod_remove_community"]
200 pub struct ModRemoveCommunity {
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,
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>,
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)
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)
231 fn create(conn: &PgConnection, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
232 use crate::schema::mod_remove_community::dsl::*;
233 insert_into(mod_remove_community)
235 .get_result::<Self>(conn)
241 form: &ModRemoveCommunityForm,
242 ) -> Result<Self, Error> {
243 use crate::schema::mod_remove_community::dsl::*;
244 diesel::update(mod_remove_community.find(from_id))
246 .get_result::<Self>(conn)
250 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
251 #[table_name = "mod_ban_from_community"]
252 pub struct ModBanFromCommunity {
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,
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>,
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)
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)
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)
289 .get_result::<Self>(conn)
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))
300 .get_result::<Self>(conn)
304 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
305 #[table_name = "mod_ban"]
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,
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>,
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)
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)
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)
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))
346 .get_result::<Self>(conn)
350 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
351 #[table_name = "mod_add_community"]
352 pub struct ModAddCommunity {
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,
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>,
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)
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)
381 fn create(conn: &PgConnection, form: &ModAddCommunityForm) -> Result<Self, Error> {
382 use crate::schema::mod_add_community::dsl::*;
383 insert_into(mod_add_community)
385 .get_result::<Self>(conn)
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))
392 .get_result::<Self>(conn)
396 #[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize)]
397 #[table_name = "mod_add"]
400 pub mod_user_id: i32,
401 pub other_user_id: i32,
402 pub removed: Option<bool>,
403 pub when_: chrono::NaiveDateTime,
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>,
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)
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)
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)
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))
434 .get_result::<Self>(conn)
445 tests::establish_unpooled_connection,
454 let conn = establish_unpooled_connection();
456 let new_mod = UserForm {
457 name: "the mod".into(),
458 preferred_username: None,
459 password_encrypted: "nope".into(),
461 matrix_user_id: None,
467 theme: "darkly".into(),
468 default_sort_type: SortType::Hot as i16,
469 default_listing_type: ListingType::Subscribed as i16,
470 lang: "browser".into(),
472 send_notifications_to_email: false,
473 actor_id: "changeme_829398".into(),
478 last_refreshed_at: None,
481 let inserted_mod = User_::create(&conn, &new_mod).unwrap();
483 let new_user = UserForm {
485 preferred_username: None,
486 password_encrypted: "nope".into(),
488 matrix_user_id: None,
494 theme: "darkly".into(),
495 default_sort_type: SortType::Hot as i16,
496 default_listing_type: ListingType::Subscribed as i16,
497 lang: "browser".into(),
499 send_notifications_to_email: false,
500 actor_id: "changeme_82982738".into(),
505 last_refreshed_at: None,
508 let inserted_user = User_::create(&conn, &new_user).unwrap();
510 let new_community = CommunityForm {
511 name: "mod_community".to_string(),
512 title: "nada".to_owned(),
515 creator_id: inserted_user.id,
520 actor_id: "changeme_283687".into(),
524 last_refreshed_at: None,
528 let inserted_community = Community::create(&conn, &new_community).unwrap();
530 let new_post = PostForm {
531 name: "A test post thweep".into(),
534 creator_id: inserted_user.id,
535 community_id: inserted_community.id,
543 embed_description: None,
546 ap_id: "http://fake.com".into(),
551 let inserted_post = Post::create(&conn, &new_post).unwrap();
553 let comment_form = CommentForm {
554 content: "A test comment".into(),
555 creator_id: inserted_user.id,
556 post_id: inserted_post.id,
563 ap_id: "http://fake.com".into(),
567 let inserted_comment = Comment::create(&conn, &comment_form).unwrap();
569 // Now the actual tests
572 let mod_remove_post_form = ModRemovePostForm {
573 mod_user_id: inserted_mod.id,
574 post_id: inserted_post.id,
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,
586 when_: inserted_mod_remove_post.when_,
591 let mod_lock_post_form = ModLockPostForm {
592 mod_user_id: inserted_mod.id,
593 post_id: inserted_post.id,
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,
603 when_: inserted_mod_lock_post.when_,
608 let mod_sticky_post_form = ModStickyPostForm {
609 mod_user_id: inserted_mod.id,
610 post_id: inserted_post.id,
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_,
625 let mod_remove_comment_form = ModRemoveCommentForm {
626 mod_user_id: inserted_mod.id,
627 comment_id: inserted_comment.id,
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,
641 when_: inserted_mod_remove_comment.when_,
646 let mod_remove_community_form = ModRemoveCommunityForm {
647 mod_user_id: inserted_mod.id,
648 community_id: inserted_community.id,
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,
664 when_: inserted_mod_remove_community.when_,
667 // ban from community
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,
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,
689 when_: inserted_mod_ban_from_community.when_,
694 let mod_ban_form = ModBanForm {
695 mod_user_id: inserted_mod.id,
696 other_user_id: inserted_user.id,
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,
710 when_: inserted_mod_ban.when_,
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,
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_,
736 let mod_add_form = ModAddForm {
737 mod_user_id: inserted_mod.id,
738 other_user_id: inserted_user.id,
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_,
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();
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();
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);