From 8651df8c2a19feca2a5dc997d5eda2389305c9d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Thu, 13 Sep 2018 21:55:23 +0200 Subject: [PATCH] Fixed some lint issues --- src/api/core/accounts.rs | 10 ++++------ src/api/core/ciphers.rs | 6 +++--- src/api/core/organizations.rs | 2 +- src/api/core/two_factor.rs | 2 +- src/api/icons.rs | 2 +- src/api/identity.rs | 2 +- src/api/notifications.rs | 16 ++++++++-------- src/db/models/attachment.rs | 2 +- src/db/models/cipher.rs | 2 +- src/db/models/organization.rs | 6 +++--- src/db/models/user.rs | 2 +- 11 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/api/core/accounts.rs b/src/api/core/accounts.rs index 3e545773..6127be0e 100644 --- a/src/api/core/accounts.rs +++ b/src/api/core/accounts.rs @@ -41,12 +41,10 @@ fn register(data: JsonUpcase, conn: DbConn) -> EmptyResult { user_org.save(&conn); }; user + } else if CONFIG.signups_allowed { + err!("Account with this email already exists") } else { - if CONFIG.signups_allowed { - err!("Account with this email already exists") - } else { - err!("Registration not allowed") - } + err!("Registration not allowed") } }, None => { @@ -305,7 +303,7 @@ fn password_hint(data: JsonUpcase, conn: DbConn) -> EmptyResul if let Some(hint) = user.password_hint { err!(format!("Your password hint is: {}", &hint)); } else { - err!(format!("Sorry, you have no password hint...")); + err!("Sorry, you have no password hint..."); } } diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index b16ea002..23554820 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -376,11 +376,11 @@ fn put_cipher_share_seleted(data: JsonUpcase, headers: let mut data: ShareSelectedCipherData = data.into_inner().data; let mut cipher_ids: Vec = Vec::new(); - if data.Ciphers.len() == 0 { + if data.Ciphers.is_empty() { err!("You must select at least one cipher.") } - if data.CollectionIds.len() == 0 { + if data.CollectionIds.is_empty() { err!("You must select at least one collection.") } @@ -393,7 +393,7 @@ fn put_cipher_share_seleted(data: JsonUpcase, headers: let attachments = Attachment::find_by_ciphers(cipher_ids, &conn); - if attachments.len() > 0 { + if !attachments.is_empty() { err!("Ciphers should not have any attachments.") } diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs index 09f4fce3..687ee35c 100644 --- a/src/api/core/organizations.rs +++ b/src/api/core/organizations.rs @@ -289,7 +289,7 @@ fn get_collection_users(org_id: String, coll_id: String, _headers: AdminHeaders, .iter().map(|col_user| { UserOrganization::find_by_user_and_org(&col_user.user_uuid, &org_id, &conn) .unwrap() - .to_json_collection_user_details(&col_user.read_only, &conn) + .to_json_collection_user_details(col_user.read_only, &conn) }).collect(); Ok(Json(json!({ diff --git a/src/api/core/two_factor.rs b/src/api/core/two_factor.rs index 875dec28..a6446fd7 100644 --- a/src/api/core/two_factor.rs +++ b/src/api/core/two_factor.rs @@ -293,7 +293,7 @@ impl RegisterResponseCopy { RegisterResponse { registration_data: self.registration_data, version: self.version, - challenge: challenge, + challenge, client_data: self.client_data, } } diff --git a/src/api/icons.rs b/src/api/icons.rs index a436c8e3..a29ede6f 100644 --- a/src/api/icons.rs +++ b/src/api/icons.rs @@ -18,7 +18,7 @@ fn icon(domain: String) -> Content> { let icon_type = ContentType::new("image", "x-icon"); // Validate the domain to avoid directory traversal attacks - if domain.contains("/") || domain.contains("..") { + if domain.contains('/') || domain.contains("..") { return Content(icon_type, get_fallback_icon()); } diff --git a/src/api/identity.rs b/src/api/identity.rs index da27ff61..db62398b 100644 --- a/src/api/identity.rs +++ b/src/api/identity.rs @@ -158,7 +158,7 @@ fn twofactor_auth( let providers: Vec<_> = twofactors.iter().map(|tf| tf.type_).collect(); // No twofactor token if twofactor is disabled - if twofactors.len() == 0 { + if twofactors.is_empty() { return Ok(None); } diff --git a/src/api/notifications.rs b/src/api/notifications.rs index 0a0406e9..377b59d1 100644 --- a/src/api/notifications.rs +++ b/src/api/notifications.rs @@ -60,20 +60,20 @@ fn serialize(val: Value) -> Vec { // Add size bytes at the start // Extracted from BinaryMessageFormat.js - let mut size = buf.len(); + let mut size: usize = buf.len(); let mut len_buf: Vec = Vec::new(); loop { let mut size_part = size & 0x7f; - size = size >> 7; + size >>= 7; if size > 0 { - size_part = size_part | 0x80; + size_part |= 0x80; } len_buf.push(size_part as u8); - if size <= 0 { + if size == 0 { break; } } @@ -129,7 +129,7 @@ impl Handler for WSHandler { fn on_open(&mut self, hs: Handshake) -> ws::Result<()> { // TODO: Improve this split let path = hs.request.resource(); - let mut query_split: Vec<_> = path.split("?").nth(1).unwrap().split("&").collect(); + let mut query_split: Vec<_> = path.split('?').nth(1).unwrap().split('&').collect(); query_split.sort(); let access_token = &query_split[0][13..]; let _id = &query_split[1][3..]; @@ -255,7 +255,7 @@ impl WebSocketUsers { vec![ ("UserId".into(), user.uuid.clone().into()), ("Date".into(), serialize_date(user.updated_at)), - ].into(), + ], ut, ); @@ -268,7 +268,7 @@ impl WebSocketUsers { ("Id".into(), folder.uuid.clone().into()), ("UserId".into(), folder.user_uuid.clone().into()), ("RevisionDate".into(), serialize_date(folder.updated_at)), - ].into(), + ], ut, ); @@ -286,7 +286,7 @@ impl WebSocketUsers { ("OrganizationId".into(), org_uuid), ("CollectionIds".into(), Value::Nil), ("RevisionDate".into(), serialize_date(cipher.updated_at)), - ].into(), + ], ut, ); diff --git a/src/db/models/attachment.rs b/src/db/models/attachment.rs index 9c8eeefd..cfae5fba 100644 --- a/src/db/models/attachment.rs +++ b/src/db/models/attachment.rs @@ -78,7 +78,7 @@ impl Attachment { println!("ERROR: Failed with 10 retries"); return Err(err) } else { - retries = retries - 1; + retries -= 1; println!("Had to retry! Retries left: {}", retries); thread::sleep(time::Duration::from_millis(500)); continue diff --git a/src/db/models/cipher.rs b/src/db/models/cipher.rs index 2941db00..9039c527 100644 --- a/src/db/models/cipher.rs +++ b/src/db/models/cipher.rs @@ -362,6 +362,6 @@ impl Cipher { ) )) .select(ciphers_collections::collection_uuid) - .load::(&**conn).unwrap_or(vec![]) + .load::(&**conn).unwrap_or_default() } } diff --git a/src/db/models/organization.rs b/src/db/models/organization.rs index a2d9f5c7..65b779b8 100644 --- a/src/db/models/organization.rs +++ b/src/db/models/organization.rs @@ -194,7 +194,7 @@ impl UserOrganization { }) } - pub fn to_json_collection_user_details(&self, read_only: &bool, conn: &DbConn) -> JsonValue { + pub fn to_json_collection_user_details(&self, read_only: bool, conn: &DbConn) -> JsonValue { let user = User::find_by_uuid(&self.user_uuid, conn).unwrap(); json!({ @@ -281,14 +281,14 @@ impl UserOrganization { users_organizations::table .filter(users_organizations::user_uuid.eq(user_uuid)) .filter(users_organizations::status.eq(UserOrgStatus::Confirmed as i32)) - .load::(&**conn).unwrap_or(vec![]) + .load::(&**conn).unwrap_or_default() } pub fn find_invited_by_user(user_uuid: &str, conn: &DbConn) -> Vec { users_organizations::table .filter(users_organizations::user_uuid.eq(user_uuid)) .filter(users_organizations::status.eq(UserOrgStatus::Invited as i32)) - .load::(&**conn).unwrap_or(vec![]) + .load::(&**conn).unwrap_or_default() } pub fn find_by_org(org_uuid: &str, conn: &DbConn) -> Vec { diff --git a/src/db/models/user.rs b/src/db/models/user.rs index 0d958b5e..71611e1c 100644 --- a/src/db/models/user.rs +++ b/src/db/models/user.rs @@ -113,7 +113,7 @@ impl User { let orgs = UserOrganization::find_by_user(&self.uuid, conn); let orgs_json: Vec = orgs.iter().map(|c| c.to_json(&conn)).collect(); - let twofactor_enabled = TwoFactor::find_by_user(&self.uuid, conn).len() > 0; + let twofactor_enabled = !TwoFactor::find_by_user(&self.uuid, conn).is_empty(); json!({ "Id": self.uuid,