From 9254cf9d9c1b43a4ad3bc640610048c0a798424e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Sat, 19 Jun 2021 22:02:03 +0200 Subject: [PATCH] Fix clippy lints --- src/api/core/ciphers.rs | 76 ++++++++++++------------ src/api/core/organizations.rs | 12 ++-- src/api/core/two_factor/authenticator.rs | 6 +- src/api/core/two_factor/duo.rs | 6 +- src/api/core/two_factor/email.rs | 18 +++--- src/api/core/two_factor/u2f.rs | 12 ++-- src/api/core/two_factor/webauthn.rs | 8 +-- src/api/icons.rs | 8 +-- src/api/identity.rs | 12 ++-- src/api/mod.rs | 1 + src/api/notifications.rs | 2 +- src/config.rs | 6 +- src/db/models/attachment.rs | 4 +- src/db/models/cipher.rs | 30 +++++----- src/db/models/collection.rs | 20 +++---- src/db/models/device.rs | 4 +- src/db/models/favorite.rs | 6 +- src/db/models/folder.rs | 6 +- src/db/models/organization.rs | 20 +++---- src/db/models/send.rs | 10 ++-- src/db/models/two_factor.rs | 6 +- src/db/models/user.rs | 6 +- src/error.rs | 50 ++++++++-------- 23 files changed, 163 insertions(+), 166 deletions(-) diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index 88dfa3fa..6e425743 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -322,12 +322,12 @@ pub fn update_cipher_from_data( } if let Some(org_id) = data.OrganizationId { - match UserOrganization::find_by_user_and_org(&headers.user.uuid, &org_id, &conn) { + match UserOrganization::find_by_user_and_org(&headers.user.uuid, &org_id, conn) { None => err!("You don't have permission to add item to organization"), Some(org_user) => { if shared_to_collection || org_user.has_full_access() - || cipher.is_write_accessible_to_user(&headers.user.uuid, &conn) + || cipher.is_write_accessible_to_user(&headers.user.uuid, conn) { cipher.organization_uuid = Some(org_id); // After some discussion in PR #1329 re-added the user_uuid = None again. @@ -359,7 +359,7 @@ pub fn update_cipher_from_data( // Modify attachments name and keys when rotating if let Some(attachments) = data.Attachments2 { for (id, attachment) in attachments { - let mut saved_att = match Attachment::find_by_id(&id, &conn) { + let mut saved_att = match Attachment::find_by_id(&id, conn) { Some(att) => att, None => err!("Attachment doesn't exist"), }; @@ -374,7 +374,7 @@ pub fn update_cipher_from_data( saved_att.akey = Some(attachment.Key); saved_att.file_name = attachment.FileName; - saved_att.save(&conn)?; + saved_att.save(conn)?; } } @@ -420,12 +420,12 @@ pub fn update_cipher_from_data( cipher.password_history = data.PasswordHistory.map(|f| f.to_string()); cipher.reprompt = data.Reprompt; - cipher.save(&conn)?; - cipher.move_to_folder(data.FolderId, &headers.user.uuid, &conn)?; - cipher.set_favorite(data.Favorite, &headers.user.uuid, &conn)?; + cipher.save(conn)?; + cipher.move_to_folder(data.FolderId, &headers.user.uuid, conn)?; + cipher.set_favorite(data.Favorite, &headers.user.uuid, conn)?; if ut != UpdateType::None { - nt.send_cipher_update(ut, &cipher, &cipher.update_users_revision(&conn)); + nt.send_cipher_update(ut, cipher, &cipher.update_users_revision(conn)); } Ok(()) @@ -595,7 +595,7 @@ fn post_collections_admin( cipher.get_collections(&headers.user.uuid, &conn).iter().cloned().collect(); for collection in posted_collections.symmetric_difference(¤t_collections) { - match Collection::find_by_uuid(&collection, &conn) { + match Collection::find_by_uuid(collection, &conn) { None => err!("Invalid collection ID provided"), Some(collection) => { if collection.is_writable_by_user(&headers.user.uuid, &conn) { @@ -709,9 +709,9 @@ fn share_cipher_by_uuid( conn: &DbConn, nt: &Notify, ) -> JsonResult { - let mut cipher = match Cipher::find_by_uuid(&uuid, &conn) { + let mut cipher = match Cipher::find_by_uuid(uuid, conn) { Some(cipher) => { - if cipher.is_write_accessible_to_user(&headers.user.uuid, &conn) { + if cipher.is_write_accessible_to_user(&headers.user.uuid, conn) { cipher } else { err!("Cipher is not write accessible") @@ -728,11 +728,11 @@ fn share_cipher_by_uuid( None => {} Some(organization_uuid) => { for uuid in &data.CollectionIds { - match Collection::find_by_uuid_and_org(uuid, &organization_uuid, &conn) { + match Collection::find_by_uuid_and_org(uuid, &organization_uuid, conn) { None => err!("Invalid collection ID provided"), Some(collection) => { - if collection.is_writable_by_user(&headers.user.uuid, &conn) { - CollectionCipher::save(&cipher.uuid, &collection.uuid, &conn)?; + if collection.is_writable_by_user(&headers.user.uuid, conn) { + CollectionCipher::save(&cipher.uuid, &collection.uuid, conn)?; shared_to_collection = true; } else { err!("No rights to modify the collection") @@ -746,14 +746,14 @@ fn share_cipher_by_uuid( update_cipher_from_data( &mut cipher, data.Cipher, - &headers, + headers, shared_to_collection, - &conn, - &nt, + conn, + nt, UpdateType::CipherUpdate, )?; - Ok(Json(cipher.to_json(&headers.host, &headers.user.uuid, &conn))) + Ok(Json(cipher.to_json(&headers.host, &headers.user.uuid, conn))) } /// v2 API for downloading an attachment. This just redirects the client to @@ -848,7 +848,7 @@ fn save_attachment( None => err_discard!("Cipher doesn't exist", data), }; - if !cipher.is_write_accessible_to_user(&headers.user.uuid, &conn) { + if !cipher.is_write_accessible_to_user(&headers.user.uuid, conn) { err_discard!("Cipher is not write accessible", data) } @@ -863,7 +863,7 @@ fn save_attachment( match CONFIG.user_attachment_limit() { Some(0) => err_discard!("Attachments are disabled", data), Some(limit_kb) => { - let left = (limit_kb * 1024) - Attachment::size_by_user(user_uuid, &conn) + size_adjust; + let left = (limit_kb * 1024) - Attachment::size_by_user(user_uuid, conn) + size_adjust; if left <= 0 { err_discard!("Attachment size limit reached! Delete some files to open space", data) } @@ -875,7 +875,7 @@ fn save_attachment( match CONFIG.org_attachment_limit() { Some(0) => err_discard!("Attachments are disabled", data), Some(limit_kb) => { - let left = (limit_kb * 1024) - Attachment::size_by_org(org_uuid, &conn) + size_adjust; + let left = (limit_kb * 1024) - Attachment::size_by_org(org_uuid, conn) + size_adjust; if left <= 0 { err_discard!("Attachment size limit reached! Delete some files to open space", data) } @@ -994,7 +994,7 @@ fn save_attachment( err!(e); } - nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &cipher.update_users_revision(&conn)); + nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &cipher.update_users_revision(conn)); Ok(cipher) } @@ -1303,22 +1303,22 @@ fn delete_all( } fn _delete_cipher_by_uuid(uuid: &str, headers: &Headers, conn: &DbConn, soft_delete: bool, nt: &Notify) -> EmptyResult { - let mut cipher = match Cipher::find_by_uuid(&uuid, &conn) { + let mut cipher = match Cipher::find_by_uuid(uuid, conn) { Some(cipher) => cipher, None => err!("Cipher doesn't exist"), }; - if !cipher.is_write_accessible_to_user(&headers.user.uuid, &conn) { + if !cipher.is_write_accessible_to_user(&headers.user.uuid, conn) { err!("Cipher can't be deleted by user") } if soft_delete { cipher.deleted_at = Some(Utc::now().naive_utc()); - cipher.save(&conn)?; - nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &cipher.update_users_revision(&conn)); + cipher.save(conn)?; + nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &cipher.update_users_revision(conn)); } else { - cipher.delete(&conn)?; - nt.send_cipher_update(UpdateType::CipherDelete, &cipher, &cipher.update_users_revision(&conn)); + cipher.delete(conn)?; + nt.send_cipher_update(UpdateType::CipherDelete, &cipher, &cipher.update_users_revision(conn)); } Ok(()) @@ -1351,20 +1351,20 @@ fn _delete_multiple_ciphers( } fn _restore_cipher_by_uuid(uuid: &str, headers: &Headers, conn: &DbConn, nt: &Notify) -> JsonResult { - let mut cipher = match Cipher::find_by_uuid(&uuid, &conn) { + let mut cipher = match Cipher::find_by_uuid(uuid, conn) { Some(cipher) => cipher, None => err!("Cipher doesn't exist"), }; - if !cipher.is_write_accessible_to_user(&headers.user.uuid, &conn) { + if !cipher.is_write_accessible_to_user(&headers.user.uuid, conn) { err!("Cipher can't be restored by user") } cipher.deleted_at = None; - cipher.save(&conn)?; + cipher.save(conn)?; - nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &cipher.update_users_revision(&conn)); - Ok(Json(cipher.to_json(&headers.host, &headers.user.uuid, &conn))) + nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &cipher.update_users_revision(conn)); + Ok(Json(cipher.to_json(&headers.host, &headers.user.uuid, conn))) } fn _restore_multiple_ciphers(data: JsonUpcase, headers: &Headers, conn: &DbConn, nt: &Notify) -> JsonResult { @@ -1400,7 +1400,7 @@ fn _delete_cipher_attachment_by_id( conn: &DbConn, nt: &Notify, ) -> EmptyResult { - let attachment = match Attachment::find_by_id(&attachment_id, &conn) { + let attachment = match Attachment::find_by_id(attachment_id, conn) { Some(attachment) => attachment, None => err!("Attachment doesn't exist"), }; @@ -1409,17 +1409,17 @@ fn _delete_cipher_attachment_by_id( err!("Attachment from other cipher") } - let cipher = match Cipher::find_by_uuid(&uuid, &conn) { + let cipher = match Cipher::find_by_uuid(uuid, conn) { Some(cipher) => cipher, None => err!("Cipher doesn't exist"), }; - if !cipher.is_write_accessible_to_user(&headers.user.uuid, &conn) { + if !cipher.is_write_accessible_to_user(&headers.user.uuid, conn) { err!("Cipher cannot be deleted by user") } // Delete attachment - attachment.delete(&conn)?; - nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &cipher.update_users_revision(&conn)); + attachment.delete(conn)?; + nt.send_cipher_update(UpdateType::CipherUpdate, &cipher, &cipher.update_users_revision(conn)); Ok(()) } diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs index cfe3932e..5c1ccedb 100644 --- a/src/api/core/organizations.rs +++ b/src/api/core/organizations.rs @@ -397,7 +397,7 @@ fn get_collection_users(org_id: String, coll_id: String, _headers: ManagerHeader .map(|col_user| { UserOrganization::find_by_user_and_org(&col_user.user_uuid, &org_id, &conn) .unwrap() - .to_json_user_access_restrictions(&col_user) + .to_json_user_access_restrictions(col_user) }) .collect(); @@ -504,13 +504,13 @@ fn send_invite(org_id: String, data: JsonUpcase, headers: AdminHeade } else { UserOrgStatus::Accepted as i32 // Automatically mark user as accepted if no email invites }; - let user = match User::find_by_mail(&email, &conn) { + let user = match User::find_by_mail(email, &conn) { None => { if !CONFIG.invitations_allowed() { err!(format!("User does not exist: {}", email)) } - if !CONFIG.is_email_domain_allowed(&email) { + if !CONFIG.is_email_domain_allowed(email) { err!("Email domain not eligible for invitations") } @@ -560,7 +560,7 @@ fn send_invite(org_id: String, data: JsonUpcase, headers: AdminHeade }; mail::send_invite( - &email, + email, &user.uuid, Some(org_id.clone()), Some(new_user.uuid), @@ -630,7 +630,7 @@ fn accept_invite(_org_id: String, _org_user_id: String, data: JsonUpcase { @@ -656,7 +656,7 @@ fn accept_invite(_org_id: String, _org_user_id: String, data: JsonUpcase org.name, None => err!("Organization not found."), }; diff --git a/src/api/core/two_factor/authenticator.rs b/src/api/core/two_factor/authenticator.rs index 2d076b27..36ce137a 100644 --- a/src/api/core/two_factor/authenticator.rs +++ b/src/api/core/two_factor/authenticator.rs @@ -114,7 +114,7 @@ pub fn validate_totp_code_str( _ => err!("TOTP code is not a number"), }; - validate_totp_code(user_uuid, totp_code, secret, ip, &conn) + validate_totp_code(user_uuid, totp_code, secret, ip, conn) } pub fn validate_totp_code(user_uuid: &str, totp_code: u64, secret: &str, ip: &ClientIp, conn: &DbConn) -> EmptyResult { @@ -125,7 +125,7 @@ pub fn validate_totp_code(user_uuid: &str, totp_code: u64, secret: &str, ip: &Cl Err(_) => err!("Invalid TOTP secret"), }; - let mut twofactor = match TwoFactor::find_by_user_and_type(&user_uuid, TwoFactorType::Authenticator as i32, &conn) { + let mut twofactor = match TwoFactor::find_by_user_and_type(user_uuid, TwoFactorType::Authenticator as i32, conn) { Some(tf) => tf, _ => TwoFactor::new(user_uuid.to_string(), TwoFactorType::Authenticator, secret.to_string()), }; @@ -156,7 +156,7 @@ pub fn validate_totp_code(user_uuid: &str, totp_code: u64, secret: &str, ip: &Cl // Save the last used time step so only totp time steps higher then this one are allowed. // This will also save a newly created twofactor if the code is correct. twofactor.last_used = time_step as i32; - twofactor.save(&conn)?; + twofactor.save(conn)?; return Ok(()); } else if generated == totp_code && time_step <= twofactor.last_used as i64 { warn!("This or a TOTP code within {} steps back and forward has already been used!", steps); diff --git a/src/api/core/two_factor/duo.rs b/src/api/core/two_factor/duo.rs index 5ca87085..a45724df 100644 --- a/src/api/core/two_factor/duo.rs +++ b/src/api/core/two_factor/duo.rs @@ -226,7 +226,7 @@ fn get_user_duo_data(uuid: &str, conn: &DbConn) -> DuoStatus { let type_ = TwoFactorType::Duo as i32; // If the user doesn't have an entry, disabled - let twofactor = match TwoFactor::find_by_user_and_type(uuid, type_, &conn) { + let twofactor = match TwoFactor::find_by_user_and_type(uuid, type_, conn) { Some(t) => t, None => return DuoStatus::Disabled(DuoData::global().is_some()), }; @@ -247,8 +247,8 @@ fn get_user_duo_data(uuid: &str, conn: &DbConn) -> DuoStatus { // let (ik, sk, ak, host) = get_duo_keys(); fn get_duo_keys_email(email: &str, conn: &DbConn) -> ApiResult<(String, String, String, String)> { - let data = User::find_by_mail(email, &conn) - .and_then(|u| get_user_duo_data(&u.uuid, &conn).data()) + let data = User::find_by_mail(email, conn) + .and_then(|u| get_user_duo_data(&u.uuid, conn).data()) .or_else(DuoData::global) .map_res("Can't fetch Duo keys")?; diff --git a/src/api/core/two_factor/email.rs b/src/api/core/two_factor/email.rs index c47f9498..f9b03499 100644 --- a/src/api/core/two_factor/email.rs +++ b/src/api/core/two_factor/email.rs @@ -56,14 +56,14 @@ fn send_email_login(data: JsonUpcase, conn: DbConn) -> Empty /// Generate the token, save the data for later verification and send email to user pub fn send_token(user_uuid: &str, conn: &DbConn) -> EmptyResult { let type_ = TwoFactorType::Email as i32; - let mut twofactor = TwoFactor::find_by_user_and_type(user_uuid, type_, &conn).map_res("Two factor not found")?; + let mut twofactor = TwoFactor::find_by_user_and_type(user_uuid, type_, conn).map_res("Two factor not found")?; let generated_token = crypto::generate_token(CONFIG.email_token_size())?; let mut twofactor_data = EmailTokenData::from_json(&twofactor.data)?; twofactor_data.set_token(generated_token); twofactor.data = twofactor_data.to_json(); - twofactor.save(&conn)?; + twofactor.save(conn)?; mail::send_token(&twofactor_data.email, &twofactor_data.last_token.map_res("Token is empty")?)?; @@ -181,8 +181,8 @@ fn email(data: JsonUpcase, headers: Headers, conn: DbConn) -> JsonRes /// Validate the email code when used as TwoFactor token mechanism pub fn validate_email_code_str(user_uuid: &str, token: &str, data: &str, conn: &DbConn) -> EmptyResult { - let mut email_data = EmailTokenData::from_json(&data)?; - let mut twofactor = TwoFactor::find_by_user_and_type(&user_uuid, TwoFactorType::Email as i32, &conn) + let mut email_data = EmailTokenData::from_json(data)?; + let mut twofactor = TwoFactor::find_by_user_and_type(user_uuid, TwoFactorType::Email as i32, conn) .map_res("Two factor not found")?; let issued_token = match &email_data.last_token { Some(t) => t, @@ -195,14 +195,14 @@ pub fn validate_email_code_str(user_uuid: &str, token: &str, data: &str, conn: & email_data.reset_token(); } twofactor.data = email_data.to_json(); - twofactor.save(&conn)?; + twofactor.save(conn)?; err!("Token is invalid") } email_data.reset_token(); twofactor.data = email_data.to_json(); - twofactor.save(&conn)?; + twofactor.save(conn)?; let date = NaiveDateTime::from_timestamp(email_data.token_sent, 0); let max_time = CONFIG.email_expiration_time() as i64; @@ -255,7 +255,7 @@ impl EmailTokenData { } pub fn from_json(string: &str) -> Result { - let res: Result = serde_json::from_str(&string); + let res: Result = serde_json::from_str(string); match res { Ok(x) => Ok(x), Err(_) => err!("Could not decode EmailTokenData from string"), @@ -292,7 +292,7 @@ mod tests { fn test_obscure_email_long() { let email = "bytes@example.ext"; - let result = obscure_email(&email); + let result = obscure_email(email); // Only first two characters should be visible. assert_eq!(result, "by***@example.ext"); @@ -302,7 +302,7 @@ mod tests { fn test_obscure_email_short() { let email = "byt@example.ext"; - let result = obscure_email(&email); + let result = obscure_email(email); // If it's smaller than 3 characters it should only show asterisks. assert_eq!(result, "***@example.ext"); diff --git a/src/api/core/two_factor/u2f.rs b/src/api/core/two_factor/u2f.rs index bd40076d..f3d42c3e 100644 --- a/src/api/core/two_factor/u2f.rs +++ b/src/api/core/two_factor/u2f.rs @@ -248,7 +248,7 @@ fn _create_u2f_challenge(user_uuid: &str, type_: TwoFactorType, conn: &DbConn) - } fn save_u2f_registrations(user_uuid: &str, regs: &[U2FRegistration], conn: &DbConn) -> EmptyResult { - TwoFactor::new(user_uuid.into(), TwoFactorType::U2f, serde_json::to_string(regs)?).save(&conn) + TwoFactor::new(user_uuid.into(), TwoFactorType::U2f, serde_json::to_string(regs)?).save(conn) } fn get_u2f_registrations(user_uuid: &str, conn: &DbConn) -> Result<(bool, Vec), Error> { @@ -279,7 +279,7 @@ fn get_u2f_registrations(user_uuid: &str, conn: &DbConn) -> Result<(bool, Vec ApiResult EmptyResult { let challenge_type = TwoFactorType::U2fLoginChallenge as i32; - let tf_challenge = TwoFactor::find_by_user_and_type(user_uuid, challenge_type, &conn); + let tf_challenge = TwoFactor::find_by_user_and_type(user_uuid, challenge_type, conn); let challenge = match tf_challenge { Some(tf_challenge) => { let challenge: Challenge = serde_json::from_str(&tf_challenge.data)?; - tf_challenge.delete(&conn)?; + tf_challenge.delete(conn)?; challenge } None => err!("Can't recover login challenge"), @@ -332,13 +332,13 @@ pub fn validate_u2f_login(user_uuid: &str, response: &str, conn: &DbConn) -> Emp match response { Ok(new_counter) => { reg.counter = new_counter; - save_u2f_registrations(user_uuid, ®istrations, &conn)?; + save_u2f_registrations(user_uuid, ®istrations, conn)?; return Ok(()); } Err(u2f::u2ferror::U2fError::CounterTooLow) => { reg.compromised = true; - save_u2f_registrations(user_uuid, ®istrations, &conn)?; + save_u2f_registrations(user_uuid, ®istrations, conn)?; err!("This device might be compromised!"); } diff --git a/src/api/core/two_factor/webauthn.rs b/src/api/core/two_factor/webauthn.rs index 567ddce0..e68b134b 100644 --- a/src/api/core/two_factor/webauthn.rs +++ b/src/api/core/two_factor/webauthn.rs @@ -128,7 +128,7 @@ fn generate_webauthn_challenge(data: JsonUpcase, headers: Headers, )?; let type_ = TwoFactorType::WebauthnRegisterChallenge; - TwoFactor::new(headers.user.uuid.clone(), type_, serde_json::to_string(&state)?).save(&conn)?; + TwoFactor::new(headers.user.uuid, type_, serde_json::to_string(&state)?).save(&conn)?; let mut challenge_value = serde_json::to_value(challenge.public_key)?; challenge_value["status"] = "ok".into(); @@ -354,7 +354,7 @@ pub fn generate_webauthn_login(user_uuid: &str, conn: &DbConn) -> JsonResult { // Save the challenge state for later validation TwoFactor::new(user_uuid.into(), TwoFactorType::WebauthnLoginChallenge, serde_json::to_string(&state)?) - .save(&conn)?; + .save(conn)?; // Return challenge to the clients Ok(Json(serde_json::to_value(response.public_key)?)) @@ -365,7 +365,7 @@ pub fn validate_webauthn_login(user_uuid: &str, response: &str, conn: &DbConn) - let state = match TwoFactor::find_by_user_and_type(user_uuid, type_, conn) { Some(tf) => { let state: AuthenticationState = serde_json::from_str(&tf.data)?; - tf.delete(&conn)?; + tf.delete(conn)?; state } None => err!("Can't recover login challenge"), @@ -385,7 +385,7 @@ pub fn validate_webauthn_login(user_uuid: &str, response: &str, conn: &DbConn) - reg.credential.counter = auth_data.counter; TwoFactor::new(user_uuid.to_string(), TwoFactorType::Webauthn, serde_json::to_string(®istrations)?) - .save(&conn)?; + .save(conn)?; return Ok(()); } } diff --git a/src/api/icons.rs b/src/api/icons.rs index f085678a..36eb286c 100644 --- a/src/api/icons.rs +++ b/src/api/icons.rs @@ -249,7 +249,7 @@ fn is_domain_blacklisted(domain: &str) -> bool { }; // Use the pre-generate Regex stored in a Lazy HashMap. - if regex.is_match(&domain) { + if regex.is_match(domain) { warn!("Blacklisted domain: {:#?} matched {:#?}", domain, blacklist); is_blacklisted = true; } @@ -280,7 +280,7 @@ fn get_icon(domain: &str) -> Option<(Vec, String)> { } // Get the icon, or None in case of error - match download_icon(&domain) { + match download_icon(domain) { Ok((icon, icon_type)) => { save_icon(&path, &icon); Some((icon, icon_type.unwrap_or("x-icon").to_string())) @@ -431,7 +431,7 @@ fn get_favicons_node(node: &std::rc::Rc, icons: &mut Ve if has_rel { if let Some(inner_href) = href { - if let Ok(full_href) = url.join(&inner_href).map(String::from) { + if let Ok(full_href) = url.join(inner_href).map(String::from) { let priority = get_icon_priority(&full_href, sizes); icons.push(Icon::new(priority, full_href)); } @@ -650,7 +650,7 @@ fn download_icon(domain: &str) -> Result<(Vec, Option<&str>), Error> { err!("Domain is blacklisted", domain) } - let icon_result = get_icon_url(&domain)?; + let icon_result = get_icon_url(domain)?; let mut buffer = Vec::new(); let mut icon_type: Option<&str> = None; diff --git a/src/api/identity.rs b/src/api/identity.rs index 9f9dde66..1c1ab233 100644 --- a/src/api/identity.rs +++ b/src/api/identity.rs @@ -134,7 +134,7 @@ fn _password_login(data: ConnectData, conn: DbConn, ip: &ClientIp) -> JsonResult let (mut device, new_device) = get_device(&data, &conn, &user); - let twofactor_token = twofactor_auth(&user.uuid, &data, &mut device, &ip, &conn)?; + let twofactor_token = twofactor_auth(&user.uuid, &data, &mut device, ip, &conn)?; if CONFIG.mail_enabled() && new_device { if let Err(e) = mail::send_new_device_logged_in(&user.email, &ip.ip.to_string(), &now, &device.name) { @@ -185,7 +185,7 @@ fn get_device(data: &ConnectData, conn: &DbConn, user: &User) -> (Device, bool) let mut new_device = false; // Find device or create new - let device = match Device::find_by_uuid(&device_id, &conn) { + let device = match Device::find_by_uuid(&device_id, conn) { Some(device) => { // Check if owned device, and recreate if not if device.user_uuid != user.uuid { @@ -316,7 +316,7 @@ fn _json_err_twofactor(providers: &[i32], user_uuid: &str, conn: &DbConn) -> Api } Some(TwoFactorType::Duo) => { - let email = match User::find_by_uuid(user_uuid, &conn) { + let email = match User::find_by_uuid(user_uuid, conn) { Some(u) => u.email, None => err!("User does not exist"), }; @@ -330,7 +330,7 @@ fn _json_err_twofactor(providers: &[i32], user_uuid: &str, conn: &DbConn) -> Api } Some(tf_type @ TwoFactorType::YubiKey) => { - let twofactor = match TwoFactor::find_by_user_and_type(user_uuid, tf_type as i32, &conn) { + let twofactor = match TwoFactor::find_by_user_and_type(user_uuid, tf_type as i32, conn) { Some(tf) => tf, None => err!("No YubiKey devices registered"), }; @@ -345,14 +345,14 @@ fn _json_err_twofactor(providers: &[i32], user_uuid: &str, conn: &DbConn) -> Api Some(tf_type @ TwoFactorType::Email) => { use crate::api::core::two_factor as _tf; - let twofactor = match TwoFactor::find_by_user_and_type(user_uuid, tf_type as i32, &conn) { + let twofactor = match TwoFactor::find_by_user_and_type(user_uuid, tf_type as i32, conn) { Some(tf) => tf, None => err!("No twofactor email registered"), }; // Send email immediately if email is the only 2FA option if providers.len() == 1 { - _tf::email::send_token(&user_uuid, &conn)? + _tf::email::send_token(user_uuid, conn)? } let email_data = EmailTokenData::from_json(&twofactor.data)?; diff --git a/src/api/mod.rs b/src/api/mod.rs index dca32f1f..f16503d2 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -51,6 +51,7 @@ impl NumberOrString { } } + #[allow(clippy::wrong_self_convention)] fn into_i32(&self) -> ApiResult { use std::num::ParseIntError as PIE; match self { diff --git a/src/api/notifications.rs b/src/api/notifications.rs index a64ea9d8..e93598dc 100644 --- a/src/api/notifications.rs +++ b/src/api/notifications.rs @@ -332,7 +332,7 @@ impl WebSocketUsers { ); for uuid in user_uuids { - self.send_update(&uuid, &data).ok(); + self.send_update(uuid, &data).ok(); } } } diff --git a/src/config.rs b/src/config.rs index dd6e0f07..73a8f886 100644 --- a/src/config.rs +++ b/src/config.rs @@ -81,20 +81,16 @@ macro_rules! make_config { dotenv::Error::Io(ioerr) => match ioerr.kind() { std::io::ErrorKind::NotFound => { println!("[INFO] No .env file found.\n"); - () }, std::io::ErrorKind::PermissionDenied => { println!("[WARNING] Permission Denied while trying to read the .env file!\n"); - () }, _ => { println!("[WARNING] Reading the .env file failed:\n{:?}\n", ioerr); - () } }, _ => { println!("[WARNING] Reading the .env file failed:\n{:?}\n", e); - () } } }; @@ -610,7 +606,7 @@ fn validate_config(cfg: &ConfigItems) -> Result<(), Error> { // Check if the icon blacklist regex is valid if let Some(ref r) = cfg.icon_blacklist_regex { - let validate_regex = Regex::new(&r); + let validate_regex = Regex::new(r); match validate_regex { Ok(_) => (), Err(e) => err!(format!("`ICON_BLACKLIST_REGEX` is invalid: {:#?}", e)), diff --git a/src/db/models/attachment.rs b/src/db/models/attachment.rs index cf25acdc..04ad8990 100644 --- a/src/db/models/attachment.rs +++ b/src/db/models/attachment.rs @@ -117,8 +117,8 @@ impl Attachment { } pub fn delete_all_by_cipher(cipher_uuid: &str, conn: &DbConn) -> EmptyResult { - for attachment in Attachment::find_by_cipher(&cipher_uuid, &conn) { - attachment.delete(&conn)?; + for attachment in Attachment::find_by_cipher(cipher_uuid, conn) { + attachment.delete(conn)?; } Ok(()) } diff --git a/src/db/models/cipher.rs b/src/db/models/cipher.rs index 355efe68..437934c7 100644 --- a/src/db/models/cipher.rs +++ b/src/db/models/cipher.rs @@ -97,7 +97,7 @@ impl Cipher { let password_history_json = self.password_history.as_ref().and_then(|s| serde_json::from_str(s).ok()).unwrap_or(Value::Null); - let (read_only, hide_passwords) = match self.get_access_restrictions(&user_uuid, conn) { + let (read_only, hide_passwords) = match self.get_access_restrictions(user_uuid, conn) { Some((ro, hp)) => (ro, hp), None => { error!("Cipher ownership assertion failure"); @@ -144,8 +144,8 @@ impl Cipher { "Type": self.atype, "RevisionDate": format_date(&self.updated_at), "DeletedDate": self.deleted_at.map_or(Value::Null, |d| Value::String(format_date(&d))), - "FolderId": self.get_folder_uuid(&user_uuid, conn), - "Favorite": self.is_favorite(&user_uuid, conn), + "FolderId": self.get_folder_uuid(user_uuid, conn), + "Favorite": self.is_favorite(user_uuid, conn), "Reprompt": self.reprompt.unwrap_or(RepromptType::None as i32), "OrganizationId": self.organization_uuid, "Attachments": attachments_json, @@ -193,13 +193,13 @@ impl Cipher { let mut user_uuids = Vec::new(); match self.user_uuid { Some(ref user_uuid) => { - User::update_uuid_revision(&user_uuid, conn); + User::update_uuid_revision(user_uuid, conn); user_uuids.push(user_uuid.clone()) } None => { // Belongs to Organization, need to update affected users if let Some(ref org_uuid) = self.organization_uuid { - UserOrganization::find_by_cipher_and_org(&self.uuid, &org_uuid, conn).iter().for_each(|user_org| { + UserOrganization::find_by_cipher_and_org(&self.uuid, org_uuid, conn).iter().for_each(|user_org| { User::update_uuid_revision(&user_org.user_uuid, conn); user_uuids.push(user_org.user_uuid.clone()) }); @@ -260,15 +260,15 @@ impl Cipher { } pub fn delete_all_by_organization(org_uuid: &str, conn: &DbConn) -> EmptyResult { - for cipher in Self::find_by_org(org_uuid, &conn) { - cipher.delete(&conn)?; + for cipher in Self::find_by_org(org_uuid, conn) { + cipher.delete(conn)?; } Ok(()) } pub fn delete_all_by_user(user_uuid: &str, conn: &DbConn) -> EmptyResult { - for cipher in Self::find_owned_by_user(user_uuid, &conn) { - cipher.delete(&conn)?; + for cipher in Self::find_owned_by_user(user_uuid, conn) { + cipher.delete(conn)?; } Ok(()) } @@ -279,7 +279,7 @@ impl Cipher { let now = Utc::now().naive_utc(); let dt = now - Duration::days(auto_delete_days); for cipher in Self::find_deleted_before(&dt, conn) { - cipher.delete(&conn).ok(); + cipher.delete(conn).ok(); } } } @@ -287,7 +287,7 @@ impl Cipher { pub fn move_to_folder(&self, folder_uuid: Option, user_uuid: &str, conn: &DbConn) -> EmptyResult { User::update_uuid_revision(user_uuid, conn); - match (self.get_folder_uuid(&user_uuid, conn), folder_uuid) { + match (self.get_folder_uuid(user_uuid, conn), folder_uuid) { // No changes (None, None) => Ok(()), (Some(ref old), Some(ref new)) if old == new => Ok(()), @@ -319,7 +319,7 @@ impl Cipher { /// Returns whether this cipher is owned by an org in which the user has full access. pub fn is_in_full_access_org(&self, user_uuid: &str, conn: &DbConn) -> bool { if let Some(ref org_uuid) = self.organization_uuid { - if let Some(user_org) = UserOrganization::find_by_user_and_org(&user_uuid, &org_uuid, conn) { + if let Some(user_org) = UserOrganization::find_by_user_and_org(user_uuid, org_uuid, conn) { return user_org.has_full_access(); } } @@ -336,7 +336,7 @@ impl Cipher { // Check whether this cipher is directly owned by the user, or is in // a collection that the user has full access to. If so, there are no // access restrictions. - if self.is_owned_by_user(&user_uuid) || self.is_in_full_access_org(&user_uuid, &conn) { + if self.is_owned_by_user(user_uuid) || self.is_in_full_access_org(user_uuid, conn) { return Some((false, false)); } @@ -377,14 +377,14 @@ impl Cipher { } pub fn is_write_accessible_to_user(&self, user_uuid: &str, conn: &DbConn) -> bool { - match self.get_access_restrictions(&user_uuid, &conn) { + match self.get_access_restrictions(user_uuid, conn) { Some((read_only, _hide_passwords)) => !read_only, None => false, } } pub fn is_accessible_to_user(&self, user_uuid: &str, conn: &DbConn) -> bool { - self.get_access_restrictions(&user_uuid, &conn).is_some() + self.get_access_restrictions(user_uuid, conn).is_some() } // Returns whether this cipher is a favorite of the specified user. diff --git a/src/db/models/collection.rs b/src/db/models/collection.rs index 88e11c6e..2073ca17 100644 --- a/src/db/models/collection.rs +++ b/src/db/models/collection.rs @@ -109,8 +109,8 @@ impl Collection { pub fn delete(self, conn: &DbConn) -> EmptyResult { self.update_users_revision(conn); - CollectionCipher::delete_all_by_collection(&self.uuid, &conn)?; - CollectionUser::delete_all_by_collection(&self.uuid, &conn)?; + CollectionCipher::delete_all_by_collection(&self.uuid, conn)?; + CollectionUser::delete_all_by_collection(&self.uuid, conn)?; db_run! { conn: { diesel::delete(collections::table.filter(collections::uuid.eq(self.uuid))) @@ -120,8 +120,8 @@ impl Collection { } pub fn delete_all_by_organization(org_uuid: &str, conn: &DbConn) -> EmptyResult { - for collection in Self::find_by_organization(org_uuid, &conn) { - collection.delete(&conn)?; + for collection in Self::find_by_organization(org_uuid, conn) { + collection.delete(conn)?; } Ok(()) } @@ -220,7 +220,7 @@ impl Collection { } pub fn is_writable_by_user(&self, user_uuid: &str, conn: &DbConn) -> bool { - match UserOrganization::find_by_user_and_org(&user_uuid, &self.org_uuid, &conn) { + match UserOrganization::find_by_user_and_org(user_uuid, &self.org_uuid, conn) { None => false, // Not in Org Some(user_org) => { if user_org.has_full_access() { @@ -242,7 +242,7 @@ impl Collection { } pub fn hide_passwords_for_user(&self, user_uuid: &str, conn: &DbConn) -> bool { - match UserOrganization::find_by_user_and_org(&user_uuid, &self.org_uuid, &conn) { + match UserOrganization::find_by_user_and_org(user_uuid, &self.org_uuid, conn) { None => true, // Not in Org Some(user_org) => { if user_org.has_full_access() { @@ -286,7 +286,7 @@ impl CollectionUser { hide_passwords: bool, conn: &DbConn, ) -> EmptyResult { - User::update_uuid_revision(&user_uuid, conn); + User::update_uuid_revision(user_uuid, conn); db_run! { conn: sqlite, mysql { @@ -375,7 +375,7 @@ impl CollectionUser { } pub fn delete_all_by_collection(collection_uuid: &str, conn: &DbConn) -> EmptyResult { - CollectionUser::find_by_collection(&collection_uuid, conn).iter().for_each(|collection| { + CollectionUser::find_by_collection(collection_uuid, conn).iter().for_each(|collection| { User::update_uuid_revision(&collection.user_uuid, conn); }); @@ -406,7 +406,7 @@ impl CollectionUser { /// Database methods impl CollectionCipher { pub fn save(cipher_uuid: &str, collection_uuid: &str, conn: &DbConn) -> EmptyResult { - Self::update_users_revision(&collection_uuid, conn); + Self::update_users_revision(collection_uuid, conn); db_run! { conn: sqlite, mysql { @@ -436,7 +436,7 @@ impl CollectionCipher { } pub fn delete(cipher_uuid: &str, collection_uuid: &str, conn: &DbConn) -> EmptyResult { - Self::update_users_revision(&collection_uuid, conn); + Self::update_users_revision(collection_uuid, conn); db_run! { conn: { diesel::delete( diff --git a/src/db/models/device.rs b/src/db/models/device.rs index 77837fca..1633ceba 100644 --- a/src/db/models/device.rs +++ b/src/db/models/device.rs @@ -143,8 +143,8 @@ impl Device { } pub fn delete_all_by_user(user_uuid: &str, conn: &DbConn) -> EmptyResult { - for device in Self::find_by_user(user_uuid, &conn) { - device.delete(&conn)?; + for device in Self::find_by_user(user_uuid, conn) { + device.delete(conn)?; } Ok(()) } diff --git a/src/db/models/favorite.rs b/src/db/models/favorite.rs index 2fc20380..cb3e3420 100644 --- a/src/db/models/favorite.rs +++ b/src/db/models/favorite.rs @@ -32,10 +32,10 @@ impl Favorite { // Sets whether the specified cipher is a favorite of the specified user. pub fn set_favorite(favorite: bool, cipher_uuid: &str, user_uuid: &str, conn: &DbConn) -> EmptyResult { - let (old, new) = (Self::is_favorite(cipher_uuid, user_uuid, &conn), favorite); + let (old, new) = (Self::is_favorite(cipher_uuid, user_uuid, conn), favorite); match (old, new) { (false, true) => { - User::update_uuid_revision(user_uuid, &conn); + User::update_uuid_revision(user_uuid, conn); db_run! { conn: { diesel::insert_into(favorites::table) .values(( @@ -47,7 +47,7 @@ impl Favorite { }} } (true, false) => { - User::update_uuid_revision(user_uuid, &conn); + User::update_uuid_revision(user_uuid, conn); db_run! { conn: { diesel::delete( favorites::table diff --git a/src/db/models/folder.rs b/src/db/models/folder.rs index ec83d117..d51e71b4 100644 --- a/src/db/models/folder.rs +++ b/src/db/models/folder.rs @@ -107,7 +107,7 @@ impl Folder { pub fn delete(&self, conn: &DbConn) -> EmptyResult { User::update_uuid_revision(&self.user_uuid, conn); - FolderCipher::delete_all_by_folder(&self.uuid, &conn)?; + FolderCipher::delete_all_by_folder(&self.uuid, conn)?; db_run! { conn: { diesel::delete(folders::table.filter(folders::uuid.eq(&self.uuid))) @@ -117,8 +117,8 @@ impl Folder { } pub fn delete_all_by_user(user_uuid: &str, conn: &DbConn) -> EmptyResult { - for folder in Self::find_by_user(user_uuid, &conn) { - folder.delete(&conn)?; + for folder in Self::find_by_user(user_uuid, conn) { + folder.delete(conn)?; } Ok(()) } diff --git a/src/db/models/organization.rs b/src/db/models/organization.rs index c5d36ff7..e0c87977 100644 --- a/src/db/models/organization.rs +++ b/src/db/models/organization.rs @@ -228,10 +228,10 @@ impl Organization { pub fn delete(self, conn: &DbConn) -> EmptyResult { use super::{Cipher, Collection}; - Cipher::delete_all_by_organization(&self.uuid, &conn)?; - Collection::delete_all_by_organization(&self.uuid, &conn)?; - UserOrganization::delete_all_by_organization(&self.uuid, &conn)?; - OrgPolicy::delete_all_by_organization(&self.uuid, &conn)?; + Cipher::delete_all_by_organization(&self.uuid, conn)?; + Collection::delete_all_by_organization(&self.uuid, conn)?; + UserOrganization::delete_all_by_organization(&self.uuid, conn)?; + OrgPolicy::delete_all_by_organization(&self.uuid, conn)?; db_run! { conn: { diesel::delete(organizations::table.filter(organizations::uuid.eq(self.uuid))) @@ -402,7 +402,7 @@ impl UserOrganization { pub fn delete(self, conn: &DbConn) -> EmptyResult { User::update_uuid_revision(&self.user_uuid, conn); - CollectionUser::delete_all_by_user_and_org(&self.user_uuid, &self.org_uuid, &conn)?; + CollectionUser::delete_all_by_user_and_org(&self.user_uuid, &self.org_uuid, conn)?; db_run! { conn: { diesel::delete(users_organizations::table.filter(users_organizations::uuid.eq(self.uuid))) @@ -412,22 +412,22 @@ impl UserOrganization { } pub fn delete_all_by_organization(org_uuid: &str, conn: &DbConn) -> EmptyResult { - for user_org in Self::find_by_org(&org_uuid, &conn) { - user_org.delete(&conn)?; + for user_org in Self::find_by_org(org_uuid, conn) { + user_org.delete(conn)?; } Ok(()) } pub fn delete_all_by_user(user_uuid: &str, conn: &DbConn) -> EmptyResult { - for user_org in Self::find_any_state_by_user(&user_uuid, &conn) { - user_org.delete(&conn)?; + for user_org in Self::find_any_state_by_user(user_uuid, conn) { + user_org.delete(conn)?; } Ok(()) } pub fn find_by_email_and_org(email: &str, org_id: &str, conn: &DbConn) -> Option { if let Some(user) = super::User::find_by_mail(email, conn) { - if let Some(user_org) = UserOrganization::find_by_user_and_org(&user.uuid, org_id, &conn) { + if let Some(user_org) = UserOrganization::find_by_user_and_org(&user.uuid, org_id, conn) { return Some(user_org); } } diff --git a/src/db/models/send.rs b/src/db/models/send.rs index 20c7cc50..1fae40c8 100644 --- a/src/db/models/send.rs +++ b/src/db/models/send.rs @@ -227,15 +227,15 @@ impl Send { /// Purge all sends that are past their deletion date. pub fn purge(conn: &DbConn) { - for send in Self::find_by_past_deletion_date(&conn) { - send.delete(&conn).ok(); + for send in Self::find_by_past_deletion_date(conn) { + send.delete(conn).ok(); } } pub fn update_users_revision(&self, conn: &DbConn) { match &self.user_uuid { Some(user_uuid) => { - User::update_uuid_revision(&user_uuid, conn); + User::update_uuid_revision(user_uuid, conn); } None => { // Belongs to Organization, not implemented @@ -244,8 +244,8 @@ impl Send { } pub fn delete_all_by_user(user_uuid: &str, conn: &DbConn) -> EmptyResult { - for send in Self::find_by_user(user_uuid, &conn) { - send.delete(&conn)?; + for send in Self::find_by_user(user_uuid, conn) { + send.delete(conn)?; } Ok(()) } diff --git a/src/db/models/two_factor.rs b/src/db/models/two_factor.rs index bbfb7529..6b400889 100644 --- a/src/db/models/two_factor.rs +++ b/src/db/models/two_factor.rs @@ -171,7 +171,7 @@ impl TwoFactor { continue; } - let (_, mut webauthn_regs) = get_webauthn_registrations(&u2f.user_uuid, &conn)?; + let (_, mut webauthn_regs) = get_webauthn_registrations(&u2f.user_uuid, conn)?; // If the user already has webauthn registrations saved, don't overwrite them if !webauthn_regs.is_empty() { @@ -210,10 +210,10 @@ impl TwoFactor { } u2f.data = serde_json::to_string(®s)?; - u2f.save(&conn)?; + u2f.save(conn)?; TwoFactor::new(u2f.user_uuid.clone(), TwoFactorType::Webauthn, serde_json::to_string(&webauthn_regs)?) - .save(&conn)?; + .save(conn)?; } Ok(()) diff --git a/src/db/models/user.rs b/src/db/models/user.rs index 5c29eaa6..5b2e1131 100644 --- a/src/db/models/user.rs +++ b/src/db/models/user.rs @@ -187,7 +187,7 @@ use crate::error::MapResult; impl User { pub fn to_json(&self, conn: &DbConn) -> Value { let orgs = UserOrganization::find_by_user(&self.uuid, conn); - let orgs_json: Vec = orgs.iter().map(|c| c.to_json(&conn)).collect(); + let orgs_json: Vec = orgs.iter().map(|c| c.to_json(conn)).collect(); let twofactor_enabled = !TwoFactor::find_by_user(&self.uuid, conn).is_empty(); // TODO: Might want to save the status field in the DB @@ -398,8 +398,8 @@ impl Invitation { } pub fn take(mail: &str, conn: &DbConn) -> bool { - match Self::find_by_mail(mail, &conn) { - Some(invitation) => invitation.delete(&conn).is_ok(), + match Self::find_by_mail(mail, conn) { + Some(invitation) => invitation.delete(conn).is_ok(), None => false, } } diff --git a/src/error.rs b/src/error.rs index e3a9c239..b1994560 100644 --- a/src/error.rs +++ b/src/error.rs @@ -61,31 +61,31 @@ pub struct Empty {} // The second one contains the function used to obtain the response sent to the client make_error! { // Just an empty error - EmptyError(Empty): _no_source, _serialize, + Empty(Empty): _no_source, _serialize, // Used to represent err! calls - SimpleError(String): _no_source, _api_error, + Simple(String): _no_source, _api_error, // Used for special return values, like 2FA errors - JsonError(Value): _no_source, _serialize, - DbError(DieselErr): _has_source, _api_error, - R2d2Error(R2d2Err): _has_source, _api_error, - U2fError(U2fErr): _has_source, _api_error, - SerdeError(SerdeErr): _has_source, _api_error, - JWtError(JwtErr): _has_source, _api_error, - TemplError(HbErr): _has_source, _api_error, + Json(Value): _no_source, _serialize, + Db(DieselErr): _has_source, _api_error, + R2d2(R2d2Err): _has_source, _api_error, + U2f(U2fErr): _has_source, _api_error, + Serde(SerdeErr): _has_source, _api_error, + JWt(JwtErr): _has_source, _api_error, + Handlebars(HbErr): _has_source, _api_error, //WsError(ws::Error): _has_source, _api_error, - IoError(IoErr): _has_source, _api_error, - TimeError(TimeErr): _has_source, _api_error, - ReqError(ReqErr): _has_source, _api_error, - RegexError(RegexErr): _has_source, _api_error, - YubiError(YubiErr): _has_source, _api_error, + Io(IoErr): _has_source, _api_error, + Time(TimeErr): _has_source, _api_error, + Req(ReqErr): _has_source, _api_error, + Regex(RegexErr): _has_source, _api_error, + Yubico(YubiErr): _has_source, _api_error, - LettreError(LettreErr): _has_source, _api_error, - AddressError(AddrErr): _has_source, _api_error, - SmtpError(SmtpErr): _has_source, _api_error, + Lettre(LettreErr): _has_source, _api_error, + Address(AddrErr): _has_source, _api_error, + Smtp(SmtpErr): _has_source, _api_error, - DieselConError(DieselConErr): _has_source, _api_error, - DieselMigError(DieselMigErr): _has_source, _api_error, - WebauthnError(WebauthnErr): _has_source, _api_error, + DieselCon(DieselConErr): _has_source, _api_error, + DieselMig(DieselMigErr): _has_source, _api_error, + Webauthn(WebauthnErr): _has_source, _api_error, } impl std::fmt::Debug for Error { @@ -93,15 +93,15 @@ impl std::fmt::Debug for Error { match self.source() { Some(e) => write!(f, "{}.\n[CAUSE] {:#?}", self.message, e), None => match self.error { - ErrorKind::EmptyError(_) => Ok(()), - ErrorKind::SimpleError(ref s) => { + ErrorKind::Empty(_) => Ok(()), + ErrorKind::Simple(ref s) => { if &self.message == s { write!(f, "{}", self.message) } else { write!(f, "{}. {}", self.message, s) } } - ErrorKind::JsonError(_) => write!(f, "{}", self.message), + ErrorKind::Json(_) => write!(f, "{}", self.message), _ => unreachable!(), }, } @@ -189,8 +189,8 @@ use rocket::response::{self, Responder, Response}; impl<'r> Responder<'r> for Error { fn respond_to(self, _: &Request) -> response::Result<'r> { match self.error { - ErrorKind::EmptyError(_) => {} // Don't print the error in this situation - ErrorKind::SimpleError(_) => {} // Don't print the error in this situation + ErrorKind::Empty(_) => {} // Don't print the error in this situation + ErrorKind::Simple(_) => {} // Don't print the error in this situation _ => error!(target: "error", "{:#?}", self), };