diff --git a/Cargo.lock b/Cargo.lock index 96313ce6..9a098f8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3070,9 +3070,9 @@ dependencies = [ [[package]] name = "pear_codegen" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfc1c836fdc3d1ef87c348b237b5b5c4dff922156fb2d968f57734f9669768ca" +checksum = "c0288ba5d581afbc93e2bbd931c1013584c15ecf46b1cdb927edc7abddbc8ca6" dependencies = [ "proc-macro2 0.4.30", "quote 0.6.13", diff --git a/Dockerfile b/Dockerfile index 1c211321..cfd52f1d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,8 +20,6 @@ RUN chmod a+x ./wasm-deps.sh && sleep 1 && ./wasm-deps.sh WORKDIR /app COPY . . -RUN echo nightly-2022-07-19 > rust-toolchain - RUN cargo install wasm-pack RUN chmod a+x ./script/plume-front.sh && sleep 1 && ./script/plume-front.sh RUN cargo install --path ./ --force --no-default-features --features postgres diff --git a/plume-common/src/activity_pub/sign.rs b/plume-common/src/activity_pub/sign.rs index 22aaf9d6..b7613b01 100644 --- a/plume-common/src/activity_pub/sign.rs +++ b/plume-common/src/activity_pub/sign.rs @@ -119,7 +119,7 @@ impl Signable for serde_json::Value { } } -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum SignatureValidity { Invalid, ValidNoDigest, diff --git a/plume-models/src/api_tokens.rs b/plume-models/src/api_tokens.rs index dfff4135..2a9d3618 100644 --- a/plume-models/src/api_tokens.rs +++ b/plume-models/src/api_tokens.rs @@ -103,7 +103,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for ApiToken { let conn = request .guard::() .map_failure(|_| (Status::InternalServerError, TokenError::DbError))?; - if let Ok(token) = ApiToken::find_by_value(&*conn, val) { + if let Ok(token) = ApiToken::find_by_value(&conn, val) { return Outcome::Success(token); } } diff --git a/plume-models/src/blocklisted_emails.rs b/plume-models/src/blocklisted_emails.rs index 3d9928b3..a6889244 100644 --- a/plume-models/src/blocklisted_emails.rs +++ b/plume-models/src/blocklisted_emails.rs @@ -126,11 +126,10 @@ pub(crate) mod tests { .id, various[1].id ); - assert_eq!( + assert!( BlocklistedEmail::matches_blocklist(&conn, no_match) .unwrap() - .is_none(), - true + .is_none() ); Ok(()) }); diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index fb20be48..489589a1 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -660,7 +660,7 @@ pub(crate) mod tests { .unwrap() .id, ); - let _: Blog = blog1.save_changes(&*conn).unwrap(); + let _: Blog = blog1.save_changes(conn).unwrap(); (users, vec![blog1, blog2, blog3]) } @@ -669,10 +669,10 @@ pub(crate) mod tests { fn get_instance() { let conn = &db(); conn.test_transaction::<_, (), _>(|| { - fill_database(&conn); + fill_database(conn); let blog = Blog::insert( - &conn, + conn, NewBlog::new_local( "SomeName".to_owned(), "Some name".to_owned(), @@ -684,7 +684,7 @@ pub(crate) mod tests { .unwrap(); assert_eq!( - blog.get_instance(&conn).unwrap().id, + blog.get_instance(conn).unwrap().id, Instance::get_local().unwrap().id ); // TODO add tests for remote instance @@ -696,10 +696,10 @@ pub(crate) mod tests { fn authors() { let conn = &db(); conn.test_transaction::<_, (), _>(|| { - let (user, _) = fill_database(&conn); + let (user, _) = fill_database(conn); let b1 = Blog::insert( - &conn, + conn, NewBlog::new_local( "SomeName".to_owned(), "Some name".to_owned(), @@ -710,7 +710,7 @@ pub(crate) mod tests { ) .unwrap(); let b2 = Blog::insert( - &conn, + conn, NewBlog::new_local( "Blog".to_owned(), "Blog".to_owned(), @@ -723,7 +723,7 @@ pub(crate) mod tests { let blog = vec![b1, b2]; BlogAuthor::insert( - &conn, + conn, NewBlogAuthor { blog_id: blog[0].id, author_id: user[0].id, @@ -733,7 +733,7 @@ pub(crate) mod tests { .unwrap(); BlogAuthor::insert( - &conn, + conn, NewBlogAuthor { blog_id: blog[0].id, author_id: user[1].id, @@ -743,7 +743,7 @@ pub(crate) mod tests { .unwrap(); BlogAuthor::insert( - &conn, + conn, NewBlogAuthor { blog_id: blog[1].id, author_id: user[0].id, @@ -753,39 +753,39 @@ pub(crate) mod tests { .unwrap(); assert!(blog[0] - .list_authors(&conn) + .list_authors(conn) .unwrap() .iter() .any(|a| a.id == user[0].id)); assert!(blog[0] - .list_authors(&conn) + .list_authors(conn) .unwrap() .iter() .any(|a| a.id == user[1].id)); assert!(blog[1] - .list_authors(&conn) + .list_authors(conn) .unwrap() .iter() .any(|a| a.id == user[0].id)); assert!(!blog[1] - .list_authors(&conn) + .list_authors(conn) .unwrap() .iter() .any(|a| a.id == user[1].id)); - assert!(Blog::find_for_author(&conn, &user[0]) + assert!(Blog::find_for_author(conn, &user[0]) .unwrap() .iter() .any(|b| b.id == blog[0].id)); - assert!(Blog::find_for_author(&conn, &user[1]) + assert!(Blog::find_for_author(conn, &user[1]) .unwrap() .iter() .any(|b| b.id == blog[0].id)); - assert!(Blog::find_for_author(&conn, &user[0]) + assert!(Blog::find_for_author(conn, &user[0]) .unwrap() .iter() .any(|b| b.id == blog[1].id)); - assert!(!Blog::find_for_author(&conn, &user[1]) + assert!(!Blog::find_for_author(conn, &user[1]) .unwrap() .iter() .any(|b| b.id == blog[1].id)); @@ -797,10 +797,10 @@ pub(crate) mod tests { fn find_local() { let conn = &db(); conn.test_transaction::<_, (), _>(|| { - fill_database(&conn); + fill_database(conn); let blog = Blog::insert( - &conn, + conn, NewBlog::new_local( "SomeName".to_owned(), "Some name".to_owned(), @@ -811,7 +811,7 @@ pub(crate) mod tests { ) .unwrap(); - assert_eq!(Blog::find_by_fqn(&conn, "SomeName").unwrap().id, blog.id); + assert_eq!(Blog::find_by_fqn(conn, "SomeName").unwrap().id, blog.id); Ok(()) }) } @@ -820,10 +820,10 @@ pub(crate) mod tests { fn get_fqn() { let conn = &db(); conn.test_transaction::<_, (), _>(|| { - fill_database(&conn); + fill_database(conn); let blog = Blog::insert( - &conn, + conn, NewBlog::new_local( "SomeName".to_owned(), "Some name".to_owned(), @@ -843,10 +843,10 @@ pub(crate) mod tests { fn delete() { let conn = &db(); conn.test_transaction::<_, (), _>(|| { - let (_, blogs) = fill_database(&conn); + let (_, blogs) = fill_database(conn); - blogs[0].delete(&conn).unwrap(); - assert!(Blog::get(&conn, blogs[0].id).is_err()); + blogs[0].delete(conn).unwrap(); + assert!(Blog::get(conn, blogs[0].id).is_err()); Ok(()) }) } @@ -855,10 +855,10 @@ pub(crate) mod tests { fn delete_via_user() { let conn = &db(); conn.test_transaction::<_, (), _>(|| { - let (user, _) = fill_database(&conn); + let (user, _) = fill_database(conn); let b1 = Blog::insert( - &conn, + conn, NewBlog::new_local( "SomeName".to_owned(), "Some name".to_owned(), @@ -869,7 +869,7 @@ pub(crate) mod tests { ) .unwrap(); let b2 = Blog::insert( - &conn, + conn, NewBlog::new_local( "Blog".to_owned(), "Blog".to_owned(), @@ -882,7 +882,7 @@ pub(crate) mod tests { let blog = vec![b1, b2]; BlogAuthor::insert( - &conn, + conn, NewBlogAuthor { blog_id: blog[0].id, author_id: user[0].id, @@ -892,7 +892,7 @@ pub(crate) mod tests { .unwrap(); BlogAuthor::insert( - &conn, + conn, NewBlogAuthor { blog_id: blog[0].id, author_id: user[1].id, @@ -902,7 +902,7 @@ pub(crate) mod tests { .unwrap(); BlogAuthor::insert( - &conn, + conn, NewBlogAuthor { blog_id: blog[1].id, author_id: user[0].id, @@ -911,11 +911,11 @@ pub(crate) mod tests { ) .unwrap(); - user[0].delete(&conn).unwrap(); - assert!(Blog::get(&conn, blog[0].id).is_ok()); - assert!(Blog::get(&conn, blog[1].id).is_err()); - user[1].delete(&conn).unwrap(); - assert!(Blog::get(&conn, blog[0].id).is_err()); + user[0].delete(conn).unwrap(); + assert!(Blog::get(conn, blog[0].id).is_ok()); + assert!(Blog::get(conn, blog[1].id).is_err()); + user[1].delete(conn).unwrap(); + assert!(Blog::get(conn, blog[0].id).is_err()); Ok(()) }) } @@ -924,10 +924,10 @@ pub(crate) mod tests { fn self_federation() { let conn = &db(); conn.test_transaction::<_, (), _>(|| { - let (users, mut blogs) = fill_database(&conn); + let (users, mut blogs) = fill_database(conn); blogs[0].icon_id = Some( Media::insert( - &conn, + conn, NewMedia { file_path: "aaa.png".into(), alt_text: String::new(), @@ -943,7 +943,7 @@ pub(crate) mod tests { ); blogs[0].banner_id = Some( Media::insert( - &conn, + conn, NewMedia { file_path: "bbb.png".into(), alt_text: String::new(), @@ -958,9 +958,9 @@ pub(crate) mod tests { .id, ); let _: Blog = blogs[0].save_changes(&**conn).unwrap(); - let ap_repr = blogs[0].to_activity(&conn).unwrap(); - blogs[0].delete(&conn).unwrap(); - let blog = Blog::from_activity(&conn, ap_repr).unwrap(); + let ap_repr = blogs[0].to_activity(conn).unwrap(); + blogs[0].delete(conn).unwrap(); + let blog = Blog::from_activity(conn, ap_repr).unwrap(); assert_eq!(blog.actor_id, blogs[0].actor_id); assert_eq!(blog.title, blogs[0].title); @@ -972,8 +972,8 @@ pub(crate) mod tests { assert_eq!(blog.public_key, blogs[0].public_key); assert_eq!(blog.fqn, blogs[0].fqn); assert_eq!(blog.summary_html, blogs[0].summary_html); - assert_eq!(blog.icon_url(&conn), blogs[0].icon_url(&conn)); - assert_eq!(blog.banner_url(&conn), blogs[0].banner_url(&conn)); + assert_eq!(blog.icon_url(conn), blogs[0].icon_url(conn)); + assert_eq!(blog.banner_url(conn), blogs[0].banner_url(conn)); Ok(()) }) @@ -983,7 +983,7 @@ pub(crate) mod tests { fn to_activity() { let conn = &db(); conn.test_transaction::<_, Error, _>(|| { - let (_users, blogs) = fill_database(&conn); + let (_users, blogs) = fill_database(conn); let blog = &blogs[0]; let act = blog.to_activity(conn)?; diff --git a/plume-models/src/comments.rs b/plume-models/src/comments.rs index d928b9a3..2ae71d93 100644 --- a/plume-models/src/comments.rs +++ b/plume-models/src/comments.rs @@ -381,7 +381,7 @@ impl AsObject for Comment { } for n in Notification::find_for_comment(conn, &self)? { - n.delete(&**conn)?; + n.delete(conn)?; } diesel::update(comments::table) @@ -431,7 +431,7 @@ mod tests { use serde_json::{json, to_value}; fn prepare_activity(conn: &DbConn) -> (Comment, Vec, Vec, Vec) { - let (posts, users, blogs) = fill_database(&conn); + let (posts, users, blogs) = fill_database(conn); let comment = Comment::insert( conn, @@ -457,8 +457,8 @@ mod tests { fn self_federation() { let conn = &db(); conn.test_transaction::<_, (), _>(|| { - let (original_comm, posts, users, _blogs) = prepare_activity(&conn); - let act = original_comm.create_activity(&conn).unwrap(); + let (original_comm, posts, users, _blogs) = prepare_activity(conn); + let act = original_comm.create_activity(conn).unwrap(); assert_json_eq!(to_value(&act).unwrap(), json!({ "actor": "https://plu.me/@/admin/", @@ -500,7 +500,7 @@ mod tests { }, ) .unwrap(); - let reply_act = reply.create_activity(&conn).unwrap(); + let reply_act = reply.create_activity(conn).unwrap(); assert_json_eq!(to_value(&reply_act).unwrap(), json!({ "actor": "https://plu.me/@/user/", @@ -522,12 +522,12 @@ mod tests { })); inbox( - &conn, - serde_json::to_value(original_comm.build_delete(&conn).unwrap()).unwrap(), + conn, + serde_json::to_value(original_comm.build_delete(conn).unwrap()).unwrap(), ) .unwrap(); - match inbox(&conn, to_value(act).unwrap()).unwrap() { + match inbox(conn, to_value(act).unwrap()).unwrap() { InboxResult::Commented(c) => { // TODO: one is HTML, the other markdown: assert_eq!(c.content, original_comm.content); assert_eq!(c.in_response_to_id, original_comm.in_response_to_id); diff --git a/plume-models/src/db_conn.rs b/plume-models/src/db_conn.rs index 5e461b18..1f683f7f 100644 --- a/plume-models/src/db_conn.rs +++ b/plume-models/src/db_conn.rs @@ -69,7 +69,8 @@ pub(crate) mod tests { impl CustomizeConnection for TestConnectionCustomizer { fn on_acquire(&self, conn: &mut Connection) -> Result<(), ConnError> { PragmaForeignKey.on_acquire(conn)?; - Ok(conn.begin_test_transaction().unwrap()) + conn.begin_test_transaction().unwrap(); + Ok(()) } } } diff --git a/plume-models/src/follows.rs b/plume-models/src/follows.rs index c74b90a1..1d47b2d5 100644 --- a/plume-models/src/follows.rs +++ b/plume-models/src/follows.rs @@ -108,7 +108,7 @@ impl Follow { let accept = res.build_accept(from, target, follow)?; broadcast( - &*target, + target, accept, vec![from.clone()], CONFIG.proxy().cloned(), diff --git a/plume-models/src/inbox.rs b/plume-models/src/inbox.rs index fdf4056e..aafc8b32 100644 --- a/plume-models/src/inbox.rs +++ b/plume-models/src/inbox.rs @@ -82,9 +82,9 @@ pub(crate) mod tests { use crate::post_authors::*; use crate::posts::*; - let (users, blogs) = blog_fill_db(&conn); + let (users, blogs) = blog_fill_db(conn); let post = Post::insert( - &conn, + conn, NewPost { blog_id: blogs[0].id, slug: "testing".to_owned(), @@ -102,7 +102,7 @@ pub(crate) mod tests { .unwrap(); PostAuthor::insert( - &conn, + conn, NewPostAuthor { post_id: post.id, author_id: users[0].id, @@ -190,7 +190,7 @@ pub(crate) mod tests { }); assert!(matches!( - super::inbox(&conn, act.clone()), + super::inbox(&conn, act), Err(super::Error::Inbox( box plume_common::activity_pub::inbox::InboxError::InvalidObject(_), )) @@ -221,7 +221,7 @@ pub(crate) mod tests { }); assert!(matches!( - super::inbox(&conn, act.clone()), + super::inbox(&conn, act), Err(super::Error::Inbox( box plume_common::activity_pub::inbox::InboxError::InvalidObject(_), )) @@ -249,7 +249,7 @@ pub(crate) mod tests { }); assert!(matches!( - super::inbox(&conn, act.clone()), + super::inbox(&conn, act), Err(super::Error::Inbox( box plume_common::activity_pub::inbox::InboxError::InvalidObject(_), )) @@ -324,7 +324,7 @@ pub(crate) mod tests { }); assert!(matches!( - super::inbox(&conn, act.clone()), + super::inbox(&conn, act), Err(super::Error::Inbox( box plume_common::activity_pub::inbox::InboxError::InvalidObject(_), )) @@ -362,7 +362,7 @@ pub(crate) mod tests { }); assert!(matches!( - super::inbox(&conn, act.clone()), + super::inbox(&conn, act), Err(super::Error::Inbox( box plume_common::activity_pub::inbox::InboxError::InvalidObject(_), )) @@ -397,7 +397,7 @@ pub(crate) mod tests { }); assert!(matches!( - super::inbox(&conn, act.clone()), + super::inbox(&conn, act), Err(super::Error::Inbox( box plume_common::activity_pub::inbox::InboxError::InvalidObject(_), )) diff --git a/plume-models/src/instance.rs b/plume-models/src/instance.rs index 86cb3d46..5400a126 100644 --- a/plume-models/src/instance.rs +++ b/plume-models/src/instance.rs @@ -523,7 +523,7 @@ pub(crate) mod tests { .unwrap(); let inst = Instance::get(conn, inst.id).unwrap(); assert_eq!(inst.name, "NewName".to_owned()); - assert_eq!(inst.open_registrations, false); + assert!(!inst.open_registrations); assert_eq!( inst.long_description.get(), "[long_description](/with_link)" diff --git a/plume-models/src/lib.rs b/plume-models/src/lib.rs index c9c991b4..e74a201c 100644 --- a/plume-models/src/lib.rs +++ b/plume-models/src/lib.rs @@ -177,7 +177,7 @@ pub type Result = std::result::Result; /// /// Usage: /// -/// ```rust +/// ```ignore /// impl Model { /// find_by!(model_table, name_of_the_function, field1 as String, field2 as i32); /// } @@ -201,7 +201,7 @@ macro_rules! find_by { /// /// Usage: /// -/// ```rust +/// ```ignore /// impl Model { /// list_by!(model_table, name_of_the_function, field1 as String); /// } @@ -225,7 +225,7 @@ macro_rules! list_by { /// /// # Usage /// -/// ```rust +/// ```ignore /// impl Model { /// get!(model_table); /// } @@ -248,7 +248,7 @@ macro_rules! get { /// /// # Usage /// -/// ```rust +/// ```ignore /// impl Model { /// insert!(model_table, NewModelType); /// } @@ -280,7 +280,7 @@ macro_rules! insert { /// /// # Usage /// -/// ```rust +/// ```ignore /// impl Model { /// last!(model_table); /// } @@ -354,7 +354,7 @@ mod tests { }; } - pub fn db<'a>() -> db_conn::DbConn { + pub fn db() -> db_conn::DbConn { db_conn::DbConn((*DB_POOL).get().unwrap()) } diff --git a/plume-models/src/likes.rs b/plume-models/src/likes.rs index b9dda167..5cf0b29d 100644 --- a/plume-models/src/likes.rs +++ b/plume-models/src/likes.rs @@ -199,7 +199,7 @@ mod tests { let (posts, _users, _blogs) = fill_database(&conn); let post = &posts[0]; let user = &post.get_authors(&conn)?[0]; - let like = Like::insert(&*conn, NewLike::new(post, user))?; + let like = Like::insert(&conn, NewLike::new(post, user))?; let act = like.to_activity(&conn).unwrap(); let expected = json!({ @@ -223,8 +223,8 @@ mod tests { let (posts, _users, _blogs) = fill_database(&conn); let post = &posts[0]; let user = &post.get_authors(&conn)?[0]; - let like = Like::insert(&*conn, NewLike::new(post, user))?; - let act = like.build_undo(&*conn)?; + let like = Like::insert(&conn, NewLike::new(post, user))?; + let act = like.build_undo(&conn)?; let expected = json!({ "actor": "https://plu.me/@/admin/", diff --git a/plume-models/src/lists.rs b/plume-models/src/lists.rs index 5b393f64..3a27fc52 100644 --- a/plume-models/src/lists.rs +++ b/plume-models/src/lists.rs @@ -413,7 +413,7 @@ mod tests { &List::find_for_user_by_name(conn, l1.user_id, &l1.name).unwrap(), ); l_eq( - &&l1u, + &l1u, &List::find_for_user_by_name(conn, l1u.user_id, &l1u.name).unwrap(), ); Ok(()) diff --git a/plume-models/src/medias.rs b/plume-models/src/medias.rs index 05a5278c..0d9d1157 100644 --- a/plume-models/src/medias.rs +++ b/plume-models/src/medias.rs @@ -42,7 +42,7 @@ pub struct NewMedia { pub owner_id: i32, } -#[derive(PartialEq)] +#[derive(PartialEq, Eq)] pub enum MediaCategory { Image, Audio, @@ -343,7 +343,7 @@ pub(crate) mod tests { use std::path::Path; pub(crate) fn fill_database(conn: &Conn) -> (Vec, Vec) { - let mut wd = current_dir().unwrap().to_path_buf(); + let mut wd = current_dir().unwrap(); while wd.pop() { if wd.join(".git").exists() { set_current_dir(wd).unwrap(); @@ -456,7 +456,7 @@ pub(crate) mod tests { let media = Media::insert( conn, NewMedia { - file_path: path.clone(), + file_path: path, alt_text: "alt message".to_owned(), is_remote: false, remote_url: None, diff --git a/plume-models/src/password_reset_requests.rs b/plume-models/src/password_reset_requests.rs index cfd93529..332fdf93 100644 --- a/plume-models/src/password_reset_requests.rs +++ b/plume-models/src/password_reset_requests.rs @@ -89,7 +89,7 @@ mod tests { let request = PasswordResetRequest::find_by_token(&conn, &token) .expect("couldn't retrieve request"); - assert!(&token.len() > &32); + assert!(token.len() > 32); assert_eq!(&request.email, &admin_email); Ok(()) @@ -103,8 +103,8 @@ mod tests { user_tests::fill_database(&conn); let admin_email = "admin@example.com"; - PasswordResetRequest::insert(&conn, &admin_email).expect("couldn't insert new request"); - PasswordResetRequest::insert(&conn, &admin_email) + PasswordResetRequest::insert(&conn, admin_email).expect("couldn't insert new request"); + PasswordResetRequest::insert(&conn, admin_email) .expect("couldn't insert second request"); let count = password_reset_requests::table.count().get_result(&*conn); @@ -132,7 +132,7 @@ mod tests { .execute(&*conn) .expect("could not insert request"); - match PasswordResetRequest::find_by_token(&conn, &token) { + match PasswordResetRequest::find_by_token(&conn, token) { Err(Error::Expired) => (), _ => panic!("Received unexpected result finding expired token"), } @@ -148,7 +148,7 @@ mod tests { user_tests::fill_database(&conn); let admin_email = "admin@example.com"; - let token = PasswordResetRequest::insert(&conn, &admin_email) + let token = PasswordResetRequest::insert(&conn, admin_email) .expect("couldn't insert new request"); PasswordResetRequest::find_and_delete_by_token(&conn, &token) .expect("couldn't find and delete request"); diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index ef86ca97..d76015ac 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -133,8 +133,7 @@ impl Post { .filter(posts::id.eq_any(ids)) .filter(posts::published.eq(true)) .count() - .load(conn)? - .get(0) + .load(conn)?.first() .cloned() .ok_or(Error::NotFound) } @@ -465,7 +464,7 @@ impl Post { .collect::>(); for (m, id) in &mentions { if !old_user_mentioned.contains(id) { - Mention::from_activity(&*conn, m, self.id, true, true)?; + Mention::from_activity(conn, m, self.id, true, true)?; } } @@ -488,7 +487,7 @@ impl Post { .filter_map(|t| t.name.as_ref().map(|name| name.as_str().to_string())) .collect::>(); - let old_tags = Tag::for_post(&*conn, self.id)?; + let old_tags = Tag::for_post(conn, self.id)?; let old_tags_name = old_tags .iter() .filter_map(|tag| { @@ -525,7 +524,7 @@ impl Post { .filter_map(|t| t.name.as_ref().map(|name| name.as_str().to_string())) .collect::>(); - let old_tags = Tag::for_post(&*conn, self.id)?; + let old_tags = Tag::for_post(conn, self.id)?; let old_tags_name = old_tags .iter() .filter_map(|tag| { @@ -1036,7 +1035,7 @@ mod tests { let post = &posts[0]; let mentioned = &users[1]; let mention = Mention::insert( - &conn, + conn, NewMention { mentioned_id: mentioned.id, post_id: Some(post.id), @@ -1044,7 +1043,7 @@ mod tests { }, ) .unwrap(); - (post.to_owned(), mention.to_owned(), posts, users, blogs) + (post.to_owned(), mention, posts, users, blogs) } // creates a post, get it's Create activity, delete the post, @@ -1053,9 +1052,9 @@ mod tests { fn self_federation() { let conn = &db(); conn.test_transaction::<_, (), _>(|| { - let (_, users, blogs) = fill_database(&conn); + let (_, users, blogs) = fill_database(conn); let post = Post::insert( - &conn, + conn, NewPost { blog_id: blogs[0].id, slug: "yo".into(), @@ -1072,19 +1071,19 @@ mod tests { ) .unwrap(); PostAuthor::insert( - &conn, + conn, NewPostAuthor { post_id: post.id, author_id: users[0].id, }, ) .unwrap(); - let create = post.create_activity(&conn).unwrap(); - post.delete(&conn).unwrap(); + let create = post.create_activity(conn).unwrap(); + post.delete(conn).unwrap(); - match inbox(&conn, serde_json::to_value(create).unwrap()).unwrap() { + match inbox(conn, serde_json::to_value(create).unwrap()).unwrap() { InboxResult::Post(p) => { - assert!(p.is_author(&conn, users[0].id).unwrap()); + assert!(p.is_author(conn, users[0].id).unwrap()); assert_eq!(p.source, "Hello".to_owned()); assert_eq!(p.blog_id, blogs[0].id); assert_eq!(p.content, SafeString::new("Hello")); @@ -1221,7 +1220,7 @@ mod tests { let actual = to_value(act)?; let id = actual["id"].to_string(); - let (id_pre, id_post) = id.rsplit_once("-").unwrap(); + let (id_pre, id_post) = id.rsplit_once('-').unwrap(); assert_eq!(post.ap_url, "https://plu.me/~/BlogName/testing"); assert_eq!( id_pre, diff --git a/plume-models/src/reshares.rs b/plume-models/src/reshares.rs index aec75796..67811da1 100644 --- a/plume-models/src/reshares.rs +++ b/plume-models/src/reshares.rs @@ -229,7 +229,7 @@ mod test { let (posts, _users, _blogs) = fill_database(&conn); let post = &posts[0]; let user = &post.get_authors(&conn)?[0]; - let reshare = Reshare::insert(&*conn, NewReshare::new(post, user))?; + let reshare = Reshare::insert(&conn, NewReshare::new(post, user))?; let act = reshare.to_activity(&conn).unwrap(); let expected = json!({ @@ -253,8 +253,8 @@ mod test { let (posts, _users, _blogs) = fill_database(&conn); let post = &posts[0]; let user = &post.get_authors(&conn)?[0]; - let reshare = Reshare::insert(&*conn, NewReshare::new(post, user))?; - let act = reshare.build_undo(&*conn)?; + let reshare = Reshare::insert(&conn, NewReshare::new(post, user))?; + let act = reshare.build_undo(&conn)?; let expected = json!({ "actor": "https://plu.me/@/admin/", diff --git a/plume-models/src/safe_string.rs b/plume-models/src/safe_string.rs index fedcdd70..7560aa43 100644 --- a/plume-models/src/safe_string.rs +++ b/plume-models/src/safe_string.rs @@ -93,7 +93,7 @@ fn url_add_prefix(url: &str) -> Option> { } } -#[derive(Debug, Clone, PartialEq, AsExpression, FromSqlRow, Default)] +#[derive(Debug, Clone, PartialEq, Eq, AsExpression, FromSqlRow, Default)] #[sql_type = "Text"] pub struct SafeString { value: String, diff --git a/plume-models/src/search/actor.rs b/plume-models/src/search/actor.rs index d97718e0..0b8afcfb 100644 --- a/plume-models/src/search/actor.rs +++ b/plume-models/src/search/actor.rs @@ -108,7 +108,7 @@ mod tests { let searcher = Arc::new(get_searcher(&CONFIG.search_tokenizers)); SearchActor::init(searcher.clone(), db_pool.clone()); - let conn = db_pool.clone().get().unwrap(); + let conn = db_pool.get().unwrap(); let title = random_hex()[..8].to_owned(); let (_instance, _user, blog) = fill_database(&conn); @@ -161,41 +161,43 @@ mod tests { long_description_html: "

Good morning

".to_string(), short_description: SafeString::new("Hello"), short_description_html: "

Hello

".to_string(), - name: random_hex().to_string(), + name: random_hex(), open_registrations: true, - public_domain: random_hex().to_string(), + public_domain: random_hex(), }, ) .unwrap(); let user = User::insert( conn, NewUser { - username: random_hex().to_string(), - display_name: random_hex().to_string(), - outbox_url: random_hex().to_string(), - inbox_url: random_hex().to_string(), + username: random_hex(), + display_name: random_hex(), + outbox_url: random_hex(), + inbox_url: random_hex(), summary: "".to_string(), email: None, hashed_password: None, instance_id: instance.id, - ap_url: random_hex().to_string(), + ap_url: random_hex(), private_key: None, public_key: "".to_string(), shared_inbox_url: None, - followers_endpoint: random_hex().to_string(), + followers_endpoint: random_hex(), avatar_id: None, summary_html: SafeString::new(""), role: 0, - fqn: random_hex().to_string(), + fqn: random_hex(), }, ) .unwrap(); - let mut blog = NewBlog::default(); - blog.instance_id = instance.id; - blog.actor_id = random_hex().to_string(); - blog.ap_url = random_hex().to_string(); - blog.inbox_url = random_hex().to_string(); - blog.outbox_url = random_hex().to_string(); + let blog = NewBlog { + instance_id: instance.id, + actor_id: random_hex(), + ap_url: random_hex(), + inbox_url: random_hex(), + outbox_url: random_hex(), + ..Default::default() + }; let blog = Blog::insert(conn, blog).unwrap(); BlogAuthor::insert( conn, diff --git a/plume-models/src/search/mod.rs b/plume-models/src/search/mod.rs index 917f7778..2948ac36 100644 --- a/plume-models/src/search/mod.rs +++ b/plume-models/src/search/mod.rs @@ -154,7 +154,7 @@ pub(crate) mod tests { }, ) .unwrap(); - searcher.add_document(&conn, &post).unwrap(); + searcher.add_document(conn, &post).unwrap(); searcher.commit(); assert_eq!( searcher.search_document(conn, Query::from_str(&title).unwrap(), (0, 1))[0].id, diff --git a/plume-models/src/tags.rs b/plume-models/src/tags.rs index 681de5e1..2d5cb08c 100644 --- a/plume-models/src/tags.rs +++ b/plume-models/src/tags.rs @@ -92,7 +92,7 @@ mod tests { let (posts, _users, _blogs) = fill_database(conn); let post_id = posts[0].id; let mut ht = Hashtag::new(); - ht.set_href(ap_url(&format!("https://plu.me/tag/a_tag")).parse::()?); + ht.set_href(ap_url("https://plu.me/tag/a_tag").parse::()?); ht.set_name("a_tag".to_string()); let tag = Tag::from_activity(conn, &ht, post_id, true)?; diff --git a/plume-models/src/timeline/mod.rs b/plume-models/src/timeline/mod.rs index 2bc87021..a8881392 100644 --- a/plume-models/src/timeline/mod.rs +++ b/plume-models/src/timeline/mod.rs @@ -14,7 +14,7 @@ pub(crate) mod query; pub use self::query::Kind; use self::query::{QueryError, TimelineQuery}; -#[derive(Clone, Debug, PartialEq, Queryable, Identifiable, AsChangeset)] +#[derive(Clone, Debug, PartialEq, Eq, Queryable, Identifiable, AsChangeset)] #[table_name = "timeline_definition"] pub struct Timeline { pub id: i32, @@ -282,73 +282,73 @@ mod tests { fn test_timeline() { let conn = &db(); conn.test_transaction::<_, (), _>(|| { - let users = userTests::fill_database(&conn); + let users = userTests::fill_database(conn); let mut tl1_u1 = Timeline::new_for_user( - &conn, + conn, users[0].id, "my timeline".to_owned(), "all".to_owned(), ) .unwrap(); List::new( - &conn, + conn, "languages I speak", Some(&users[1]), ListType::Prefix, ) .unwrap(); let tl2_u1 = Timeline::new_for_user( - &conn, + conn, users[0].id, "another timeline".to_owned(), "followed".to_owned(), ) .unwrap(); let tl1_u2 = Timeline::new_for_user( - &conn, + conn, users[1].id, "english posts".to_owned(), "lang in \"languages I speak\"".to_owned(), ) .unwrap(); let tl1_instance = Timeline::new_for_instance( - &conn, + conn, "english posts".to_owned(), "license in [cc]".to_owned(), ) .unwrap(); - assert_eq!(tl1_u1, Timeline::get(&conn, tl1_u1.id).unwrap()); + assert_eq!(tl1_u1, Timeline::get(conn, tl1_u1.id).unwrap()); assert_eq!( tl2_u1, - Timeline::find_for_user_by_name(&conn, Some(users[0].id), "another timeline") + Timeline::find_for_user_by_name(conn, Some(users[0].id), "another timeline") .unwrap() ); assert_eq!( tl1_instance, - Timeline::find_for_user_by_name(&conn, None, "english posts").unwrap() + Timeline::find_for_user_by_name(conn, None, "english posts").unwrap() ); - let tl_u1 = Timeline::list_for_user(&conn, Some(users[0].id)).unwrap(); + let tl_u1 = Timeline::list_for_user(conn, Some(users[0].id)).unwrap(); assert_eq!(3, tl_u1.len()); // it is not 2 because there is a "Your feed" tl created for each user automatically - assert!(tl_u1.iter().fold(false, |res, tl| { res || *tl == tl1_u1 })); - assert!(tl_u1.iter().fold(false, |res, tl| { res || *tl == tl2_u1 })); + assert!(tl_u1.iter().any(|tl| *tl == tl1_u1)); + assert!(tl_u1.iter().any(|tl| *tl == tl2_u1)); - let tl_instance = Timeline::list_for_user(&conn, None).unwrap(); + let tl_instance = Timeline::list_for_user(conn, None).unwrap(); assert_eq!(3, tl_instance.len()); // there are also the local and federated feed by default assert!(tl_instance .iter() - .fold(false, |res, tl| { res || *tl == tl1_instance })); + .any(|tl| *tl == tl1_instance)); tl1_u1.name = "My Super TL".to_owned(); - let new_tl1_u2 = tl1_u2.update(&conn).unwrap(); + let new_tl1_u2 = tl1_u2.update(conn).unwrap(); - let tl_u2 = Timeline::list_for_user(&conn, Some(users[1].id)).unwrap(); + let tl_u2 = Timeline::list_for_user(conn, Some(users[1].id)).unwrap(); assert_eq!(2, tl_u2.len()); // same here assert!(tl_u2 .iter() - .fold(false, |res, tl| { res || *tl == new_tl1_u2 })); + .any(|tl| *tl == new_tl1_u2)); Ok(()) }); @@ -358,48 +358,48 @@ mod tests { fn test_timeline_creation_error() { let conn = &db(); conn.test_transaction::<_, (), _>(|| { - let users = userTests::fill_database(&conn); + let users = userTests::fill_database(conn); assert!(Timeline::new_for_user( - &conn, + conn, users[0].id, "my timeline".to_owned(), "invalid keyword".to_owned(), ) .is_err()); assert!(Timeline::new_for_instance( - &conn, + conn, "my timeline".to_owned(), "invalid keyword".to_owned(), ) .is_err()); assert!(Timeline::new_for_user( - &conn, + conn, users[0].id, "my timeline".to_owned(), "author in non_existant_list".to_owned(), ) .is_err()); assert!(Timeline::new_for_instance( - &conn, + conn, "my timeline".to_owned(), "lang in dont-exist".to_owned(), ) .is_err()); - List::new(&conn, "friends", Some(&users[0]), ListType::User).unwrap(); - List::new(&conn, "idk", None, ListType::Blog).unwrap(); + List::new(conn, "friends", Some(&users[0]), ListType::User).unwrap(); + List::new(conn, "idk", None, ListType::Blog).unwrap(); assert!(Timeline::new_for_user( - &conn, + conn, users[0].id, "my timeline".to_owned(), "blog in friends".to_owned(), ) .is_err()); assert!(Timeline::new_for_instance( - &conn, + conn, "my timeline".to_owned(), "not author in idk".to_owned(), ) @@ -413,10 +413,10 @@ mod tests { fn test_simple_match() { let conn = &db(); conn.test_transaction::<_, (), _>(|| { - let (users, blogs) = blogTests::fill_database(&conn); + let (users, blogs) = blogTests::fill_database(conn); let gnu_tl = Timeline::new_for_user( - &conn, + conn, users[0].id, "GNU timeline".to_owned(), "license in [AGPL, LGPL, GPL]".to_owned(), @@ -424,7 +424,7 @@ mod tests { .unwrap(); let gnu_post = Post::insert( - &conn, + conn, NewPost { blog_id: blogs[0].id, slug: "slug".to_string(), @@ -440,10 +440,10 @@ mod tests { }, ) .unwrap(); - assert!(gnu_tl.matches(&conn, &gnu_post, Kind::Original).unwrap()); + assert!(gnu_tl.matches(conn, &gnu_post, Kind::Original).unwrap()); let non_free_post = Post::insert( - &conn, + conn, NewPost { blog_id: blogs[0].id, slug: "slug2".to_string(), @@ -460,7 +460,7 @@ mod tests { ) .unwrap(); assert!(!gnu_tl - .matches(&conn, &non_free_post, Kind::Original) + .matches(conn, &non_free_post, Kind::Original) .unwrap()); Ok(()) @@ -471,9 +471,9 @@ mod tests { fn test_complex_match() { let conn = &db(); conn.test_transaction::<_, (), _>(|| { - let (users, blogs) = blogTests::fill_database(&conn); + let (users, blogs) = blogTests::fill_database(conn); Follow::insert( - &conn, + conn, NewFollow { follower_id: users[0].id, following_id: users[1].id, @@ -483,11 +483,11 @@ mod tests { .unwrap(); let fav_blogs_list = - List::new(&conn, "fav_blogs", Some(&users[0]), ListType::Blog).unwrap(); - fav_blogs_list.add_blogs(&conn, &[blogs[0].id]).unwrap(); + List::new(conn, "fav_blogs", Some(&users[0]), ListType::Blog).unwrap(); + fav_blogs_list.add_blogs(conn, &[blogs[0].id]).unwrap(); let my_tl = Timeline::new_for_user( - &conn, + conn, users[0].id, "My timeline".to_owned(), "blog in fav_blogs and not has_cover or local and followed exclude likes" @@ -496,7 +496,7 @@ mod tests { .unwrap(); let post = Post::insert( - &conn, + conn, NewPost { blog_id: blogs[0].id, slug: "about-linux".to_string(), @@ -512,10 +512,10 @@ mod tests { }, ) .unwrap(); - assert!(my_tl.matches(&conn, &post, Kind::Original).unwrap()); // matches because of "blog in fav_blogs" (and there is no cover) + assert!(my_tl.matches(conn, &post, Kind::Original).unwrap()); // matches because of "blog in fav_blogs" (and there is no cover) let post = Post::insert( - &conn, + conn, NewPost { blog_id: blogs[1].id, slug: "about-linux-2".to_string(), @@ -533,7 +533,7 @@ mod tests { }, ) .unwrap(); - assert!(!my_tl.matches(&conn, &post, Kind::Like(&users[1])).unwrap()); + assert!(!my_tl.matches(conn, &post, Kind::Like(&users[1])).unwrap()); Ok(()) }); @@ -543,17 +543,17 @@ mod tests { fn test_add_to_all_timelines() { let conn = &db(); conn.test_transaction::<_, (), _>(|| { - let (users, blogs) = blogTests::fill_database(&conn); + let (users, blogs) = blogTests::fill_database(conn); let gnu_tl = Timeline::new_for_user( - &conn, + conn, users[0].id, "GNU timeline".to_owned(), "license in [AGPL, LGPL, GPL]".to_owned(), ) .unwrap(); let non_gnu_tl = Timeline::new_for_user( - &conn, + conn, users[0].id, "Stallman disapproved timeline".to_owned(), "not license in [AGPL, LGPL, GPL]".to_owned(), @@ -561,7 +561,7 @@ mod tests { .unwrap(); let gnu_post = Post::insert( - &conn, + conn, NewPost { blog_id: blogs[0].id, slug: "slug".to_string(), @@ -579,7 +579,7 @@ mod tests { .unwrap(); let non_free_post = Post::insert( - &conn, + conn, NewPost { blog_id: blogs[0].id, slug: "slug2".to_string(), @@ -596,13 +596,13 @@ mod tests { ) .unwrap(); - Timeline::add_to_all_timelines(&conn, &gnu_post, Kind::Original).unwrap(); - Timeline::add_to_all_timelines(&conn, &non_free_post, Kind::Original).unwrap(); + Timeline::add_to_all_timelines(conn, &gnu_post, Kind::Original).unwrap(); + Timeline::add_to_all_timelines(conn, &non_free_post, Kind::Original).unwrap(); - let res = gnu_tl.get_latest(&conn, 2).unwrap(); + let res = gnu_tl.get_latest(conn, 2).unwrap(); assert_eq!(res.len(), 1); assert_eq!(res[0].id, gnu_post.id); - let res = non_gnu_tl.get_latest(&conn, 2).unwrap(); + let res = non_gnu_tl.get_latest(conn, 2).unwrap(); assert_eq!(res.len(), 1); assert_eq!(res[0].id, non_free_post.id); @@ -614,10 +614,10 @@ mod tests { fn test_matches_lists_direct() { let conn = &db(); conn.test_transaction::<_, (), _>(|| { - let (users, blogs) = blogTests::fill_database(&conn); + let (users, blogs) = blogTests::fill_database(conn); let gnu_post = Post::insert( - &conn, + conn, NewPost { blog_id: blogs[0].id, slug: "slug".to_string(), @@ -634,63 +634,63 @@ mod tests { ) .unwrap(); gnu_post - .update_tags(&conn, vec![Tag::build_activity("free".to_owned()).unwrap()]) + .update_tags(conn, vec![Tag::build_activity("free".to_owned()).unwrap()]) .unwrap(); PostAuthor::insert( - &conn, + conn, NewPostAuthor { post_id: gnu_post.id, - author_id: blogs[0].list_authors(&conn).unwrap()[0].id, + author_id: blogs[0].list_authors(conn).unwrap()[0].id, }, ) .unwrap(); let tl = Timeline::new_for_user( - &conn, + conn, users[0].id, "blog timeline".to_owned(), format!("blog in [{}]", blogs[0].fqn), ) .unwrap(); - assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap()); - tl.delete(&conn).unwrap(); + assert!(tl.matches(conn, &gnu_post, Kind::Original).unwrap()); + tl.delete(conn).unwrap(); let tl = Timeline::new_for_user( - &conn, + conn, users[0].id, "blog timeline".to_owned(), "blog in [no_one@nowhere]".to_owned(), ) .unwrap(); - assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap()); - tl.delete(&conn).unwrap(); + assert!(!tl.matches(conn, &gnu_post, Kind::Original).unwrap()); + tl.delete(conn).unwrap(); let tl = Timeline::new_for_user( - &conn, + conn, users[0].id, "author timeline".to_owned(), format!( "author in [{}]", - blogs[0].list_authors(&conn).unwrap()[0].fqn + blogs[0].list_authors(conn).unwrap()[0].fqn ), ) .unwrap(); - assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap()); - tl.delete(&conn).unwrap(); + assert!(tl.matches(conn, &gnu_post, Kind::Original).unwrap()); + tl.delete(conn).unwrap(); let tl = Timeline::new_for_user( - &conn, + conn, users[0].id, "author timeline".to_owned(), format!("author in [{}]", users[2].fqn), ) .unwrap(); - assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap()); + assert!(!tl.matches(conn, &gnu_post, Kind::Original).unwrap()); assert!(tl - .matches(&conn, &gnu_post, Kind::Reshare(&users[2])) + .matches(conn, &gnu_post, Kind::Reshare(&users[2])) .unwrap()); - assert!(!tl.matches(&conn, &gnu_post, Kind::Like(&users[2])).unwrap()); - tl.delete(&conn).unwrap(); + assert!(!tl.matches(conn, &gnu_post, Kind::Like(&users[2])).unwrap()); + tl.delete(conn).unwrap(); let tl = Timeline::new_for_user( - &conn, + conn, users[0].id, "author timeline".to_owned(), format!( @@ -699,50 +699,50 @@ mod tests { ), ) .unwrap(); - assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap()); + assert!(!tl.matches(conn, &gnu_post, Kind::Original).unwrap()); assert!(!tl - .matches(&conn, &gnu_post, Kind::Reshare(&users[2])) + .matches(conn, &gnu_post, Kind::Reshare(&users[2])) .unwrap()); - assert!(tl.matches(&conn, &gnu_post, Kind::Like(&users[2])).unwrap()); - tl.delete(&conn).unwrap(); + assert!(tl.matches(conn, &gnu_post, Kind::Like(&users[2])).unwrap()); + tl.delete(conn).unwrap(); let tl = Timeline::new_for_user( - &conn, + conn, users[0].id, "tag timeline".to_owned(), "tags in [free]".to_owned(), ) .unwrap(); - assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap()); - tl.delete(&conn).unwrap(); + assert!(tl.matches(conn, &gnu_post, Kind::Original).unwrap()); + tl.delete(conn).unwrap(); let tl = Timeline::new_for_user( - &conn, + conn, users[0].id, "tag timeline".to_owned(), "tags in [private]".to_owned(), ) .unwrap(); - assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap()); - tl.delete(&conn).unwrap(); + assert!(!tl.matches(conn, &gnu_post, Kind::Original).unwrap()); + tl.delete(conn).unwrap(); let tl = Timeline::new_for_user( - &conn, + conn, users[0].id, "english timeline".to_owned(), "lang in [en]".to_owned(), ) .unwrap(); - assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap()); - tl.delete(&conn).unwrap(); + assert!(tl.matches(conn, &gnu_post, Kind::Original).unwrap()); + tl.delete(conn).unwrap(); let tl = Timeline::new_for_user( - &conn, + conn, users[0].id, "franco-italian timeline".to_owned(), "lang in [fr, it]".to_owned(), ) .unwrap(); - assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap()); - tl.delete(&conn).unwrap(); + assert!(!tl.matches(conn, &gnu_post, Kind::Original).unwrap()); + tl.delete(conn).unwrap(); Ok(()) }); @@ -786,10 +786,10 @@ mod tests { fn test_matches_keyword() { let conn = &db(); conn.test_transaction::<_, (), _>(|| { - let (users, blogs) = blogTests::fill_database(&conn); + let (users, blogs) = blogTests::fill_database(conn); let gnu_post = Post::insert( - &conn, + conn, NewPost { blog_id: blogs[0].id, slug: "slug".to_string(), @@ -807,61 +807,61 @@ mod tests { .unwrap(); let tl = Timeline::new_for_user( - &conn, + conn, users[0].id, "Linux title".to_owned(), "title contains Linux".to_owned(), ) .unwrap(); - assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap()); - tl.delete(&conn).unwrap(); + assert!(tl.matches(conn, &gnu_post, Kind::Original).unwrap()); + tl.delete(conn).unwrap(); let tl = Timeline::new_for_user( - &conn, + conn, users[0].id, "Microsoft title".to_owned(), "title contains Microsoft".to_owned(), ) .unwrap(); - assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap()); - tl.delete(&conn).unwrap(); + assert!(!tl.matches(conn, &gnu_post, Kind::Original).unwrap()); + tl.delete(conn).unwrap(); let tl = Timeline::new_for_user( - &conn, + conn, users[0].id, "Linux subtitle".to_owned(), "subtitle contains Stallman".to_owned(), ) .unwrap(); - assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap()); - tl.delete(&conn).unwrap(); + assert!(tl.matches(conn, &gnu_post, Kind::Original).unwrap()); + tl.delete(conn).unwrap(); let tl = Timeline::new_for_user( - &conn, + conn, users[0].id, "Microsoft subtitle".to_owned(), "subtitle contains Nadella".to_owned(), ) .unwrap(); - assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap()); - tl.delete(&conn).unwrap(); + assert!(!tl.matches(conn, &gnu_post, Kind::Original).unwrap()); + tl.delete(conn).unwrap(); let tl = Timeline::new_for_user( - &conn, + conn, users[0].id, "Linux content".to_owned(), "content contains Linux".to_owned(), ) .unwrap(); - assert!(tl.matches(&conn, &gnu_post, Kind::Original).unwrap()); - tl.delete(&conn).unwrap(); + assert!(tl.matches(conn, &gnu_post, Kind::Original).unwrap()); + tl.delete(conn).unwrap(); let tl = Timeline::new_for_user( - &conn, + conn, users[0].id, "Microsoft content".to_owned(), "subtitle contains Windows".to_owned(), ) .unwrap(); - assert!(!tl.matches(&conn, &gnu_post, Kind::Original).unwrap()); - tl.delete(&conn).unwrap(); + assert!(!tl.matches(conn, &gnu_post, Kind::Original).unwrap()); + tl.delete(conn).unwrap(); Ok(()) }); diff --git a/plume-models/src/timeline/query.rs b/plume-models/src/timeline/query.rs index 00509440..0981d1a2 100644 --- a/plume-models/src/timeline/query.rs +++ b/plume-models/src/timeline/query.rs @@ -11,7 +11,7 @@ use crate::{ use plume_common::activity_pub::inbox::AsActor; use whatlang::{self, Lang}; -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum QueryError { SyntaxError(usize, usize, String), UnexpectedEndOfQuery, @@ -20,7 +20,7 @@ pub enum QueryError { pub type QueryResult = std::result::Result; -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Kind<'a> { Original, Reshare(&'a User), @@ -292,7 +292,7 @@ impl WithList { WithList::Author { boosts, likes } => match kind { Kind::Original => Ok(list .iter() - .filter_map(|a| User::find_by_fqn(&*conn, a).ok()) + .filter_map(|a| User::find_by_fqn(conn, a).ok()) .any(|a| post.is_author(conn, a.id).unwrap_or(false))), Kind::Reshare(u) => { if *boosts { diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index b33f9bc1..0314bf0b 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -187,7 +187,7 @@ impl User { users::table .filter(users::instance_id.eq(Instance::get_local()?.id)) .count() - .get_result(&*conn) + .get_result(conn) .map_err(Error::from) } @@ -435,7 +435,7 @@ impl User { } // if no user was found, and we were unable to auto-register from ldap // fake-verify a password, and return an error. - let other = User::get(&*conn, 1) + let other = User::get(conn, 1) .expect("No user is registered") .hashed_password; other.map(|pass| bcrypt::verify(password, &pass)); @@ -931,7 +931,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for User { .cookies() .get_private(AUTH_COOKIE) .and_then(|cookie| cookie.value().parse().ok()) - .and_then(|id| User::get(&*conn, id).ok()) + .and_then(|id| User::get(&conn, id).ok()) .or_forward(()) } } @@ -1232,7 +1232,7 @@ pub(crate) mod tests { ) .unwrap(); other.avatar_id = Some(avatar.id); - let other = other.save_changes::(&*conn).unwrap(); + let other = other.save_changes::(conn).unwrap(); vec![admin, user, other] } @@ -1335,11 +1335,11 @@ pub(crate) mod tests { fn delete() { let conn = &db(); conn.test_transaction::<_, (), _>(|| { - let inserted = fill_database(&conn); + let inserted = fill_database(conn); - assert!(User::get(&conn, inserted[0].id).is_ok()); - inserted[0].delete(&conn).unwrap(); - assert!(User::get(&conn, inserted[0].id).is_err()); + assert!(User::get(conn, inserted[0].id).is_ok()); + inserted[0].delete(conn).unwrap(); + assert!(User::get(conn, inserted[0].id).is_err()); Ok(()) }); } @@ -1348,20 +1348,20 @@ pub(crate) mod tests { fn admin() { let conn = &db(); conn.test_transaction::<_, (), _>(|| { - let inserted = fill_database(&conn); + let inserted = fill_database(conn); let local_inst = Instance::get_local().unwrap(); let mut i = 0; - while local_inst.has_admin(&conn).unwrap() { + while local_inst.has_admin(conn).unwrap() { assert!(i < 100); //prevent from looping indefinitelly local_inst - .main_admin(&conn) + .main_admin(conn) .unwrap() - .set_role(&conn, Role::Normal) + .set_role(conn, Role::Normal) .unwrap(); i += 1; } - inserted[0].set_role(&conn, Role::Admin).unwrap(); - assert_eq!(inserted[0].id, local_inst.main_admin(&conn).unwrap().id); + inserted[0].set_role(conn, Role::Admin).unwrap(); + assert_eq!(inserted[0].id, local_inst.main_admin(conn).unwrap().id); Ok(()) }); } @@ -1370,9 +1370,9 @@ pub(crate) mod tests { fn auth() { let conn = &db(); conn.test_transaction::<_, (), _>(|| { - fill_database(&conn); + fill_database(conn); let test_user = NewUser::new_local( - &conn, + conn, "test".to_owned(), "test user".to_owned(), Role::Normal, @@ -1383,10 +1383,10 @@ pub(crate) mod tests { .unwrap(); assert_eq!( - User::login(&conn, "test", "test_password").unwrap().id, + User::login(conn, "test", "test_password").unwrap().id, test_user.id ); - assert!(User::login(&conn, "test", "other_password").is_err()); + assert!(User::login(conn, "test", "other_password").is_err()); Ok(()) }); } @@ -1395,26 +1395,26 @@ pub(crate) mod tests { fn get_local_page() { let conn = &db(); conn.test_transaction::<_, (), _>(|| { - fill_database(&conn); + fill_database(conn); - let page = User::get_local_page(&conn, (0, 2)).unwrap(); + let page = User::get_local_page(conn, (0, 2)).unwrap(); assert_eq!(page.len(), 2); assert!(page[0].username <= page[1].username); - let mut last_username = User::get_local_page(&conn, (0, 1)).unwrap()[0] + let mut last_username = User::get_local_page(conn, (0, 1)).unwrap()[0] .username .clone(); - for i in 1..User::count_local(&conn).unwrap() as i32 { - let page = User::get_local_page(&conn, (i, i + 1)).unwrap(); + for i in 1..User::count_local(conn).unwrap() as i32 { + let page = User::get_local_page(conn, (i, i + 1)).unwrap(); assert_eq!(page.len(), 1); assert!(last_username <= page[0].username); last_username = page[0].username.clone(); } assert_eq!( - User::get_local_page(&conn, (0, User::count_local(&conn).unwrap() as i32 + 10)) + User::get_local_page(conn, (0, User::count_local(conn).unwrap() as i32 + 10)) .unwrap() .len() as i64, - User::count_local(&conn).unwrap() + User::count_local(conn).unwrap() ); Ok(()) }); diff --git a/rust-toolchain b/rust-toolchain index 63af764b..b57117c9 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2022-01-27 +nightly-2022-07-19 diff --git a/src/api/apps.rs b/src/api/apps.rs index 7bbc2d7a..b3fa280d 100644 --- a/src/api/apps.rs +++ b/src/api/apps.rs @@ -10,7 +10,7 @@ pub fn create(conn: DbConn, data: Json) -> Api { let client_id = random_hex(); let client_secret = random_hex(); let app = App::insert( - &*conn, + &conn, NewApp { name: data.name.clone(), client_id, diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index b8f28959..bff25d01 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -160,7 +160,7 @@ pub fn delete(name: String, conn: DbConn, rockets: PlumeRocket) -> RespondOrRedi .and_then(|u| u.is_author_in(&conn, &blog).ok()) .unwrap_or(false) { - blog.delete(&*conn).expect("blog::expect: deletion error"); + blog.delete(&conn).expect("blog::expect: deletion error"); Flash::success( Redirect::to(uri!(super::instance::index)), i18n!(rockets.intl.catalog, "Your blog was deleted."), @@ -364,7 +364,7 @@ pub fn outbox_page( #[get("/~//atom.xml")] pub fn atom_feed(name: String, conn: DbConn) -> Option> { let blog = Blog::find_by_fqn(&conn, &name).ok()?; - let entries = Post::get_recents_for_blog(&*conn, &blog, 15).ok()?; + let entries = Post::get_recents_for_blog(&conn, &blog, 15).ok()?; let uri = Instance::get_local() .ok()? .compute_box("~", &name, "atom.xml"); @@ -454,9 +454,9 @@ mod tests { long_description_html: "

Good morning

".to_string(), short_description: SafeString::new("Hello"), short_description_html: "

Hello

".to_string(), - name: random_hex().to_string(), + name: random_hex(), open_registrations: true, - public_domain: random_hex().to_string(), + public_domain: random_hex(), }, ) .unwrap(); @@ -465,18 +465,18 @@ mod tests { }); let mut user = NewUser::default(); user.instance_id = instance.id; - user.username = random_hex().to_string(); - user.ap_url = random_hex().to_string(); - user.inbox_url = random_hex().to_string(); - user.outbox_url = random_hex().to_string(); - user.followers_endpoint = random_hex().to_string(); + user.username = random_hex(); + user.ap_url = random_hex(); + user.inbox_url = random_hex(); + user.outbox_url = random_hex(); + user.followers_endpoint = random_hex(); let user = User::insert(conn, user).unwrap(); let mut blog = NewBlog::default(); blog.instance_id = instance.id; - blog.actor_id = random_hex().to_string(); - blog.ap_url = random_hex().to_string(); - blog.inbox_url = random_hex().to_string(); - blog.outbox_url = random_hex().to_string(); + blog.actor_id = random_hex(); + blog.ap_url = random_hex(); + blog.inbox_url = random_hex(); + blog.outbox_url = random_hex(); let blog = Blog::insert(conn, blog).unwrap(); BlogAuthor::insert( conn, diff --git a/src/routes/comments.rs b/src/routes/comments.rs index 5f60aae3..c60382be 100644 --- a/src/routes/comments.rs +++ b/src/routes/comments.rs @@ -125,7 +125,7 @@ pub fn create( user.has_reshared(&conn, &post) .expect("comments::create: reshared error"), user.is_following( - &*conn, + &conn, post.get_authors(&conn) .expect("comments::create: authors error")[0] .id diff --git a/src/routes/instance.rs b/src/routes/instance.rs index 526bde31..b4ac399b 100644 --- a/src/routes/instance.rs +++ b/src/routes/instance.rs @@ -105,7 +105,7 @@ pub fn update_settings( Instance::get_local().expect("instance::update_settings: local instance error"); instance .update( - &*conn, + &conn, form.name.clone(), form.open_registrations, form.short_description.clone(), @@ -366,8 +366,8 @@ pub fn edit_users( } fn ban(id: i32, conn: &Connection, worker: &ScheduledThreadPool) -> Result<(), ErrorPage> { - let u = User::get(&*conn, id)?; - u.delete(&*conn)?; + let u = User::get(conn, id)?; + u.delete(conn)?; if Instance::get_local() .map(|i| u.instance_id == i.id) .unwrap_or(false) @@ -382,8 +382,8 @@ fn ban(id: i32, conn: &Connection, worker: &ScheduledThreadPool) -> Result<(), E }, ) .unwrap(); - let target = User::one_by_instance(&*conn)?; - let delete_act = u.delete_activity(&*conn)?; + let target = User::one_by_instance(conn)?; + let delete_act = u.delete_activity(conn)?; worker.execute(move || broadcast(&u, delete_act, target, CONFIG.proxy().cloned())); } diff --git a/src/routes/likes.rs b/src/routes/likes.rs index 25ca68bf..687b23a8 100644 --- a/src/routes/likes.rs +++ b/src/routes/likes.rs @@ -20,14 +20,14 @@ pub fn create( let b = Blog::find_by_fqn(&conn, &blog)?; let post = Post::find_by_slug(&conn, &slug, b.id)?; - if !user.has_liked(&*conn, &post)? { - let like = likes::Like::insert(&*conn, likes::NewLike::new(&post, &user))?; - like.notify(&*conn)?; + if !user.has_liked(&conn, &post)? { + let like = likes::Like::insert(&conn, likes::NewLike::new(&post, &user))?; + like.notify(&conn)?; Timeline::add_to_all_timelines(&conn, &post, Kind::Like(&user))?; - let dest = User::one_by_instance(&*conn)?; - let act = like.to_activity(&*conn)?; + let dest = User::one_by_instance(&conn)?; + let act = like.to_activity(&conn)?; rockets .worker .execute(move || broadcast(&user, act, dest, CONFIG.proxy().cloned())); diff --git a/src/routes/medias.rs b/src/routes/medias.rs index 8f920036..1981c542 100644 --- a/src/routes/medias.rs +++ b/src/routes/medias.rs @@ -145,9 +145,9 @@ pub fn details( #[post("/medias//delete")] pub fn delete(id: i32, user: User, conn: DbConn, intl: I18n) -> Result, ErrorPage> { - let media = Media::get(&*conn, id)?; + let media = Media::get(&conn, id)?; if media.owner_id == user.id { - media.delete(&*conn)?; + media.delete(&conn)?; Ok(Flash::success( Redirect::to(uri!(list: page = _)), i18n!(intl.catalog, "Your media have been deleted."), @@ -167,9 +167,9 @@ pub fn set_avatar( conn: DbConn, intl: I18n, ) -> Result, ErrorPage> { - let media = Media::get(&*conn, id)?; + let media = Media::get(&conn, id)?; if media.owner_id == user.id { - user.set_avatar(&*conn, media.id)?; + user.set_avatar(&conn, media.id)?; Ok(Flash::success( Redirect::to(uri!(details: id = id)), i18n!(intl.catalog, "Your avatar has been updated."), diff --git a/src/routes/mod.rs b/src/routes/mod.rs index 5ea53c96..58d71aa6 100644 --- a/src/routes/mod.rs +++ b/src/routes/mod.rs @@ -165,7 +165,7 @@ fn post_to_atom(post: Post, conn: &Connection) -> Entry { .build(), ) .authors( - post.get_authors(&*conn) + post.get_authors(conn) .expect("Atom feed: author error") .into_iter() .map(|a| { diff --git a/src/routes/user.rs b/src/routes/user.rs index e1b1cfdd..c71be6e2 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -48,10 +48,10 @@ pub fn me(user: Option) -> RespondOrRedirect { #[get("/@/", rank = 2)] pub fn details(name: String, rockets: PlumeRocket, conn: DbConn) -> Result { let user = User::find_by_fqn(&conn, &name)?; - let recents = Post::get_recents_for_author(&*conn, &user, 6)?; - let reshares = Reshare::get_recents_for_author(&*conn, &user, 6)?; + let recents = Post::get_recents_for_author(&conn, &user, 6)?; + let reshares = Reshare::get_recents_for_author(&conn, &user, 6)?; - if !user.get_instance(&*conn)?.local { + if !user.get_instance(&conn)?.local { tracing::trace!("remote user found"); user.remote_user_found(); // Doesn't block } @@ -62,14 +62,14 @@ pub fn details(name: String, rockets: PlumeRocket, conn: DbConn) -> Result for WebfingerResolver { fn find(prefix: Prefix, acct: String, conn: DbConn) -> Result { match prefix { Prefix::Acct => User::find_by_fqn(&conn, &acct) - .and_then(|usr| usr.webfinger(&*conn)) + .and_then(|usr| usr.webfinger(&conn)) .or(Err(ResolverError::NotFound)), Prefix::Group => Blog::find_by_fqn(&conn, &acct) - .and_then(|blog| blog.webfinger(&*conn)) + .and_then(|blog| blog.webfinger(&conn)) .or(Err(ResolverError::NotFound)), Prefix::Custom(_) => Err(ResolverError::NotFound), } diff --git a/src/template_utils.rs b/src/template_utils.rs index 1dfcc56d..9d4095b0 100644 --- a/src/template_utils.rs +++ b/src/template_utils.rs @@ -85,7 +85,7 @@ impl<'r> Responder<'r> for Ructe { macro_rules! render { ($group:tt :: $page:tt ( $( $param:expr ),* ) ) => { { - use crate::templates; + use $crate::templates; let mut res = vec![]; templates::$group::$page(