Browse Source

log_user_event take enum parameter not i32

pull/7563/head
Timshel 1 week ago
parent
commit
7ab6d91a1f
  1. 12
      src/api/core/accounts.rs
  2. 4
      src/api/core/events.rs
  3. 5
      src/api/core/two_factor/authenticator.rs
  4. 5
      src/api/core/two_factor/duo.rs
  5. 5
      src/api/core/two_factor/email.rs
  6. 4
      src/api/core/two_factor/webauthn.rs
  7. 5
      src/api/core/two_factor/yubikey.rs
  8. 7
      src/api/identity.rs

12
src/api/core/accounts.rs

@ -487,8 +487,7 @@ async fn post_set_password(data: Json<SetPasswordData>, headers: Headers, conn:
Membership::accept_user_invitations(&user.uuid, &conn).await?;
}
log_user_event(EventType::UserChangedPassword as i32, &user.uuid, headers.device.atype, &headers.ip.ip, &conn)
.await;
log_user_event(EventType::UserChangedPassword, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
user.save(&conn).await?;
@ -613,8 +612,7 @@ async fn post_password(data: Json<ChangePassData>, headers: Headers, conn: DbCon
err!("Invalid password")
}
log_user_event(EventType::UserChangedPassword as i32, &user.uuid, headers.device.atype, &headers.ip.ip, &conn)
.await;
log_user_event(EventType::UserChangedPassword, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
let (new_master_password_hash, new_key) =
if let (Some(unlock_data), Some(authentication_data)) = (data.unlock_data, data.authentication_data) {
@ -1620,7 +1618,7 @@ async fn post_auth_request(
nt.send_auth_request(&user.uuid, &auth_request.uuid, &device, &conn).await;
log_user_event(
EventType::UserRequestedDeviceApproval as i32,
EventType::UserRequestedDeviceApproval,
&user.uuid,
client_headers.device_type,
&client_headers.ip.ip,
@ -1714,7 +1712,7 @@ async fn put_auth_request(
nt.send_auth_response(&auth_request.user_uuid, &auth_request.uuid, &headers.device, &conn).await;
log_user_event(
EventType::OrganizationUserApprovedAuthRequest as i32,
EventType::OrganizationUserApprovedAuthRequest,
&headers.user.uuid,
headers.device.atype,
&headers.ip.ip,
@ -1725,7 +1723,7 @@ async fn put_auth_request(
// If denied, there's no reason to keep the request
auth_request.delete(&conn).await?;
log_user_event(
EventType::OrganizationUserRejectedAuthRequest as i32,
EventType::OrganizationUserRejectedAuthRequest,
&headers.user.uuid,
headers.device.atype,
&headers.ip.ip,

4
src/api/core/events.rs

@ -225,11 +225,11 @@ async fn post_events_collect(data: Json<Vec<EventCollection>>, headers: Headers,
Ok(())
}
pub async fn log_user_event(event_type: i32, user_id: &UserId, device_type: i32, ip: &IpAddr, conn: &DbConn) {
pub async fn log_user_event(event_type: EventType, user_id: &UserId, device_type: i32, ip: &IpAddr, conn: &DbConn) {
if !CONFIG.org_events_enabled() {
return;
}
log_user_event_impl(event_type, user_id, device_type, None, ip, conn).await;
log_user_event_impl(event_type as i32, user_id, device_type, None, ip, conn).await;
}
async fn log_user_event_impl(

5
src/api/core/two_factor/authenticator.rs

@ -74,7 +74,7 @@ async fn activate_authenticator(data: Json<EnableAuthenticatorData>, headers: He
generate_recover_code(&mut user, &conn).await;
log_user_event(EventType::UserUpdated2fa as i32, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
log_user_event(EventType::UserUpdated2fa, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
Ok(Json(json!({
"authenticator": json!({
@ -186,8 +186,7 @@ async fn disable_authenticator(data: Json<DisableAuthenticatorData>, headers: He
if let Some(twofactor) = TwoFactor::find_by_user_and_type(&user.uuid, TwoFactorType::Authenticator, &conn).await {
if twofactor.data == data.key {
twofactor.delete(&conn).await?;
log_user_event(EventType::UserDisabled2fa as i32, &user.uuid, headers.device.atype, &headers.ip.ip, &conn)
.await;
log_user_event(EventType::UserDisabled2fa, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
} else {
err!(format!("TOTP key for user {} does not match recorded value, cannot deactivate", &user.email));
}

5
src/api/core/two_factor/duo.rs

@ -128,7 +128,7 @@ async fn activate_duo(data: Json<EnableDuoData>, headers: Headers, conn: DbConn)
generate_recover_code(&mut user, &conn).await;
log_user_event(EventType::UserUpdated2fa as i32, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
log_user_event(EventType::UserUpdated2fa, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
Ok(Json(json!({
"duo": json!({
@ -160,8 +160,7 @@ async fn disable_duo(data: Json<VerificationTokenData>, headers: Headers, conn:
two_factor::validate_duo(&data.user_verification_token, &user.uuid, duo.as_ref(), true)?;
twofactor.delete(&conn).await?;
log_user_event(EventType::UserDisabled2fa as i32, &user.uuid, headers.device.atype, &headers.ip.ip, &conn)
.await;
log_user_event(EventType::UserDisabled2fa, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
}
if TwoFactor::find_by_user(&user.uuid, &conn).await.is_empty() {

5
src/api/core/two_factor/email.rs

@ -224,7 +224,7 @@ async fn email(data: Json<EmailData>, headers: Headers, conn: DbConn) -> JsonRes
generate_recover_code(&mut user, &conn).await;
log_user_event(EventType::UserUpdated2fa as i32, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
log_user_event(EventType::UserUpdated2fa, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
Ok(Json(json!({})))
}
@ -238,8 +238,7 @@ async fn disable_email(data: Json<VerificationTokenData>, headers: Headers, conn
two_factor::validate_email(&data.user_verification_token, &user.uuid, twofactor_data.email, true)?;
twofactor.delete(&conn).await?;
log_user_event(EventType::UserDisabled2fa as i32, &user.uuid, headers.device.atype, &headers.ip.ip, &conn)
.await;
log_user_event(EventType::UserDisabled2fa, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
}
if TwoFactor::find_by_user(&user.uuid, &conn).await.is_empty() {

4
src/api/core/two_factor/webauthn.rs

@ -297,7 +297,7 @@ async fn activate_webauthn(data: Json<EnableWebauthnData>, headers: Headers, con
.await?;
generate_recover_code(&mut user, &conn).await;
log_user_event(EventType::UserUpdated2fa as i32, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
log_user_event(EventType::UserUpdated2fa, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
let keys_json: Vec<Value> = registrations.iter().map(WebauthnRegistration::to_json).collect();
@ -328,7 +328,7 @@ async fn delete_webauthn(data: Json<VerificationTokenData>, headers: Headers, co
two_factor::validate_webauthn(&data.user_verification_token, &user.uuid, &keys, true)?;
tf.delete(&conn).await?;
log_user_event(EventType::UserDisabled2fa as i32, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
log_user_event(EventType::UserDisabled2fa, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
let migrated: Vec<WebauthnRegistration> = removed.into_iter().filter(|r| r.migrated).collect();
// If entry is migrated from u2f, delete the u2f entry as well

5
src/api/core/two_factor/yubikey.rs

@ -189,7 +189,7 @@ async fn activate_yubikey(data: Json<EnableYubikeyData>, headers: Headers, conn:
generate_recover_code(&mut user, &conn).await;
log_user_event(EventType::UserUpdated2fa as i32, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
log_user_event(EventType::UserUpdated2fa, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
let mut result = jsonify_yubikeys(yubikey_metadata.keys);
result["enabled"] = Value::Bool(true);
@ -211,8 +211,7 @@ async fn delete_yubikeys(data: Json<VerificationTokenData>, headers: Headers, co
two_factor::validate_yubikey(&data.user_verification_token, &user.uuid, &yubikey_metadata.keys, true)?;
r.delete(&conn).await?;
log_user_event(EventType::UserDisabled2fa as i32, &user.uuid, headers.device.atype, &headers.ip.ip, &conn)
.await;
log_user_event(EventType::UserDisabled2fa, &user.uuid, headers.device.atype, &headers.ip.ip, &conn).await;
}
if TwoFactor::find_by_user(&user.uuid, &conn).await.is_empty() {

7
src/api/identity.rs

@ -129,7 +129,7 @@ async fn login(
match &login_result {
Ok(_) => {
log_user_event(
EventType::UserLoggedIn as i32,
EventType::UserLoggedIn,
&user_id,
client_header.device_type,
&client_header.ip.ip,
@ -139,8 +139,7 @@ async fn login(
}
Err(e) => {
if let Some(ev) = e.get_event() {
log_user_event(ev.event as i32, &user_id, client_header.device_type, &client_header.ip.ip, &conn)
.await;
log_user_event(ev.event, &user_id, client_header.device_type, &client_header.ip.ip, &conn).await;
}
}
}
@ -907,7 +906,7 @@ async fn twofactor_auth(
TwoFactor::delete_all_by_user(&user.uuid, conn).await?;
enforce_2fa_policy(user, &user.uuid, device.atype, &ip.ip, conn).await?;
log_user_event(EventType::UserRecovered2fa as i32, &user.uuid, device.atype, &ip.ip, conn).await;
log_user_event(EventType::UserRecovered2fa, &user.uuid, device.atype, &ip.ip, conn).await;
// Remove the recovery code, not needed without twofactors
user.totp_recover = None;

Loading…
Cancel
Save