From d29b6bee2850795ac9565ee1ab70f4c53be68536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Sat, 2 Nov 2019 17:39:01 +0100 Subject: [PATCH] Remove unnecessary clones and other clippy fixes --- src/api/core/folders.rs | 2 +- src/api/core/organizations.rs | 8 ++++---- src/api/core/two_factor/duo.rs | 2 +- src/api/core/two_factor/u2f.rs | 2 +- src/api/icons.rs | 12 +++--------- src/auth.rs | 12 ++++++------ src/config.rs | 18 ++++++------------ src/mail.rs | 2 +- 8 files changed, 23 insertions(+), 35 deletions(-) diff --git a/src/api/core/folders.rs b/src/api/core/folders.rs index fef99a7d..79e8c03a 100644 --- a/src/api/core/folders.rs +++ b/src/api/core/folders.rs @@ -59,7 +59,7 @@ pub struct FolderData { fn post_folders(data: JsonUpcase, headers: Headers, conn: DbConn, nt: Notify) -> JsonResult { let data: FolderData = data.into_inner().data; - let mut folder = Folder::new(headers.user.uuid.clone(), data.Name); + let mut folder = Folder::new(headers.user.uuid, data.Name); folder.save(&conn)?; nt.send_folder_update(UpdateType::FolderCreate, &folder); diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs index 0a6a9db1..1b092d1a 100644 --- a/src/api/core/organizations.rs +++ b/src/api/core/organizations.rs @@ -77,7 +77,7 @@ fn create_organization(headers: Headers, data: JsonUpcase, conn: DbConn let data: OrgData = data.into_inner().data; let org = Organization::new(data.Name, data.BillingEmail); - let mut user_org = UserOrganization::new(headers.user.uuid.clone(), org.uuid.clone()); + let mut user_org = UserOrganization::new(headers.user.uuid, org.uuid.clone()); let collection = Collection::new(org.uuid.clone(), data.CollectionName); user_org.akey = data.Key; @@ -221,7 +221,7 @@ fn post_organization_collections( None => err!("Can't find organization details"), }; - let collection = Collection::new(org.uuid.clone(), data.Name); + let collection = Collection::new(org.uuid, data.Name); collection.save(&conn)?; Ok(Json(collection.to_json())) @@ -262,7 +262,7 @@ fn post_organization_collection_update( err!("Collection is not owned by organization"); } - collection.name = data.Name.clone(); + collection.name = data.Name; collection.save(&conn)?; Ok(Json(collection.to_json())) @@ -581,7 +581,7 @@ fn reinvite_user(org_id: String, user_org: String, headers: AdminHeaders, conn: Some(headers.user.email), )?; } else { - let invitation = Invitation::new(user.email.clone()); + let invitation = Invitation::new(user.email); invitation.save(&conn)?; } diff --git a/src/api/core/two_factor/duo.rs b/src/api/core/two_factor/duo.rs index 0d6d2124..5b7d7886 100644 --- a/src/api/core/two_factor/duo.rs +++ b/src/api/core/two_factor/duo.rs @@ -167,7 +167,7 @@ fn activate_duo(data: JsonUpcase, headers: Headers, conn: DbConn) }; let type_ = TwoFactorType::Duo; - let twofactor = TwoFactor::new(headers.user.uuid.clone(), type_, data_str); + let twofactor = TwoFactor::new(headers.user.uuid, type_, data_str); twofactor.save(&conn)?; Ok(Json(json!({ diff --git a/src/api/core/two_factor/u2f.rs b/src/api/core/two_factor/u2f.rs index 5ccf2914..6324ed03 100644 --- a/src/api/core/two_factor/u2f.rs +++ b/src/api/core/two_factor/u2f.rs @@ -164,7 +164,7 @@ fn activate_u2f(data: JsonUpcase, headers: Headers, conn: DbConn) err!("Error registering U2F token") } - let registration = U2F.register_response(challenge.clone(), response.into())?; + let registration = U2F.register_response(challenge, response.into())?; let full_registration = U2FRegistration { id: data.Id.into_i32()?, name: data.Name, diff --git a/src/api/icons.rs b/src/api/icons.rs index ad692d5d..e8e4d1c1 100644 --- a/src/api/icons.rs +++ b/src/api/icons.rs @@ -65,9 +65,8 @@ fn icon(domain: String) -> Content> { } fn check_icon_domain_is_blacklisted(domain: &str) -> bool { - let mut is_blacklisted = false; - if CONFIG.icon_blacklist_non_global_ips() { - is_blacklisted = (domain, 0) + let mut is_blacklisted = CONFIG.icon_blacklist_non_global_ips() + && (domain, 0) .to_socket_addrs() .map(|x| { for ip_port in x { @@ -79,7 +78,6 @@ fn check_icon_domain_is_blacklisted(domain: &str) -> bool { false }) .unwrap_or(false); - } // Skip the regex check if the previous one is true already if !is_blacklisted { @@ -279,11 +277,7 @@ fn get_page_with_cookies(url: &str, cookie_str: &str) -> Result } if cookie_str.is_empty() { - CLIENT - .get(url) - .send()? - .error_for_status() - .map_err(Into::into) + CLIENT.get(url).send()?.error_for_status().map_err(Into::into) } else { CLIENT .get(url) diff --git a/src/auth.rs b/src/auth.rs index eab1e900..8a55ba54 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -118,7 +118,7 @@ pub fn generate_invite_claims( uuid: String, email: String, org_id: Option, - org_user_id: Option, + user_org_id: Option, invited_by_email: Option, ) -> InviteJWTClaims { let time_now = Utc::now().naive_utc(); @@ -126,11 +126,11 @@ pub fn generate_invite_claims( nbf: time_now.timestamp(), exp: (time_now + Duration::days(5)).timestamp(), iss: JWT_INVITE_ISSUER.to_string(), - sub: uuid.clone(), - email: email.clone(), - org_id: org_id.clone(), - user_org_id: org_user_id.clone(), - invited_by_email: invited_by_email.clone(), + sub: uuid, + email, + org_id, + user_org_id, + invited_by_email, } } diff --git a/src/config.rs b/src/config.rs index 7826d381..cfb3ddb1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -368,22 +368,16 @@ make_config! { fn validate_config(cfg: &ConfigItems) -> Result<(), Error> { let db_url = cfg.database_url.to_lowercase(); - if cfg!(feature = "sqlite") { - if db_url.starts_with("mysql:") || db_url.starts_with("postgresql:") { - err!("`DATABASE_URL` is meant for MySQL or Postgres, while this server is meant for SQLite") - } + if cfg!(feature = "sqlite") && (db_url.starts_with("mysql:") || db_url.starts_with("postgresql:")) { + err!("`DATABASE_URL` is meant for MySQL or Postgres, while this server is meant for SQLite") } - if cfg!(feature = "mysql") { - if !db_url.starts_with("mysql:") { - err!("`DATABASE_URL` should start with mysql: when using the MySQL server") - } + if cfg!(feature = "mysql") && !db_url.starts_with("mysql:") { + err!("`DATABASE_URL` should start with mysql: when using the MySQL server") } - if cfg!(feature = "postgresql") { - if !db_url.starts_with("postgresql:") { - err!("`DATABASE_URL` should start with postgresql: when using the PostgreSQL server") - } + if cfg!(feature = "postgresql") && !db_url.starts_with("postgresql:") { + err!("`DATABASE_URL` should start with postgresql: when using the PostgreSQL server") } if let Some(ref token) = cfg.admin_token { diff --git a/src/mail.rs b/src/mail.rs index 17e9f152..0e524850 100644 --- a/src/mail.rs +++ b/src/mail.rs @@ -105,7 +105,7 @@ pub fn send_invite( String::from(address), org_id.clone(), org_user_id.clone(), - invited_by_email.clone(), + invited_by_email, ); let invite_token = encode_jwt(&claims);