diff --git a/src/api/core/accounts.rs b/src/api/core/accounts.rs index 1f114497..bb6e4bbf 100644 --- a/src/api/core/accounts.rs +++ b/src/api/core/accounts.rs @@ -1069,26 +1069,31 @@ struct PushToken { push_token: String, } -#[post("/devices/identifier//token", data = "")] -async fn post_device_token(uuid: &str, data: Json, headers: Headers, conn: DbConn) -> EmptyResult { - put_device_token(uuid, data, headers, conn).await +#[post("/devices/identifier//token", data = "")] +async fn post_device_token(device_id: DeviceId, data: Json, headers: Headers, conn: DbConn) -> EmptyResult { + put_device_token(device_id, data, headers, conn).await } -#[put("/devices/identifier//token", data = "")] -async fn put_device_token(uuid: &str, data: Json, headers: Headers, mut conn: DbConn) -> EmptyResult { +#[put("/devices/identifier//token", data = "")] +async fn put_device_token( + device_id: DeviceId, + data: Json, + headers: Headers, + mut conn: DbConn, +) -> EmptyResult { let data = data.into_inner(); let token = data.push_token; let Some(mut device) = Device::find_by_uuid_and_user(&headers.device.uuid, &headers.user.uuid, &mut conn).await else { - err!(format!("Error: device {uuid} should be present before a token can be assigned")) + err!(format!("Error: device {device_id} should be present before a token can be assigned")) }; // if the device already has been registered if device.is_registered() { // check if the new token is the same as the registered token if device.push_token.is_some() && device.push_token.unwrap() == token.clone() { - debug!("Device {} is already registered and token is the same", uuid); + debug!("Device {} is already registered and token is the same", device_id); return Ok(()); } else { // Try to unregister already registered device @@ -1107,8 +1112,8 @@ async fn put_device_token(uuid: &str, data: Json, headers: Headers, m Ok(()) } -#[put("/devices/identifier//clear-token")] -async fn put_clear_device_token(uuid: DeviceId, mut conn: DbConn) -> EmptyResult { +#[put("/devices/identifier//clear-token")] +async fn put_clear_device_token(device_id: DeviceId, mut conn: DbConn) -> EmptyResult { // This only clears push token // https://github.com/bitwarden/core/blob/master/src/Api/Controllers/DevicesController.cs#L109 // https://github.com/bitwarden/core/blob/master/src/Core/Services/Implementations/DeviceService.cs#L37 @@ -1117,8 +1122,8 @@ async fn put_clear_device_token(uuid: DeviceId, mut conn: DbConn) -> EmptyResult return Ok(()); } - if let Some(device) = Device::find_by_uuid(&uuid, &mut conn).await { - Device::clear_push_token_by_uuid(&uuid, &mut conn).await?; + if let Some(device) = Device::find_by_uuid(&device_id, &mut conn).await { + Device::clear_push_token_by_uuid(&device_id, &mut conn).await?; unregister_push_device(device.push_uuid).await?; } @@ -1126,9 +1131,9 @@ async fn put_clear_device_token(uuid: DeviceId, mut conn: DbConn) -> EmptyResult } // On upstream server, both PUT and POST are declared. Implementing the POST method in case it would be useful somewhere -#[post("/devices/identifier//clear-token")] -async fn post_clear_device_token(uuid: DeviceId, conn: DbConn) -> EmptyResult { - put_clear_device_token(uuid, conn).await +#[post("/devices/identifier//clear-token")] +async fn post_clear_device_token(device_id: DeviceId, conn: DbConn) -> EmptyResult { + put_clear_device_token(device_id, conn).await } #[derive(Debug, Deserialize)]