diff options
Diffstat (limited to 'src/api/admin.rs')
-rw-r--r-- | src/api/admin.rs | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/api/admin.rs b/src/api/admin.rs index 29cb42ec..005856de 100644 --- a/src/api/admin.rs +++ b/src/api/admin.rs @@ -13,7 +13,7 @@ use rocket::{ }; use crate::{ - api::{core::log_event, ApiResult, EmptyResult, JsonResult, Notify, NumberOrString}, + api::{core::log_event, unregister_push_device, ApiResult, EmptyResult, JsonResult, Notify, NumberOrString}, auth::{decode_admin, encode_jwt, generate_admin_claims, ClientIp}, config::ConfigBuilder, db::{backup_database, get_sql_server_version, models::*, DbConn, DbConnType}, @@ -402,14 +402,22 @@ async fn delete_user(uuid: &str, token: AdminToken, mut conn: DbConn) -> EmptyRe #[post("/users/<uuid>/deauth")] async fn deauth_user(uuid: &str, _token: AdminToken, mut conn: DbConn, nt: Notify<'_>) -> EmptyResult { let mut user = get_user_or_404(uuid, &mut conn).await?; - Device::delete_all_by_user(&user.uuid, &mut conn).await?; - user.reset_security_stamp(); - let save_result = user.save(&mut conn).await; + nt.send_logout(&user, None, &mut conn).await; - nt.send_logout(&user, None).await; + if CONFIG.push_enabled() { + for device in Device::find_push_device_by_user(&user.uuid, &mut conn).await { + match unregister_push_device(device.uuid).await { + Ok(r) => r, + Err(e) => error!("Unable to unregister devices from Bitwarden server: {}", e), + }; + } + } - save_result + Device::delete_all_by_user(&user.uuid, &mut conn).await?; + user.reset_security_stamp(); + + user.save(&mut conn).await } #[post("/users/<uuid>/disable")] @@ -421,7 +429,7 @@ async fn disable_user(uuid: &str, _token: AdminToken, mut conn: DbConn, nt: Noti let save_result = user.save(&mut conn).await; - nt.send_logout(&user, None).await; + nt.send_logout(&user, None, &mut conn).await; save_result } |