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,
468 theme: "darkly".into(),
469 default_sort_type: SortType::Hot as i16,
470 default_listing_type: ListingType::Subscribed as i16,
471 lang: "browser".into(),
473 send_notifications_to_email: false,
474 actor_id: "changeme_829398".into(),
479 last_refreshed_at: None,
482 let inserted_mod = User_::create(&conn, &new_mod).unwrap();
484 let new_user = UserForm {
486 preferred_username: None,
487 password_encrypted: "nope".into(),
489 matrix_user_id: None,
496 theme: "darkly".into(),
497 default_sort_type: SortType::Hot as i16,
498 default_listing_type: ListingType::Subscribed as i16,
499 lang: "browser".into(),
501 send_notifications_to_email: false,
502 actor_id: "changeme_82982738".into(),
507 last_refreshed_at: None,
510 let inserted_user = User_::create(&conn, &new_user).unwrap();
512 let new_community = CommunityForm {
513 name: "mod_community".to_string(),
514 title: "nada".to_owned(),
517 creator_id: inserted_user.id,
522 actor_id: "changeme_283687".into(),
526 last_refreshed_at: None,
532 let inserted_community = Community::create(&conn, &new_community).unwrap();
534 let new_post = PostForm {
535 name: "A test post thweep".into(),
538 creator_id: inserted_user.id,
539 community_id: inserted_community.id,
547 embed_description: None,
550 ap_id: "http://fake.com".into(),
555 let inserted_post = Post::create(&conn, &new_post).unwrap();
557 let comment_form = CommentForm {
558 content: "A test comment".into(),
559 creator_id: inserted_user.id,
560 post_id: inserted_post.id,
567 ap_id: "http://fake.com".into(),
571 let inserted_comment = Comment::create(&conn, &comment_form).unwrap();
573 // Now the actual tests
576 let mod_remove_post_form = ModRemovePostForm {
577 mod_user_id: inserted_mod.id,
578 post_id: inserted_post.id,
582 let inserted_mod_remove_post = ModRemovePost::create(&conn, &mod_remove_post_form).unwrap();
583 let read_mod_remove_post = ModRemovePost::read(&conn, inserted_mod_remove_post.id).unwrap();
584 let expected_mod_remove_post = ModRemovePost {
585 id: inserted_mod_remove_post.id,
586 post_id: inserted_post.id,
587 mod_user_id: inserted_mod.id,
590 when_: inserted_mod_remove_post.when_,
595 let mod_lock_post_form = ModLockPostForm {
596 mod_user_id: inserted_mod.id,
597 post_id: inserted_post.id,
600 let inserted_mod_lock_post = ModLockPost::create(&conn, &mod_lock_post_form).unwrap();
601 let read_mod_lock_post = ModLockPost::read(&conn, inserted_mod_lock_post.id).unwrap();
602 let expected_mod_lock_post = ModLockPost {
603 id: inserted_mod_lock_post.id,
604 post_id: inserted_post.id,
605 mod_user_id: inserted_mod.id,
607 when_: inserted_mod_lock_post.when_,
612 let mod_sticky_post_form = ModStickyPostForm {
613 mod_user_id: inserted_mod.id,
614 post_id: inserted_post.id,
617 let inserted_mod_sticky_post = ModStickyPost::create(&conn, &mod_sticky_post_form).unwrap();
618 let read_mod_sticky_post = ModStickyPost::read(&conn, inserted_mod_sticky_post.id).unwrap();
619 let expected_mod_sticky_post = ModStickyPost {
620 id: inserted_mod_sticky_post.id,
621 post_id: inserted_post.id,
622 mod_user_id: inserted_mod.id,
623 stickied: Some(true),
624 when_: inserted_mod_sticky_post.when_,
629 let mod_remove_comment_form = ModRemoveCommentForm {
630 mod_user_id: inserted_mod.id,
631 comment_id: inserted_comment.id,
635 let inserted_mod_remove_comment =
636 ModRemoveComment::create(&conn, &mod_remove_comment_form).unwrap();
637 let read_mod_remove_comment =
638 ModRemoveComment::read(&conn, inserted_mod_remove_comment.id).unwrap();
639 let expected_mod_remove_comment = ModRemoveComment {
640 id: inserted_mod_remove_comment.id,
641 comment_id: inserted_comment.id,
642 mod_user_id: inserted_mod.id,
645 when_: inserted_mod_remove_comment.when_,
650 let mod_remove_community_form = ModRemoveCommunityForm {
651 mod_user_id: inserted_mod.id,
652 community_id: inserted_community.id,
657 let inserted_mod_remove_community =
658 ModRemoveCommunity::create(&conn, &mod_remove_community_form).unwrap();
659 let read_mod_remove_community =
660 ModRemoveCommunity::read(&conn, inserted_mod_remove_community.id).unwrap();
661 let expected_mod_remove_community = ModRemoveCommunity {
662 id: inserted_mod_remove_community.id,
663 community_id: inserted_community.id,
664 mod_user_id: inserted_mod.id,
668 when_: inserted_mod_remove_community.when_,
671 // ban from community
673 let mod_ban_from_community_form = ModBanFromCommunityForm {
674 mod_user_id: inserted_mod.id,
675 other_user_id: inserted_user.id,
676 community_id: inserted_community.id,
681 let inserted_mod_ban_from_community =
682 ModBanFromCommunity::create(&conn, &mod_ban_from_community_form).unwrap();
683 let read_mod_ban_from_community =
684 ModBanFromCommunity::read(&conn, inserted_mod_ban_from_community.id).unwrap();
685 let expected_mod_ban_from_community = ModBanFromCommunity {
686 id: inserted_mod_ban_from_community.id,
687 community_id: inserted_community.id,
688 mod_user_id: inserted_mod.id,
689 other_user_id: inserted_user.id,
693 when_: inserted_mod_ban_from_community.when_,
698 let mod_ban_form = ModBanForm {
699 mod_user_id: inserted_mod.id,
700 other_user_id: inserted_user.id,
705 let inserted_mod_ban = ModBan::create(&conn, &mod_ban_form).unwrap();
706 let read_mod_ban = ModBan::read(&conn, inserted_mod_ban.id).unwrap();
707 let expected_mod_ban = ModBan {
708 id: inserted_mod_ban.id,
709 mod_user_id: inserted_mod.id,
710 other_user_id: inserted_user.id,
714 when_: inserted_mod_ban.when_,
719 let mod_add_community_form = ModAddCommunityForm {
720 mod_user_id: inserted_mod.id,
721 other_user_id: inserted_user.id,
722 community_id: inserted_community.id,
725 let inserted_mod_add_community =
726 ModAddCommunity::create(&conn, &mod_add_community_form).unwrap();
727 let read_mod_add_community =
728 ModAddCommunity::read(&conn, inserted_mod_add_community.id).unwrap();
729 let expected_mod_add_community = ModAddCommunity {
730 id: inserted_mod_add_community.id,
731 community_id: inserted_community.id,
732 mod_user_id: inserted_mod.id,
733 other_user_id: inserted_user.id,
734 removed: Some(false),
735 when_: inserted_mod_add_community.when_,
740 let mod_add_form = ModAddForm {
741 mod_user_id: inserted_mod.id,
742 other_user_id: inserted_user.id,
745 let inserted_mod_add = ModAdd::create(&conn, &mod_add_form).unwrap();
746 let read_mod_add = ModAdd::read(&conn, inserted_mod_add.id).unwrap();
747 let expected_mod_add = ModAdd {
748 id: inserted_mod_add.id,
749 mod_user_id: inserted_mod.id,
750 other_user_id: inserted_user.id,
751 removed: Some(false),
752 when_: inserted_mod_add.when_,
755 ModRemovePost::delete(&conn, inserted_mod_remove_post.id).unwrap();
756 ModLockPost::delete(&conn, inserted_mod_lock_post.id).unwrap();
757 ModStickyPost::delete(&conn, inserted_mod_sticky_post.id).unwrap();
758 ModRemoveComment::delete(&conn, inserted_mod_remove_comment.id).unwrap();
759 ModRemoveCommunity::delete(&conn, inserted_mod_remove_community.id).unwrap();
760 ModBanFromCommunity::delete(&conn, inserted_mod_ban_from_community.id).unwrap();
761 ModBan::delete(&conn, inserted_mod_ban.id).unwrap();
762 ModAddCommunity::delete(&conn, inserted_mod_add_community.id).unwrap();
763 ModAdd::delete(&conn, inserted_mod_add.id).unwrap();
765 Comment::delete(&conn, inserted_comment.id).unwrap();
766 Post::delete(&conn, inserted_post.id).unwrap();
767 Community::delete(&conn, inserted_community.id).unwrap();
768 User_::delete(&conn, inserted_user.id).unwrap();
769 User_::delete(&conn, inserted_mod.id).unwrap();
771 assert_eq!(expected_mod_remove_post, read_mod_remove_post);
772 assert_eq!(expected_mod_lock_post, read_mod_lock_post);
773 assert_eq!(expected_mod_sticky_post, read_mod_sticky_post);
774 assert_eq!(expected_mod_remove_comment, read_mod_remove_comment);
775 assert_eq!(expected_mod_remove_community, read_mod_remove_community);
776 assert_eq!(expected_mod_ban_from_community, read_mod_ban_from_community);
777 assert_eq!(expected_mod_ban, read_mod_ban);
778 assert_eq!(expected_mod_add_community, read_mod_add_community);
779 assert_eq!(expected_mod_add, read_mod_add);