From d5847e60a85ee8c59e938a39d6c3dd8a41c1a5ac Mon Sep 17 00:00:00 2001 From: Stefan Melmuk Date: Mon, 28 Aug 2023 20:48:08 +0200 Subject: [PATCH] use &str instead of String in log_event() --- src/api/admin.rs | 6 ++-- src/api/core/ciphers.rs | 24 +++++---------- src/api/core/events.rs | 4 +-- src/api/core/organizations.rs | 53 +++++++++++++++++----------------- src/api/core/two_factor/mod.rs | 12 ++++---- 5 files changed, 45 insertions(+), 54 deletions(-) diff --git a/src/api/admin.rs b/src/api/admin.rs index cdbad638..a10df891 100644 --- a/src/api/admin.rs +++ b/src/api/admin.rs @@ -393,7 +393,7 @@ async fn delete_user(uuid: &str, token: AdminToken, mut conn: DbConn) -> EmptyRe EventType::OrganizationUserRemoved as i32, &user_org.uuid, &user_org.org_uuid, - String::from(ACTING_ADMIN_USER), + ACTING_ADMIN_USER, 14, // Use UnknownBrowser type &token.ip.ip, &mut conn, @@ -451,7 +451,7 @@ async fn enable_user(uuid: &str, _token: AdminToken, mut conn: DbConn) -> EmptyR async fn remove_2fa(uuid: &str, token: AdminToken, mut conn: DbConn) -> EmptyResult { let mut user = get_user_or_404(uuid, &mut conn).await?; TwoFactor::delete_all_by_user(&user.uuid, &mut conn).await?; - two_factor::enforce_2fa_policy(&user, String::from(ACTING_ADMIN_USER), 14, &token.ip.ip, &mut conn).await?; + two_factor::enforce_2fa_policy(&user, ACTING_ADMIN_USER, 14, &token.ip.ip, &mut conn).await?; user.totp_recover = None; user.save(&mut conn).await } @@ -521,7 +521,7 @@ async fn update_user_org_type(data: Json, token: AdminToken, mu EventType::OrganizationUserUpdated as i32, &user_to_edit.uuid, &data.org_uuid, - String::from(ACTING_ADMIN_USER), + ACTING_ADMIN_USER, 14, // Use UnknownBrowser type &token.ip.ip, &mut conn, diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index 0410d68e..a4a2d836 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -510,7 +510,7 @@ pub async fn update_cipher_from_data( event_type as i32, &cipher.uuid, org_uuid, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, conn, @@ -791,7 +791,7 @@ async fn post_collections_admin( EventType::CipherUpdatedCollections as i32, &cipher.uuid, &cipher.organization_uuid.unwrap(), - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -1145,7 +1145,7 @@ async fn save_attachment( EventType::CipherAttachmentCreated as i32, &cipher.uuid, org_uuid, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -1479,7 +1479,7 @@ async fn delete_all( EventType::OrganizationPurgedVault as i32, &org_data.org_id, &org_data.org_id, - user.uuid, + &user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -1560,16 +1560,8 @@ async fn _delete_cipher_by_uuid( false => EventType::CipherDeleted as i32, }; - log_event( - event_type, - &cipher.uuid, - &org_uuid, - headers.user.uuid.clone(), - headers.device.atype, - &headers.ip.ip, - conn, - ) - .await; + log_event(event_type, &cipher.uuid, &org_uuid, &headers.user.uuid, headers.device.atype, &headers.ip.ip, conn) + .await; } Ok(()) @@ -1629,7 +1621,7 @@ async fn _restore_cipher_by_uuid(uuid: &str, headers: &Headers, conn: &mut DbCon EventType::CipherRestored as i32, &cipher.uuid.clone(), org_uuid, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, conn, @@ -1713,7 +1705,7 @@ async fn _delete_cipher_attachment_by_id( EventType::CipherAttachmentDeleted as i32, &cipher.uuid, &org_uuid, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, conn, diff --git a/src/api/core/events.rs b/src/api/core/events.rs index 70704d79..9a2027e0 100644 --- a/src/api/core/events.rs +++ b/src/api/core/events.rs @@ -263,7 +263,7 @@ pub async fn log_event( event_type: i32, source_uuid: &str, org_uuid: &str, - act_user_uuid: String, + act_user_uuid: &str, device_type: i32, ip: &IpAddr, conn: &mut DbConn, @@ -271,7 +271,7 @@ pub async fn log_event( if !CONFIG.org_events_enabled() { return; } - _log_event(event_type, source_uuid, org_uuid, &act_user_uuid, device_type, None, ip, conn).await; + _log_event(event_type, source_uuid, org_uuid, act_user_uuid, device_type, None, ip, conn).await; } #[allow(clippy::too_many_arguments)] diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs index 935cd07f..f57d8506 100644 --- a/src/api/core/organizations.rs +++ b/src/api/core/organizations.rs @@ -226,7 +226,7 @@ async fn leave_organization(org_id: &str, headers: Headers, mut conn: DbConn) -> EventType::OrganizationUserRemoved as i32, &user_org.uuid, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -279,7 +279,7 @@ async fn post_organization( EventType::OrganizationUpdated as i32, org_id, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -396,7 +396,7 @@ async fn post_organization_collections( EventType::CollectionCreated as i32, &collection.uuid, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -477,7 +477,7 @@ async fn post_organization_collection_update( EventType::CollectionUpdated as i32, &collection.uuid, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -565,7 +565,7 @@ async fn _delete_organization_collection( EventType::CollectionDeleted as i32, &collection.uuid, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, conn, @@ -946,7 +946,7 @@ async fn send_invite( EventType::OrganizationUserInvited as i32, &new_user.uuid, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -1240,7 +1240,7 @@ async fn _confirm_invite( EventType::OrganizationUserConfirmed as i32, &user_to_confirm.uuid, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, conn, @@ -1402,7 +1402,7 @@ async fn edit_user( EventType::OrganizationUserUpdated as i32, &user_to_edit.uuid, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -1494,7 +1494,7 @@ async fn _delete_user( EventType::OrganizationUserRemoved as i32, &user_to_delete.uuid, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, conn, @@ -1701,7 +1701,7 @@ async fn put_policy( if pol_type_enum == OrgPolicyType::TwoFactorAuthentication && data.enabled { two_factor::enforce_2fa_policy_for_org( org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -1731,7 +1731,7 @@ async fn put_policy( EventType::OrganizationUserRemoved as i32, &member.uuid, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -1756,7 +1756,7 @@ async fn put_policy( EventType::PolicyUpdated as i32, &policy.uuid, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -1873,7 +1873,7 @@ async fn import(org_id: &str, data: JsonUpcase, headers: Headers, EventType::OrganizationUserRemoved as i32, &user_org.uuid, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -1903,7 +1903,7 @@ async fn import(org_id: &str, data: JsonUpcase, headers: Headers, EventType::OrganizationUserInvited as i32, &new_org_user.uuid, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -1939,7 +1939,7 @@ async fn import(org_id: &str, data: JsonUpcase, headers: Headers, EventType::OrganizationUserRemoved as i32, &user_org.uuid, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -2052,7 +2052,7 @@ async fn _revoke_organization_user( EventType::OrganizationUserRevoked as i32, &user_org.uuid, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, conn, @@ -2171,7 +2171,7 @@ async fn _restore_organization_user( EventType::OrganizationUserRestored as i32, &user_org.uuid, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, conn, @@ -2300,7 +2300,7 @@ async fn post_groups( EventType::GroupCreated as i32, &group.uuid, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -2337,7 +2337,7 @@ async fn put_group( EventType::GroupUpdated as i32, &updated_group.uuid, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -2370,7 +2370,7 @@ async fn add_update_group( EventType::OrganizationUserUpdatedGroups as i32, &assigned_user_id, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, conn, @@ -2425,7 +2425,7 @@ async fn _delete_group(org_id: &str, group_id: &str, headers: &AdminHeaders, con EventType::GroupDeleted as i32, &group.uuid, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, conn, @@ -2516,7 +2516,7 @@ async fn put_group_users( EventType::OrganizationUserUpdatedGroups as i32, &assigned_user_id, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -2594,7 +2594,7 @@ async fn put_user_groups( EventType::OrganizationUserUpdatedGroups as i32, org_user_id, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -2649,7 +2649,7 @@ async fn delete_group_user( EventType::OrganizationUserUpdatedGroups as i32, org_user_id, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -2738,7 +2738,7 @@ async fn put_reset_password( EventType::OrganizationUserAdminResetPassword as i32, org_user_id, org_id, - headers.user.uuid.clone(), + &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn, @@ -2865,8 +2865,7 @@ async fn put_reset_password_enrollment( EventType::OrganizationUserResetPasswordWithdraw as i32 }; - log_event(log_id, org_user_id, org_id, headers.user.uuid.clone(), headers.device.atype, &headers.ip.ip, &mut conn) - .await; + log_event(log_id, org_user_id, org_id, &headers.user.uuid, headers.device.atype, &headers.ip.ip, &mut conn).await; Ok(()) } diff --git a/src/api/core/two_factor/mod.rs b/src/api/core/two_factor/mod.rs index 18a4a20f..9a922d26 100644 --- a/src/api/core/two_factor/mod.rs +++ b/src/api/core/two_factor/mod.rs @@ -99,7 +99,7 @@ async fn recover(data: JsonUpcase, client_headers: ClientHeade // Remove all twofactors from the user TwoFactor::delete_all_by_user(&user.uuid, &mut conn).await?; - enforce_2fa_policy(&user, user.uuid.clone(), client_headers.device_type, &client_headers.ip.ip, &mut conn).await?; + enforce_2fa_policy(&user, &user.uuid, client_headers.device_type, &client_headers.ip.ip, &mut conn).await?; log_user_event( EventType::UserRecovered2fa as i32, @@ -154,7 +154,7 @@ async fn disable_twofactor(data: JsonUpcase, headers: Head } if TwoFactor::find_by_user(&user.uuid, &mut conn).await.is_empty() { - enforce_2fa_policy(&user, user.uuid.clone(), headers.device.atype, &headers.ip.ip, &mut conn).await?; + enforce_2fa_policy(&user, &user.uuid, headers.device.atype, &headers.ip.ip, &mut conn).await?; } Ok(Json(json!({ @@ -171,7 +171,7 @@ async fn disable_twofactor_put(data: JsonUpcase, headers: pub async fn enforce_2fa_policy( user: &User, - act_uuid: String, + act_uuid: &str, device_type: i32, ip: &std::net::IpAddr, conn: &mut DbConn, @@ -194,7 +194,7 @@ pub async fn enforce_2fa_policy( EventType::OrganizationUserRevoked as i32, &member.uuid, &member.org_uuid, - act_uuid.clone(), + act_uuid, device_type, ip, conn, @@ -208,7 +208,7 @@ pub async fn enforce_2fa_policy( pub async fn enforce_2fa_policy_for_org( org_uuid: &str, - act_uuid: String, + act_uuid: &str, device_type: i32, ip: &std::net::IpAddr, conn: &mut DbConn, @@ -229,7 +229,7 @@ pub async fn enforce_2fa_policy_for_org( EventType::OrganizationUserRevoked as i32, &member.uuid, org_uuid, - act_uuid.clone(), + act_uuid, device_type, ip, conn,