From 738ad2127bcd71f07c075a6df6424fb11fcd5837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Fri, 7 Dec 2018 15:01:29 +0100 Subject: [PATCH] Fixed some clippy linting issues --- src/api/core/ciphers.rs | 2 +- src/api/core/two_factor.rs | 7 +++---- src/api/identity.rs | 2 +- src/api/notifications.rs | 12 ++++++------ src/auth.rs | 8 ++++---- src/db/models/cipher.rs | 14 ++++---------- src/db/models/collection.rs | 7 ++----- src/db/models/organization.rs | 10 +++++----- 8 files changed, 26 insertions(+), 36 deletions(-) diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index e5a7c59e..f1d3f38a 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -180,7 +180,7 @@ pub struct Attachments2Data { fn post_ciphers_admin(data: JsonUpcase, headers: Headers, conn: DbConn, ws: State) -> JsonResult { let data: ShareCipherData = data.into_inner().data; - let mut cipher = Cipher::new(data.Cipher.Type.clone(), data.Cipher.Name.clone()); + let mut cipher = Cipher::new(data.Cipher.Type, data.Cipher.Name.clone()); cipher.user_uuid = Some(headers.user.uuid.clone()); match cipher.save(&conn) { Ok(()) => (), diff --git a/src/api/core/two_factor.rs b/src/api/core/two_factor.rs index d25a6b42..ef017af7 100644 --- a/src/api/core/two_factor.rs +++ b/src/api/core/two_factor.rs @@ -568,9 +568,8 @@ fn parse_yubikeys(data: &EnableYubikeyData) -> Vec { fn jsonify_yubikeys(yubikeys: Vec) -> serde_json::Value { let mut result = json!({}); - for i in 0..yubikeys.len() { - let ref key = &yubikeys[i]; - result[format!("Key{}", i+1)] = Value::String(key.to_string()); + for (i, key) in yubikeys.into_iter().enumerate() { + result[format!("Key{}", i+1)] = Value::String(key); } result @@ -654,7 +653,7 @@ fn activate_yubikey(data: JsonUpcase, headers: Headers, conn: let yubikeys = parse_yubikeys(&data); - if yubikeys.len() == 0 { + if yubikeys.is_empty() { return Ok(Json(json!({ "Enabled": false, "Object": "twoFactorU2f", diff --git a/src/api/identity.rs b/src/api/identity.rs index da361bc7..58628d73 100644 --- a/src/api/identity.rs +++ b/src/api/identity.rs @@ -93,7 +93,7 @@ fn _password_login(data: ConnectData, conn: DbConn, remote: Option) } let device_type = util::try_parse_string(data.device_type.as_ref()).unwrap_or(0); - let device_id = data.device_identifier.clone().unwrap_or_else(|| crate::util::get_uuid()); + let device_id = data.device_identifier.clone().unwrap_or_else(crate::util::get_uuid); let device_name = data.device_name.clone().unwrap_or("unknown_device".into()); // Find device or create new diff --git a/src/api/notifications.rs b/src/api/notifications.rs index 6e4f216a..d126b2ad 100644 --- a/src/api/notifications.rs +++ b/src/api/notifications.rs @@ -242,10 +242,10 @@ pub struct WebSocketUsers { } impl WebSocketUsers { - fn send_update(&self, user_uuid: &String, data: Vec) -> ws::Result<()> { + fn send_update(&self, user_uuid: &String, data: &[u8]) -> ws::Result<()> { if let Some(user) = self.map.get(user_uuid) { for sender in user.iter() { - sender.send(data.clone())?; + sender.send(data)?; } } Ok(()) @@ -262,7 +262,7 @@ impl WebSocketUsers { ut, ); - self.send_update(&user.uuid.clone(), data).ok(); + self.send_update(&user.uuid.clone(), &data).ok(); } pub fn send_folder_update(&self, ut: UpdateType, folder: &Folder) { @@ -275,10 +275,10 @@ impl WebSocketUsers { ut, ); - self.send_update(&folder.user_uuid, data).ok(); + self.send_update(&folder.user_uuid, &data).ok(); } - pub fn send_cipher_update(&self, ut: UpdateType, cipher: &Cipher, user_uuids: &Vec) { + pub fn send_cipher_update(&self, ut: UpdateType, cipher: &Cipher, user_uuids: &[String]) { let user_uuid = convert_option(cipher.user_uuid.clone()); let org_uuid = convert_option(cipher.organization_uuid.clone()); @@ -294,7 +294,7 @@ impl WebSocketUsers { ); for uuid in user_uuids { - self.send_update(&uuid, data.clone()).ok(); + self.send_update(&uuid, &data).ok(); } } } diff --git a/src/auth.rs b/src/auth.rs index 6e855381..5085341c 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -192,7 +192,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for OrgHeaders { fn from_request(request: &'a Request<'r>) -> request::Outcome { match request.guard::() { - Outcome::Forward(f) => Outcome::Forward(f), + Outcome::Forward(_) => Outcome::Forward(()), Outcome::Failure(f) => Outcome::Failure(f), Outcome::Success(headers) => { // org_id is expected to be the second param ("/organizations/") @@ -225,7 +225,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for OrgHeaders { device: headers.device, user: headers.user, org_user_type: { - if let Some(org_usr_type) = UserOrgType::from_i32(&org_user.type_) { + if let Some(org_usr_type) = UserOrgType::from_i32(org_user.type_) { org_usr_type } else { // This should only happen if the DB is corrupted err_handler!("Unknown user type in the database") @@ -252,7 +252,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for AdminHeaders { fn from_request(request: &'a Request<'r>) -> request::Outcome { match request.guard::() { - Outcome::Forward(f) => Outcome::Forward(f), + Outcome::Forward(_) => Outcome::Forward(()), Outcome::Failure(f) => Outcome::Failure(f), Outcome::Success(headers) => { if headers.org_user_type >= UserOrgType::Admin { @@ -281,7 +281,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for OwnerHeaders { fn from_request(request: &'a Request<'r>) -> request::Outcome { match request.guard::() { - Outcome::Forward(f) => Outcome::Forward(f), + Outcome::Forward(_) => Outcome::Forward(()), Outcome::Failure(f) => Outcome::Failure(f), Outcome::Success(headers) => { if headers.org_user_type == UserOrgType::Owner { diff --git a/src/db/models/cipher.rs b/src/db/models/cipher.rs index fc1eacb7..3b7f2dbb 100644 --- a/src/db/models/cipher.rs +++ b/src/db/models/cipher.rs @@ -232,7 +232,7 @@ impl Cipher { } pub fn is_write_accessible_to_user(&self, user_uuid: &str, conn: &DbConn) -> bool { - match ciphers::table + ciphers::table .filter(ciphers::uuid.eq(&self.uuid)) .left_join(users_organizations::table.on( ciphers::organization_uuid.eq(users_organizations::org_uuid.nullable()).and( @@ -253,14 +253,11 @@ impl Cipher { ) )) .select(ciphers::all_columns) - .first::(&**conn).ok() { - Some(_) => true, - None => false - } + .first::(&**conn).ok().is_some() } pub fn is_accessible_to_user(&self, user_uuid: &str, conn: &DbConn) -> bool { - match ciphers::table + ciphers::table .filter(ciphers::uuid.eq(&self.uuid)) .left_join(users_organizations::table.on( ciphers::organization_uuid.eq(users_organizations::org_uuid.nullable()).and( @@ -279,10 +276,7 @@ impl Cipher { ) )) .select(ciphers::all_columns) - .first::(&**conn).ok() { - Some(_) => true, - None => false - } + .first::(&**conn).ok().is_some() } pub fn get_folder_uuid(&self, user_uuid: &str, conn: &DbConn) -> Option { diff --git a/src/db/models/collection.rs b/src/db/models/collection.rs index 962563f7..6c3f640e 100644 --- a/src/db/models/collection.rs +++ b/src/db/models/collection.rs @@ -148,15 +148,12 @@ impl Collection { if user_org.access_all { true } else { - match users_collections::table.inner_join(collections::table) + users_collections::table.inner_join(collections::table) .filter(users_collections::collection_uuid.eq(&self.uuid)) .filter(users_collections::user_uuid.eq(&user_uuid)) .filter(users_collections::read_only.eq(false)) .select(collections::all_columns) - .first::(&**conn).ok() { - None => false, // Read only or no access to collection - Some(_) => true, - } + .first::(&**conn).ok().is_some() // Read only or no access to collection } } } diff --git a/src/db/models/organization.rs b/src/db/models/organization.rs index 94e2a29a..a83a9725 100644 --- a/src/db/models/organization.rs +++ b/src/db/models/organization.rs @@ -77,10 +77,10 @@ impl PartialEq for UserOrgType { impl PartialOrd for UserOrgType { fn partial_cmp(&self, other: &i32) -> Option { - if let Some(other) = Self::from_i32(other) { + if let Some(other) = Self::from_i32(*other) { return Some(self.cmp(&other)) } - return None + None } fn gt(&self, other: &i32) -> bool { @@ -107,10 +107,10 @@ impl PartialEq for i32 { impl PartialOrd for i32 { fn partial_cmp(&self, other: &UserOrgType) -> Option { - if let Some(self_type) = UserOrgType::from_i32(self) { + if let Some(self_type) = UserOrgType::from_i32(*self) { return Some(self_type.cmp(other)) } - return None + None } fn lt(&self, other: &UserOrgType) -> bool { @@ -140,7 +140,7 @@ impl UserOrgType { } } - pub fn from_i32(i: &i32) -> Option { + pub fn from_i32(i: i32) -> Option { match i { 0 => Some(UserOrgType::Owner), 1 => Some(UserOrgType::Admin),