From 629c841e2d1944b1af406e67008ff6aa013bf014 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Fri, 27 May 2022 18:37:59 +0530 Subject: [PATCH] chore: cleanup and addressing clippy lints --- db/db-core/src/tests.rs | 4 ++-- db/db-sqlx-postgres/src/tests.rs | 4 ++-- src/api/v1/account/username.rs | 4 +--- src/api/v1/mcaptcha/easy.rs | 5 +---- src/api/v1/mcaptcha/get.rs | 1 - src/api/v1/pow/get_config.rs | 2 +- src/data.rs | 2 +- src/email/verification.rs | 1 - src/errors.rs | 23 ----------------------- src/pages/auth/login.rs | 1 - src/stats.rs | 12 ++++++------ 11 files changed, 14 insertions(+), 45 deletions(-) diff --git a/db/db-core/src/tests.rs b/db/db-core/src/tests.rs index 204c61fb..3af504c1 100644 --- a/db/db-core/src/tests.rs +++ b/db/db-core/src/tests.rs @@ -160,7 +160,7 @@ pub async fn database_works<'a, T: MCDatabase>( db.create_notification(an).await.unwrap(); // 2. Get notifications - let notifications = db.get_all_unread_notifications(&an.to).await.unwrap(); + let notifications = db.get_all_unread_notifications(an.to).await.unwrap(); assert_eq!(notifications.len(), 2); assert_eq!(notifications[0].heading.as_ref().unwrap(), an.heading); @@ -168,7 +168,7 @@ pub async fn database_works<'a, T: MCDatabase>( db.mark_notification_read(an.to, notifications[0].id.unwrap()) .await .unwrap(); - let new_notifications = db.get_all_unread_notifications(&an.to).await.unwrap(); + let new_notifications = db.get_all_unread_notifications(an.to).await.unwrap(); assert_eq!(new_notifications.len(), 1); // create captcha diff --git a/db/db-sqlx-postgres/src/tests.rs b/db/db-sqlx-postgres/src/tests.rs index b1cd9cdb..cfb60069 100644 --- a/db/db-sqlx-postgres/src/tests.rs +++ b/db/db-sqlx-postgres/src/tests.rs @@ -59,7 +59,7 @@ async fn everyting_works() { }, ]; - const add_notification: AddNotification = AddNotification { + const ADD_NOTIFICATION: AddNotification = AddNotification { from: NAME, to: NAME, message: MESSAGE, @@ -84,5 +84,5 @@ async fn everyting_works() { key: CAPTCHA_SECRET, description: CAPTCHA_DESCRIPTION, }; - database_works(&db, &p, &c, &LEVELS, &TRAFFIC_PATTERN, &add_notification).await; + database_works(&db, &p, &c, &LEVELS, &TRAFFIC_PATTERN, &ADD_NOTIFICATION).await; } diff --git a/src/api/v1/account/username.rs b/src/api/v1/account/username.rs index d545d4c8..9261adc3 100644 --- a/src/api/v1/account/username.rs +++ b/src/api/v1/account/username.rs @@ -63,9 +63,7 @@ async fn set_username( let processed_uname = data.creds.username(&payload.username)?; - data.db - .update_username(&username, &processed_uname) - .await?; + data.db.update_username(&username, &processed_uname).await?; id.forget(); id.remember(processed_uname); diff --git a/src/api/v1/mcaptcha/easy.rs b/src/api/v1/mcaptcha/easy.rs index c9de5b08..b848d2a9 100644 --- a/src/api/v1/mcaptcha/easy.rs +++ b/src/api/v1/mcaptcha/easy.rs @@ -166,9 +166,7 @@ async fn update( update_captcha_runner(&msg, &data, &username).await?; - data.db - .delete_traffic_pattern(&username, &msg.key) - .await?; + data.db.delete_traffic_pattern(&username, &msg.key).await?; data.db .add_traffic_pattern(&username, &msg.key, &pattern) @@ -196,7 +194,6 @@ pub mod tests { #[test] fn easy_configuration_works() { - const NAME: &str = "defaultuserconfgworks"; let settings = crate::tests::get_settings(); let mut payload = TrafficPattern { diff --git a/src/api/v1/mcaptcha/get.rs b/src/api/v1/mcaptcha/get.rs index 35c5dd1a..4f2272a4 100644 --- a/src/api/v1/mcaptcha/get.rs +++ b/src/api/v1/mcaptcha/get.rs @@ -17,7 +17,6 @@ use actix_identity::Identity; use actix_web::{web, HttpResponse, Responder}; -use libmcaptcha::defense::Level; use serde::{Deserialize, Serialize}; use super::create::MCaptchaDetails; diff --git a/src/api/v1/pow/get_config.rs b/src/api/v1/pow/get_config.rs index 1f0476cf..f35c0787 100644 --- a/src/api/v1/pow/get_config.rs +++ b/src/api/v1/pow/get_config.rs @@ -101,7 +101,7 @@ pub async fn get_config( async fn init_mcaptcha(data: &AppData, key: &str) -> ServiceResult<()> { // get levels let levels = data.db.get_captcha_levels(None, key).await?; - let duration = data.db.get_captcha_cooldown(&key).await?; + let duration = data.db.get_captcha_cooldown(key).await?; // build defense let mut defense = DefenseBuilder::default(); diff --git a/src/data.rs b/src/data.rs index eb8188f7..b64fd243 100644 --- a/src/data.rs +++ b/src/data.rs @@ -185,7 +185,7 @@ impl Data { log::info!("Initialized credential manager"); }); - let pool = s.database.pool; + let pool = s.database.pool; let pool_options = PgPoolOptions::new().max_connections(pool); let connection_options = ConnectionOptions::Fresh(Fresh { pool_options, diff --git a/src/email/verification.rs b/src/email/verification.rs index 9f7fdb71..86a31830 100644 --- a/src/email/verification.rs +++ b/src/email/verification.rs @@ -23,7 +23,6 @@ use sailfish::TemplateOnce; use crate::errors::*; use crate::Data; -use crate::SETTINGS; const PAGE: &str = "Login"; diff --git a/src/errors.rs b/src/errors.rs index 1aa3ece8..da21674a 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -240,21 +240,6 @@ impl From for ServiceError { } } -//#[cfg(not(tarpaulin_include))] -//impl From for ServiceError { -// #[cfg(not(tarpaulin_include))] -// fn from(e: sqlx::Error) -> Self { -// use sqlx::error::Error; -// use std::borrow::Cow; -// if let Error::Database(err) = e { -// if err.code() == Some(Cow::from("23505")) { -// return ServiceError::UsernameTaken; -// } -// } -// ServiceError::InternalServerError -// } -//} - #[cfg(not(tarpaulin_include))] impl From for ServiceError { #[cfg(not(tarpaulin_include))] @@ -294,14 +279,6 @@ pub enum PageError { ServiceError(ServiceError), } -#[cfg(not(tarpaulin_include))] -impl From for PageError { - #[cfg(not(tarpaulin_include))] - fn from(_: sqlx::Error) -> Self { - PageError::InternalServerError - } -} - #[cfg(not(tarpaulin_include))] impl From for PageError { #[cfg(not(tarpaulin_include))] diff --git a/src/pages/auth/login.rs b/src/pages/auth/login.rs index 72f77d64..29133f50 100644 --- a/src/pages/auth/login.rs +++ b/src/pages/auth/login.rs @@ -20,7 +20,6 @@ use lazy_static::lazy_static; use my_codegen::get; use sailfish::TemplateOnce; -use crate::api::v1::RedirectQuery; use crate::PAGES; #[derive(Clone, TemplateOnce)] diff --git a/src/stats.rs b/src/stats.rs index 11df8e7e..466e17cd 100644 --- a/src/stats.rs +++ b/src/stats.rs @@ -50,12 +50,12 @@ where } } -impl Clone for Box { - fn clone(&self) -> Self { - self.clone() - //(*self).clone_stats() - } -} +//impl Clone for Box { +// fn clone(&self) -> Self { +// Box::clone(self) +// //(*self).clone_stats() +// } +//} #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)] pub struct CaptchaStats {