Page MenuHomePhabricator

D12589.diff
No OneTemporary

D12589.diff

diff --git a/services/identity/src/database/device_list.rs b/services/identity/src/database/device_list.rs
--- a/services/identity/src/database/device_list.rs
+++ b/services/identity/src/database/device_list.rs
@@ -1303,14 +1303,19 @@
}
/// applies updated device list received from primary device
- pub async fn apply_devicelist_update(
+ pub async fn apply_devicelist_update<V>(
&self,
user_id: &str,
update: DeviceListUpdate,
// A function that receives previous and new device IDs and
// returns boolean determining if the new device list is valid.
- validator_fn: impl Fn(&[&str], &[&str]) -> bool,
- ) -> Result<DeviceListRow, Error> {
+ validator_fn: Option<V>,
+ // Whether to remove device data when a device is removed from the list.
+ remove_device_data: bool,
+ ) -> Result<DeviceListRow, Error>
+ where
+ V: Fn(&[&str], &[&str]) -> bool,
+ {
use std::collections::HashSet;
let new_list = update.devices.clone();
@@ -1326,11 +1331,14 @@
current_list.iter().map(AsRef::as_ref).collect();
let new_device_ids: Vec<&str> =
new_list.iter().map(AsRef::as_ref).collect();
- if !validator_fn(&previous_device_ids, &new_device_ids) {
- warn!("Received invalid device list update");
- return Err(Error::DeviceList(
- DeviceListError::InvalidDeviceListUpdate,
- ));
+
+ if let Some(validate) = validator_fn {
+ if !validate(&previous_device_ids, &new_device_ids) {
+ warn!("Received invalid device list update");
+ return Err(Error::DeviceList(
+ DeviceListError::InvalidDeviceListUpdate,
+ ));
+ }
}
// collect device IDs that were removed
@@ -1347,6 +1355,10 @@
})
.await?;
+ if !remove_device_data {
+ return Ok(update_result);
+ }
+
// delete device data and invalidate CSAT for removed devices
debug!(
"{} devices have been removed from device list. Clearing data...",
diff --git a/services/identity/src/grpc_services/authenticated.rs b/services/identity/src/grpc_services/authenticated.rs
--- a/services/identity/src/grpc_services/authenticated.rs
+++ b/services/identity/src/grpc_services/authenticated.rs
@@ -732,13 +732,11 @@
let new_list = SignedDeviceList::try_from(request.into_inner())?;
let update = DeviceListUpdate::try_from(new_list)?;
+ let validator =
+ crate::device_list::validation::update_device_list_rpc_validator;
self
.db_client
- .apply_devicelist_update(
- &user_id,
- update,
- crate::device_list::validation::update_device_list_rpc_validator,
- )
+ .apply_devicelist_update(&user_id, update, Some(validator), true)
.await
.map_err(handle_db_error)?;

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 23, 12:25 AM (18 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2566837
Default Alt Text
D12589.diff (2 KB)

Event Timeline