Skip to content

Commit

Permalink
revert changes to notification interface
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan0xC committed Dec 22, 2024
1 parent a7ef71b commit 34f454e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/api/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions src/api/core/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ async fn post_password(data: Json<ChangePassData>, 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
}
Expand Down Expand Up @@ -434,7 +434,7 @@ async fn post_kdf(data: Json<ChangeKdfData>, 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
}
Expand Down Expand Up @@ -646,7 +646,7 @@ async fn post_rotatekey(data: Json<KeyData>, 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
}
Expand All @@ -662,7 +662,7 @@ async fn post_sstamp(data: Json<PasswordOrOtpData>, 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
}
Expand Down Expand Up @@ -770,7 +770,7 @@ async fn post_email(data: Json<ChangeEmailData>, 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
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/core/organizations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/api/core/sends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(())
}
Expand Down
18 changes: 9 additions & 9 deletions src/api/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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<String>) {
// Skip any processing if both WebSockets and Push are not active
if *NOTIFICATIONS_DISABLED {
return;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -479,7 +479,7 @@ impl WebSocketUsers {
("RevisionDate".into(), serialize_date(send.revision_date)),
],
ut,
acting_device_uuid.clone(),
None,
);

if CONFIG.enable_websocket() {
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -585,7 +585,7 @@ impl AnonymousWebSocketSubscriptions {
]
]
*/
fn create_update(payload: Vec<(Value, Value)>, ut: UpdateType, acting_device_uuid: DeviceId) -> Vec<u8> {
fn create_update(payload: Vec<(Value, Value)>, ut: UpdateType, acting_device_uuid: Option<String>) -> Vec<u8> {
use rmpv::Value as V;

let value = V::Array(vec![
Expand All @@ -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()),
])]),
Expand Down
4 changes: 2 additions & 2 deletions src/api/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) {
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,
Expand Down

0 comments on commit 34f454e

Please sign in to comment.