Run cargo clippy on whole project (#322)
* Run cargo clippy on plume-common Run clippy on plume-common and adjuste code accordingly * Run cargo clippy on plume-model Run clippy on plume-model and adjuste code accordingly * Reduce need for allocation in plume-common * Reduce need for allocation in plume-model add a quick compilation failure if no database backend is enabled * Run cargo clippy on plume-cli * Run cargo clippy on plume
This commit is contained in:
+14
-14
@@ -24,7 +24,7 @@ use routes::Page;
|
||||
|
||||
#[get("/~/<name>?<page>", rank = 2)]
|
||||
fn paginated_details(name: String, conn: DbConn, user: Option<User>, page: Page) -> Template {
|
||||
may_fail!(user.map(|u| u.to_json(&*conn)), Blog::find_by_fqn(&*conn, name), "Requested blog couldn't be found", |blog| {
|
||||
may_fail!(user.map(|u| u.to_json(&*conn)), Blog::find_by_fqn(&*conn, &name), "Requested blog couldn't be found", |blog| {
|
||||
let posts = Post::blog_page(&*conn, &blog, page.limits());
|
||||
let articles = Post::get_for_blog(&*conn, &blog);
|
||||
let authors = &blog.list_authors(&*conn);
|
||||
@@ -32,7 +32,7 @@ fn paginated_details(name: String, conn: DbConn, user: Option<User>, page: Page)
|
||||
Template::render("blogs/details", json!({
|
||||
"blog": &blog.to_json(&*conn),
|
||||
"account": user.clone().map(|u| u.to_json(&*conn)),
|
||||
"is_author": user.map(|x| x.is_author_in(&*conn, blog.clone())),
|
||||
"is_author": user.map(|x| x.is_author_in(&*conn, &blog)),
|
||||
"posts": posts.into_iter().map(|p| p.to_json(&*conn)).collect::<Vec<serde_json::Value>>(),
|
||||
"authors": authors.into_iter().map(|u| u.to_json(&*conn)).collect::<Vec<serde_json::Value>>(),
|
||||
"n_authors": authors.len(),
|
||||
@@ -50,8 +50,8 @@ fn details(name: String, conn: DbConn, user: Option<User>) -> Template {
|
||||
|
||||
#[get("/~/<name>", rank = 1)]
|
||||
fn activity_details(name: String, conn: DbConn, _ap: ApRequest) -> Option<ActivityStream<CustomGroup>> {
|
||||
let blog = Blog::find_local(&*conn, name)?;
|
||||
Some(ActivityStream::new(blog.into_activity(&*conn)))
|
||||
let blog = Blog::find_local(&*conn, &name)?;
|
||||
Some(ActivityStream::new(blog.to_activity(&*conn)))
|
||||
}
|
||||
|
||||
#[get("/blogs/new")]
|
||||
@@ -67,7 +67,7 @@ fn new(user: User, conn: DbConn) -> Template {
|
||||
fn new_auth() -> Flash<Redirect>{
|
||||
utils::requires_login(
|
||||
"You need to be logged in order to create a new blog",
|
||||
uri!(new).into()
|
||||
uri!(new)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -78,8 +78,8 @@ struct NewBlogForm {
|
||||
}
|
||||
|
||||
fn valid_slug(title: &str) -> Result<(), ValidationError> {
|
||||
let slug = utils::make_actor_id(title.to_string());
|
||||
if slug.len() == 0 {
|
||||
let slug = utils::make_actor_id(title);
|
||||
if slug.is_empty() {
|
||||
Err(ValidationError::new("empty_slug"))
|
||||
} else {
|
||||
Ok(())
|
||||
@@ -89,13 +89,13 @@ fn valid_slug(title: &str) -> Result<(), ValidationError> {
|
||||
#[post("/blogs/new", data = "<data>")]
|
||||
fn create(conn: DbConn, data: LenientForm<NewBlogForm>, user: User) -> Result<Redirect, Template> {
|
||||
let form = data.get();
|
||||
let slug = utils::make_actor_id(form.title.to_string());
|
||||
let slug = utils::make_actor_id(&form.title);
|
||||
|
||||
let mut errors = match form.validate() {
|
||||
Ok(_) => ValidationErrors::new(),
|
||||
Err(e) => e
|
||||
};
|
||||
if let Some(_) = Blog::find_local(&*conn, slug.clone()) {
|
||||
if Blog::find_local(&*conn, &slug).is_some() {
|
||||
errors.add("title", ValidationError {
|
||||
code: Cow::from("existing_slug"),
|
||||
message: Some(Cow::from("A blog with the same name already exists.")),
|
||||
@@ -131,8 +131,8 @@ fn create(conn: DbConn, data: LenientForm<NewBlogForm>, user: User) -> Result<Re
|
||||
|
||||
#[post("/~/<name>/delete")]
|
||||
fn delete(conn: DbConn, name: String, user: Option<User>) -> Result<Redirect, Option<Template>>{
|
||||
let blog = Blog::find_local(&*conn, name).ok_or(None)?;
|
||||
if user.map(|u| u.is_author_in(&*conn, blog.clone())).unwrap_or(false) {
|
||||
let blog = Blog::find_local(&*conn, &name).ok_or(None)?;
|
||||
if user.map(|u| u.is_author_in(&*conn, &blog)).unwrap_or(false) {
|
||||
blog.delete(&conn);
|
||||
Ok(Redirect::to(uri!(super::instance::index)))
|
||||
} else {
|
||||
@@ -144,17 +144,17 @@ fn delete(conn: DbConn, name: String, user: Option<User>) -> Result<Redirect, Op
|
||||
|
||||
#[get("/~/<name>/outbox")]
|
||||
fn outbox(name: String, conn: DbConn) -> Option<ActivityStream<OrderedCollection>> {
|
||||
let blog = Blog::find_local(&*conn, name)?;
|
||||
let blog = Blog::find_local(&*conn, &name)?;
|
||||
Some(blog.outbox(&*conn))
|
||||
}
|
||||
|
||||
#[get("/~/<name>/atom.xml")]
|
||||
fn atom_feed(name: String, conn: DbConn) -> Option<Content<String>> {
|
||||
let blog = Blog::find_by_fqn(&*conn, name.clone())?;
|
||||
let blog = Blog::find_by_fqn(&*conn, &name)?;
|
||||
let feed = FeedBuilder::default()
|
||||
.title(blog.title.clone())
|
||||
.id(Instance::get_local(&*conn).expect("blogs::atom_feed: local instance not found error")
|
||||
.compute_box("~", name, "atom.xml"))
|
||||
.compute_box("~", &name, "atom.xml"))
|
||||
.entries(Post::get_recents_for_blog(&*conn, &blog, 15)
|
||||
.into_iter()
|
||||
.map(|p| super::post_to_atom(p, &*conn))
|
||||
|
||||
Reference in New Issue
Block a user