mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2024-12-02 13:06:58 +01:00
Fix collection change ws notifications
When chaning a collection this did not got notified via WebSockets. This PR adds this feature and resolves #3534
This commit is contained in:
parent
04a17dcdef
commit
83376544d8
2 changed files with 39 additions and 9 deletions
|
@ -512,7 +512,7 @@ pub async fn update_cipher_from_data(
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
nt.send_cipher_update(ut, cipher, &cipher.update_users_revision(conn).await, &headers.device.uuid).await;
|
nt.send_cipher_update(ut, cipher, &cipher.update_users_revision(conn).await, &headers.device.uuid, None).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -702,8 +702,9 @@ async fn put_collections_update(
|
||||||
data: JsonUpcase<CollectionsAdminData>,
|
data: JsonUpcase<CollectionsAdminData>,
|
||||||
headers: Headers,
|
headers: Headers,
|
||||||
conn: DbConn,
|
conn: DbConn,
|
||||||
|
nt: Notify<'_>,
|
||||||
) -> EmptyResult {
|
) -> EmptyResult {
|
||||||
post_collections_admin(uuid, data, headers, conn).await
|
post_collections_admin(uuid, data, headers, conn, nt).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/ciphers/<uuid>/collections", data = "<data>")]
|
#[post("/ciphers/<uuid>/collections", data = "<data>")]
|
||||||
|
@ -712,8 +713,9 @@ async fn post_collections_update(
|
||||||
data: JsonUpcase<CollectionsAdminData>,
|
data: JsonUpcase<CollectionsAdminData>,
|
||||||
headers: Headers,
|
headers: Headers,
|
||||||
conn: DbConn,
|
conn: DbConn,
|
||||||
|
nt: Notify<'_>,
|
||||||
) -> EmptyResult {
|
) -> EmptyResult {
|
||||||
post_collections_admin(uuid, data, headers, conn).await
|
post_collections_admin(uuid, data, headers, conn, nt).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put("/ciphers/<uuid>/collections-admin", data = "<data>")]
|
#[put("/ciphers/<uuid>/collections-admin", data = "<data>")]
|
||||||
|
@ -722,8 +724,9 @@ async fn put_collections_admin(
|
||||||
data: JsonUpcase<CollectionsAdminData>,
|
data: JsonUpcase<CollectionsAdminData>,
|
||||||
headers: Headers,
|
headers: Headers,
|
||||||
conn: DbConn,
|
conn: DbConn,
|
||||||
|
nt: Notify<'_>,
|
||||||
) -> EmptyResult {
|
) -> EmptyResult {
|
||||||
post_collections_admin(uuid, data, headers, conn).await
|
post_collections_admin(uuid, data, headers, conn, nt).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/ciphers/<uuid>/collections-admin", data = "<data>")]
|
#[post("/ciphers/<uuid>/collections-admin", data = "<data>")]
|
||||||
|
@ -732,6 +735,7 @@ async fn post_collections_admin(
|
||||||
data: JsonUpcase<CollectionsAdminData>,
|
data: JsonUpcase<CollectionsAdminData>,
|
||||||
headers: Headers,
|
headers: Headers,
|
||||||
mut conn: DbConn,
|
mut conn: DbConn,
|
||||||
|
nt: Notify<'_>,
|
||||||
) -> EmptyResult {
|
) -> EmptyResult {
|
||||||
let data: CollectionsAdminData = data.into_inner().data;
|
let data: CollectionsAdminData = data.into_inner().data;
|
||||||
|
|
||||||
|
@ -767,6 +771,15 @@ async fn post_collections_admin(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nt.send_cipher_update(
|
||||||
|
UpdateType::SyncCipherUpdate,
|
||||||
|
&cipher,
|
||||||
|
&cipher.update_users_revision(&mut conn).await,
|
||||||
|
&headers.device.uuid,
|
||||||
|
Some(Vec::from_iter(posted_collections)),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
log_event(
|
log_event(
|
||||||
EventType::CipherUpdatedCollections as i32,
|
EventType::CipherUpdatedCollections as i32,
|
||||||
&cipher.uuid,
|
&cipher.uuid,
|
||||||
|
@ -1108,6 +1121,7 @@ async fn save_attachment(
|
||||||
&cipher,
|
&cipher,
|
||||||
&cipher.update_users_revision(&mut conn).await,
|
&cipher.update_users_revision(&mut conn).await,
|
||||||
&headers.device.uuid,
|
&headers.device.uuid,
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
@ -1393,7 +1407,8 @@ async fn move_cipher_selected(
|
||||||
// Move cipher
|
// Move cipher
|
||||||
cipher.move_to_folder(data.FolderId.clone(), &user_uuid, &mut conn).await?;
|
cipher.move_to_folder(data.FolderId.clone(), &user_uuid, &mut conn).await?;
|
||||||
|
|
||||||
nt.send_cipher_update(UpdateType::SyncCipherUpdate, &cipher, &[user_uuid.clone()], &headers.device.uuid).await;
|
nt.send_cipher_update(UpdateType::SyncCipherUpdate, &cipher, &[user_uuid.clone()], &headers.device.uuid, None)
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1503,6 +1518,7 @@ async fn _delete_cipher_by_uuid(
|
||||||
&cipher,
|
&cipher,
|
||||||
&cipher.update_users_revision(conn).await,
|
&cipher.update_users_revision(conn).await,
|
||||||
&headers.device.uuid,
|
&headers.device.uuid,
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1512,6 +1528,7 @@ async fn _delete_cipher_by_uuid(
|
||||||
&cipher,
|
&cipher,
|
||||||
&cipher.update_users_revision(conn).await,
|
&cipher.update_users_revision(conn).await,
|
||||||
&headers.device.uuid,
|
&headers.device.uuid,
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
@ -1581,6 +1598,7 @@ async fn _restore_cipher_by_uuid(uuid: &str, headers: &Headers, conn: &mut DbCon
|
||||||
&cipher,
|
&cipher,
|
||||||
&cipher.update_users_revision(conn).await,
|
&cipher.update_users_revision(conn).await,
|
||||||
&headers.device.uuid,
|
&headers.device.uuid,
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
if let Some(org_uuid) = &cipher.organization_uuid {
|
if let Some(org_uuid) = &cipher.organization_uuid {
|
||||||
|
@ -1662,6 +1680,7 @@ async fn _delete_cipher_attachment_by_id(
|
||||||
&cipher,
|
&cipher,
|
||||||
&cipher.update_users_revision(conn).await,
|
&cipher.update_users_revision(conn).await,
|
||||||
&headers.device.uuid,
|
&headers.device.uuid,
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
if let Some(org_uuid) = cipher.organization_uuid {
|
if let Some(org_uuid) = cipher.organization_uuid {
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::{
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
use chrono::NaiveDateTime;
|
use chrono::{NaiveDateTime, Utc};
|
||||||
use rmpv::Value;
|
use rmpv::Value;
|
||||||
use rocket::{
|
use rocket::{
|
||||||
futures::{SinkExt, StreamExt},
|
futures::{SinkExt, StreamExt},
|
||||||
|
@ -265,17 +265,28 @@ impl WebSocketUsers {
|
||||||
cipher: &Cipher,
|
cipher: &Cipher,
|
||||||
user_uuids: &[String],
|
user_uuids: &[String],
|
||||||
acting_device_uuid: &String,
|
acting_device_uuid: &String,
|
||||||
|
collection_uuids: Option<Vec<String>>,
|
||||||
) {
|
) {
|
||||||
let user_uuid = convert_option(cipher.user_uuid.clone());
|
|
||||||
let org_uuid = convert_option(cipher.organization_uuid.clone());
|
let org_uuid = convert_option(cipher.organization_uuid.clone());
|
||||||
|
// Depending if there are collections provided or not, we need to have different values for the following variables.
|
||||||
|
// The user_uuid should be `null`, and the revision date should be set to now, else the clients won't sync the collection change.
|
||||||
|
let (user_uuid, collection_uuids, revision_date) = if let Some(collection_uuids) = collection_uuids {
|
||||||
|
(
|
||||||
|
Value::Nil,
|
||||||
|
Value::Array(collection_uuids.into_iter().map(|v| v.into()).collect::<Vec<rmpv::Value>>()),
|
||||||
|
serialize_date(Utc::now().naive_utc()),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
(convert_option(cipher.user_uuid.clone()), Value::Nil, serialize_date(cipher.updated_at))
|
||||||
|
};
|
||||||
|
|
||||||
let data = create_update(
|
let data = create_update(
|
||||||
vec![
|
vec![
|
||||||
("Id".into(), cipher.uuid.clone().into()),
|
("Id".into(), cipher.uuid.clone().into()),
|
||||||
("UserId".into(), user_uuid),
|
("UserId".into(), user_uuid),
|
||||||
("OrganizationId".into(), org_uuid),
|
("OrganizationId".into(), org_uuid),
|
||||||
("CollectionIds".into(), Value::Nil),
|
("CollectionIds".into(), collection_uuids),
|
||||||
("RevisionDate".into(), serialize_date(cipher.updated_at)),
|
("RevisionDate".into(), revision_date),
|
||||||
],
|
],
|
||||||
ut,
|
ut,
|
||||||
Some(acting_device_uuid.into()),
|
Some(acting_device_uuid.into()),
|
||||||
|
|
Loading…
Reference in a new issue