6 mod_ban_from_community,
15 use diesel::{dsl::*, result::Error, *};
17 #[derive(Queryable, Identifiable, PartialEq, Debug)]
18 #[table_name = "mod_remove_post"]
19 pub struct ModRemovePost {
23 pub reason: Option<String>,
24 pub removed: Option<bool>,
25 pub when_: chrono::NaiveDateTime,
28 #[derive(Insertable, AsChangeset)]
29 #[table_name = "mod_remove_post"]
30 pub struct ModRemovePostForm {
33 pub reason: Option<String>,
34 pub removed: Option<bool>,
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)
43 fn create(conn: &PgConnection, form: &ModRemovePostForm) -> Result<Self, Error> {
44 use crate::schema::mod_remove_post::dsl::*;
45 insert_into(mod_remove_post)
47 .get_result::<Self>(conn)
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))
54 .get_result::<Self>(conn)
58 #[derive(Queryable, Identifiable, PartialEq, Debug)]
59 #[table_name = "mod_lock_post"]
60 pub struct ModLockPost {
64 pub locked: Option<bool>,
65 pub when_: chrono::NaiveDateTime,
68 #[derive(Insertable, AsChangeset)]
69 #[table_name = "mod_lock_post"]
70 pub struct ModLockPostForm {
73 pub locked: Option<bool>,
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)
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)]
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)]
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 create(conn: &PgConnection, form: &ModStickyPostForm) -> Result<Self, Error> {
122 use crate::schema::mod_sticky_post::dsl::*;
123 insert_into(mod_sticky_post)
125 .get_result::<Self>(conn)
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))
132 .get_result::<Self>(conn)
136 #[derive(Queryable, Identifiable, PartialEq, Debug)]
137 #[table_name = "mod_remove_comment"]
138 pub struct ModRemoveComment {
140 pub mod_user_id: i32,
142 pub reason: Option<String>,
143 pub removed: Option<bool>,
144 pub when_: chrono::NaiveDateTime,
147 #[derive(Insertable, AsChangeset)]
148 #[table_name = "mod_remove_comment"]
149 pub struct ModRemoveCommentForm {
150 pub mod_user_id: i32,
152 pub reason: Option<String>,
153 pub removed: Option<bool>,
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)
162 fn create(conn: &PgConnection, form: &ModRemoveCommentForm) -> Result<Self, Error> {
163 use crate::schema::mod_remove_comment::dsl::*;
164 insert_into(mod_remove_comment)
166 .get_result::<Self>(conn)
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))
173 .get_result::<Self>(conn)
177 #[derive(Queryable, Identifiable, PartialEq, Debug)]
178 #[table_name = "mod_remove_community"]
179 pub struct ModRemoveCommunity {
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,
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>,
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)
205 fn create(conn: &PgConnection, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
206 use crate::schema::mod_remove_community::dsl::*;
207 insert_into(mod_remove_community)
209 .get_result::<Self>(conn)
215 form: &ModRemoveCommunityForm,
216 ) -> Result<Self, Error> {
217 use crate::schema::mod_remove_community::dsl::*;
218 diesel::update(mod_remove_community.find(from_id))
220 .get_result::<Self>(conn)
224 #[derive(Queryable, Identifiable, PartialEq, Debug)]
225 #[table_name = "mod_ban_from_community"]
226 pub struct ModBanFromCommunity {
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,
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>,
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)
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)
258 .get_result::<Self>(conn)
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))
269 .get_result::<Self>(conn)
273 #[derive(Queryable, Identifiable, PartialEq, Debug)]
274 #[table_name = "mod_ban"]
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,
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>,
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)
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)
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))
310 .get_result::<Self>(conn)
314 #[derive(Queryable, Identifiable, PartialEq, Debug)]
315 #[table_name = "mod_add_community"]
316 pub struct ModAddCommunity {
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,
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>,
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)
340 fn create(conn: &PgConnection, form: &ModAddCommunityForm) -> Result<Self, Error> {
341 use crate::schema::mod_add_community::dsl::*;
342 insert_into(mod_add_community)
344 .get_result::<Self>(conn)
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))
351 .get_result::<Self>(conn)
355 #[derive(Queryable, Identifiable, PartialEq, Debug)]
356 #[table_name = "mod_add"]
359 pub mod_user_id: i32,
360 pub other_user_id: i32,
361 pub removed: Option<bool>,
362 pub when_: chrono::NaiveDateTime,
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>,
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)
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)
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))
388 .get_result::<Self>(conn)
399 tests::establish_unpooled_connection,
408 let conn = establish_unpooled_connection();
410 let new_mod = UserForm {
411 name: "the mod".into(),
412 preferred_username: None,
413 password_encrypted: "nope".into(),
415 matrix_user_id: None,
422 theme: "darkly".into(),
423 default_sort_type: SortType::Hot as i16,
424 default_listing_type: ListingType::Subscribed as i16,
425 lang: "browser".into(),
427 send_notifications_to_email: false,
433 last_refreshed_at: None,
436 let inserted_mod = User_::create(&conn, &new_mod).unwrap();
438 let new_user = UserForm {
440 preferred_username: None,
441 password_encrypted: "nope".into(),
443 matrix_user_id: None,
450 theme: "darkly".into(),
451 default_sort_type: SortType::Hot as i16,
452 default_listing_type: ListingType::Subscribed as i16,
453 lang: "browser".into(),
455 send_notifications_to_email: false,
461 last_refreshed_at: None,
464 let inserted_user = User_::create(&conn, &new_user).unwrap();
466 let new_community = CommunityForm {
467 name: "mod_community".to_string(),
468 title: "nada".to_owned(),
471 creator_id: inserted_user.id,
480 last_refreshed_at: None,
486 let inserted_community = Community::create(&conn, &new_community).unwrap();
488 let new_post = PostForm {
489 name: "A test post thweep".into(),
492 creator_id: inserted_user.id,
493 community_id: inserted_community.id,
501 embed_description: None,
509 let inserted_post = Post::create(&conn, &new_post).unwrap();
511 let comment_form = CommentForm {
512 content: "A test comment".into(),
513 creator_id: inserted_user.id,
514 post_id: inserted_post.id,
525 let inserted_comment = Comment::create(&conn, &comment_form).unwrap();
527 // Now the actual tests
530 let mod_remove_post_form = ModRemovePostForm {
531 mod_user_id: inserted_mod.id,
532 post_id: inserted_post.id,
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,
544 when_: inserted_mod_remove_post.when_,
549 let mod_lock_post_form = ModLockPostForm {
550 mod_user_id: inserted_mod.id,
551 post_id: inserted_post.id,
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,
561 when_: inserted_mod_lock_post.when_,
566 let mod_sticky_post_form = ModStickyPostForm {
567 mod_user_id: inserted_mod.id,
568 post_id: inserted_post.id,
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_,
583 let mod_remove_comment_form = ModRemoveCommentForm {
584 mod_user_id: inserted_mod.id,
585 comment_id: inserted_comment.id,
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,
599 when_: inserted_mod_remove_comment.when_,
604 let mod_remove_community_form = ModRemoveCommunityForm {
605 mod_user_id: inserted_mod.id,
606 community_id: inserted_community.id,
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,
622 when_: inserted_mod_remove_community.when_,
625 // ban from community
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,
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,
647 when_: inserted_mod_ban_from_community.when_,
652 let mod_ban_form = ModBanForm {
653 mod_user_id: inserted_mod.id,
654 other_user_id: inserted_user.id,
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,
668 when_: inserted_mod_ban.when_,
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,
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_,
694 let mod_add_form = ModAddForm {
695 mod_user_id: inserted_mod.id,
696 other_user_id: inserted_user.id,
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_,
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();
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);