diff --git a/src/api/admin.rs b/src/api/admin.rs index 8c3f178ae5..673af54548 100644 --- a/src/api/admin.rs +++ b/src/api/admin.rs @@ -418,7 +418,7 @@ async fn delete_user(uuid: UserId, token: AdminToken, mut conn: DbConn) -> Empty async fn deauth_user(uuid: UserId, _token: AdminToken, mut conn: DbConn, nt: Notify<'_>) -> EmptyResult { let mut user = get_user_or_404(&uuid, &mut conn).await?; - nt.send_logout(&user, &DeviceId::empty()).await; + nt.send_logout(&user, None).await; if CONFIG.push_enabled() { for device in Device::find_push_devices_by_user(&user.uuid, &mut conn).await { @@ -444,7 +444,7 @@ async fn disable_user(uuid: UserId, _token: AdminToken, mut conn: DbConn, nt: No let save_result = user.save(&mut conn).await; - nt.send_logout(&user, &DeviceId::empty()).await; + nt.send_logout(&user, None).await; save_result } diff --git a/src/api/core/accounts.rs b/src/api/core/accounts.rs index ee5c94fdeb..0fb885cf85 100644 --- a/src/api/core/accounts.rs +++ b/src/api/core/accounts.rs @@ -374,7 +374,7 @@ async fn post_password(data: Json, headers: Headers, mut conn: D // Prevent logging out the client where the user requested this endpoint from. // If you do logout the user it will causes issues at the client side. // Adding the device uuid will prevent this. - nt.send_logout(&user, &headers.device.uuid).await; + nt.send_logout(&user, Some(headers.device.uuid.to_string())).await; save_result } @@ -434,7 +434,7 @@ async fn post_kdf(data: Json, headers: Headers, mut conn: DbConn, user.set_password(&data.new_master_password_hash, Some(data.key), true, None); let save_result = user.save(&mut conn).await; - nt.send_logout(&user, &headers.device.uuid).await; + nt.send_logout(&user, Some(headers.device.uuid.to_string())).await; save_result } @@ -646,7 +646,7 @@ async fn post_rotatekey(data: Json, headers: Headers, mut conn: DbConn, // Prevent logging out the client where the user requested this endpoint from. // If you do logout the user it will causes issues at the client side. // Adding the device uuid will prevent this. - nt.send_logout(&user, &headers.device.uuid).await; + nt.send_logout(&user, Some(headers.device.uuid.to_string())).await; save_result } @@ -662,7 +662,7 @@ async fn post_sstamp(data: Json, headers: Headers, mut conn: user.reset_security_stamp(); let save_result = user.save(&mut conn).await; - nt.send_logout(&user, &DeviceId::empty()).await; + nt.send_logout(&user, None).await; save_result } @@ -770,7 +770,7 @@ async fn post_email(data: Json, headers: Headers, mut conn: DbC let save_result = user.save(&mut conn).await; - nt.send_logout(&user, &DeviceId::empty()).await; + nt.send_logout(&user, None).await; save_result } diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs index 0646f136bc..c81da9ad80 100644 --- a/src/api/core/organizations.rs +++ b/src/api/core/organizations.rs @@ -2860,7 +2860,7 @@ async fn put_reset_password( user.set_password(reset_request.new_master_password_hash.as_str(), Some(reset_request.key), true, None); user.save(&mut conn).await?; - nt.send_logout(&user, &DeviceId::empty()).await; + nt.send_logout(&user, None).await; log_event( EventType::OrganizationUserAdminResetPassword as i32, diff --git a/src/api/core/sends.rs b/src/api/core/sends.rs index 6eb923b663..ee3c4d9ce6 100644 --- a/src/api/core/sends.rs +++ b/src/api/core/sends.rs @@ -485,7 +485,7 @@ async fn post_access( UpdateType::SyncSendUpdate, &send, &send.update_users_revision(&mut conn).await, - &DeviceId::empty(), + &String::from("00000000-0000-0000-0000-000000000000").into(), &mut conn, ) .await; @@ -542,7 +542,7 @@ async fn post_access_file( UpdateType::SyncSendUpdate, &send, &send.update_users_revision(&mut conn).await, - &DeviceId::empty(), + &String::from("00000000-0000-0000-0000-000000000000").into(), &mut conn, ) .await; @@ -635,7 +635,7 @@ pub async fn update_send_from_data( send.save(conn).await?; if ut != UpdateType::None { - nt.send_send_update(ut, send, &send.update_users_revision(conn).await, &headers.device.uuid, conn).await + nt.send_send_update(ut, send, &send.update_users_revision(conn).await, &headers.device.uuid, conn).await; } Ok(()) } diff --git a/src/api/notifications.rs b/src/api/notifications.rs index 30ca79d539..476f534131 100644 --- a/src/api/notifications.rs +++ b/src/api/notifications.rs @@ -347,7 +347,7 @@ impl WebSocketUsers { let data = create_update( vec![("UserId".into(), user.uuid.to_string().into()), ("Date".into(), serialize_date(user.updated_at))], ut, - DeviceId::empty(), + None, ); if CONFIG.enable_websocket() { @@ -359,7 +359,7 @@ impl WebSocketUsers { } } - pub async fn send_logout(&self, user: &User, acting_device_uuid: &DeviceId) { + pub async fn send_logout(&self, user: &User, acting_device_uuid: Option) { // Skip any processing if both WebSockets and Push are not active if *NOTIFICATIONS_DISABLED { return; @@ -397,7 +397,7 @@ impl WebSocketUsers { ("RevisionDate".into(), serialize_date(folder.updated_at)), ], ut, - acting_device_uuid.clone(), + Some(acting_device_uuid.to_string()), ); if CONFIG.enable_websocket() { @@ -444,7 +444,7 @@ impl WebSocketUsers { ("RevisionDate".into(), revision_date), ], ut, - acting_device_uuid.clone(), + Some(acting_device_uuid.to_string()), ); if CONFIG.enable_websocket() { @@ -479,7 +479,7 @@ impl WebSocketUsers { ("RevisionDate".into(), serialize_date(send.revision_date)), ], ut, - acting_device_uuid.clone(), + None, ); if CONFIG.enable_websocket() { @@ -506,7 +506,7 @@ impl WebSocketUsers { let data = create_update( vec![("Id".into(), auth_request_uuid.clone().into()), ("UserId".into(), user_uuid.to_string().into())], UpdateType::AuthRequest, - acting_device_uuid.clone(), + Some(acting_device_uuid.to_string()), ); if CONFIG.enable_websocket() { self.send_update(user_uuid, &data).await; @@ -531,7 +531,7 @@ impl WebSocketUsers { let data = create_update( vec![("Id".into(), auth_response_uuid.to_owned().into()), ("UserId".into(), user_uuid.to_string().into())], UpdateType::AuthRequestResponse, - approving_device_uuid.clone(), + Some(approving_device_uuid.to_string()), ); if CONFIG.enable_websocket() { self.send_update(user_uuid, &data).await; @@ -585,7 +585,7 @@ impl AnonymousWebSocketSubscriptions { ] ] */ -fn create_update(payload: Vec<(Value, Value)>, ut: UpdateType, acting_device_uuid: DeviceId) -> Vec { +fn create_update(payload: Vec<(Value, Value)>, ut: UpdateType, acting_device_uuid: Option) -> Vec { use rmpv::Value as V; let value = V::Array(vec![ @@ -594,7 +594,7 @@ fn create_update(payload: Vec<(Value, Value)>, ut: UpdateType, acting_device_uui V::Nil, "ReceiveMessage".into(), V::Array(vec![V::Map(vec![ - ("ContextId".into(), acting_device_uuid.to_string().into()), + ("ContextId".into(), acting_device_uuid.map(|v| v.into()).unwrap_or_else(|| V::Nil)), ("Type".into(), (ut as i32).into()), ("Payload".into(), payload.into()), ])]), diff --git a/src/api/push.rs b/src/api/push.rs index 25fe60fe8c..a1a3a4ba69 100644 --- a/src/api/push.rs +++ b/src/api/push.rs @@ -178,8 +178,8 @@ pub async fn push_cipher_update( } } -pub fn push_logout(user: &User, acting_device_uuid: DeviceId) { - let acting_device_uuid: Value = acting_device_uuid.to_string().into(); +pub fn push_logout(user: &User, acting_device_uuid: Option) { + let acting_device_uuid: Value = acting_device_uuid.map(|v| v.into()).unwrap_or_else(|| Value::Null); tokio::task::spawn(send_to_push_relay(json!({ "userId": user.uuid,