Page MenuHomePhabricator

D10399.diff
No OneTemporary

D10399.diff

diff --git a/services/identity/src/database.rs b/services/identity/src/database.rs
--- a/services/identity/src/database.rs
+++ b/services/identity/src/database.rs
@@ -292,14 +292,19 @@
.await?;
// add device to the new device list if not exists
+ let device_id = flattened_device_key_upload.device_id_key.clone();
let device_exists = self
- .device_exists(
- user_id.clone(),
- flattened_device_key_upload.device_id_key.clone(),
- )
+ .device_exists(user_id.clone(), device_id.clone())
.await?;
if device_exists {
+ self
+ .update_device_login_time(
+ user_id.clone(),
+ device_id,
+ access_token_creation_time,
+ )
+ .await?;
return Ok(());
}
@@ -332,14 +337,19 @@
.await?;
// add device to the new device list if not exists
+ let device_id = flattened_device_key_upload.device_id_key.clone();
let device_exists = self
- .device_exists(
- user_id.clone(),
- flattened_device_key_upload.device_id_key.clone(),
- )
+ .device_exists(user_id.clone(), device_id.clone())
.await?;
if device_exists {
+ self
+ .update_device_login_time(
+ user_id.clone(),
+ device_id,
+ access_token_creation_time,
+ )
+ .await?;
return Ok(());
}
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
@@ -602,6 +602,40 @@
Ok(item.is_some())
}
+ /// Required only for migration purposes (determining primary device)
+ pub async fn update_device_login_time(
+ &self,
+ user_id: impl Into<String>,
+ device_id: impl Into<String>,
+ login_time: DateTime<Utc>,
+ ) -> Result<(), Error> {
+ self
+ .client
+ .update_item()
+ .table_name(devices_table::NAME)
+ .key(ATTR_USER_ID, AttributeValue::S(user_id.into()))
+ .key(ATTR_ITEM_ID, DeviceIDAttribute(device_id.into()).into())
+ .condition_expression(
+ "attribute_exists(#user_id) AND attribute_exists(#item_id)",
+ )
+ .update_expression("SET #login_time = :login_time")
+ .expression_attribute_names("#user_id", ATTR_USER_ID)
+ .expression_attribute_names("#item_id", ATTR_ITEM_ID)
+ .expression_attribute_names("#login_time", ATTR_LOGIN_TIME)
+ .expression_attribute_values(
+ ":login_time",
+ AttributeValue::S(login_time.to_rfc3339()),
+ )
+ .send()
+ .await
+ .map_err(|e| {
+ error!("Failed to update device login time: {:?}", e);
+ Error::AwsSdk(e.into())
+ })?;
+
+ Ok(())
+ }
+
pub async fn get_current_device_list(
&self,
user_id: impl Into<String>,

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 3, 3:14 AM (21 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2609986
Default Alt Text
D10399.diff (2 KB)

Event Timeline