Spiegel von
https://github.com/dani-garcia/vaultwarden.git
synchronisiert 2024-11-22 05:10:29 +01:00
Merge pull request #144 from mprasil/collection_revision
Update affected users revision when there are collection changes
Dieser Commit ist enthalten in:
Commit
d332e87655
2 geänderte Dateien mit 20 neuen und 0 gelöschten Zeilen
|
@ -185,6 +185,8 @@ impl CollectionUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save(user_uuid: &str, collection_uuid: &str, read_only:bool, conn: &DbConn) -> QueryResult<()> {
|
pub fn save(user_uuid: &str, collection_uuid: &str, read_only:bool, conn: &DbConn) -> QueryResult<()> {
|
||||||
|
User::update_uuid_revision(&user_uuid, conn);
|
||||||
|
|
||||||
diesel::replace_into(users_collections::table)
|
diesel::replace_into(users_collections::table)
|
||||||
.values((
|
.values((
|
||||||
users_collections::user_uuid.eq(user_uuid),
|
users_collections::user_uuid.eq(user_uuid),
|
||||||
|
@ -194,6 +196,8 @@ impl CollectionUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(self, conn: &DbConn) -> QueryResult<()> {
|
pub fn delete(self, conn: &DbConn) -> QueryResult<()> {
|
||||||
|
User::update_uuid_revision(&self.user_uuid, conn);
|
||||||
|
|
||||||
diesel::delete(users_collections::table
|
diesel::delete(users_collections::table
|
||||||
.filter(users_collections::user_uuid.eq(&self.user_uuid))
|
.filter(users_collections::user_uuid.eq(&self.user_uuid))
|
||||||
.filter(users_collections::collection_uuid.eq(&self.collection_uuid)))
|
.filter(users_collections::collection_uuid.eq(&self.collection_uuid)))
|
||||||
|
@ -216,12 +220,20 @@ impl CollectionUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_all_by_collection(collection_uuid: &str, conn: &DbConn) -> QueryResult<()> {
|
pub fn delete_all_by_collection(collection_uuid: &str, conn: &DbConn) -> QueryResult<()> {
|
||||||
|
CollectionUser::find_by_collection(&collection_uuid, conn)
|
||||||
|
.iter()
|
||||||
|
.for_each(|collection| {
|
||||||
|
User::update_uuid_revision(&collection.user_uuid, conn)
|
||||||
|
});
|
||||||
|
|
||||||
diesel::delete(users_collections::table
|
diesel::delete(users_collections::table
|
||||||
.filter(users_collections::collection_uuid.eq(collection_uuid))
|
.filter(users_collections::collection_uuid.eq(collection_uuid))
|
||||||
).execute(&**conn).and(Ok(()))
|
).execute(&**conn).and(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_all_by_user(user_uuid: &str, conn: &DbConn) -> QueryResult<()> {
|
pub fn delete_all_by_user(user_uuid: &str, conn: &DbConn) -> QueryResult<()> {
|
||||||
|
User::update_uuid_revision(&user_uuid, conn);
|
||||||
|
|
||||||
diesel::delete(users_collections::table
|
diesel::delete(users_collections::table
|
||||||
.filter(users_collections::user_uuid.eq(user_uuid))
|
.filter(users_collections::user_uuid.eq(user_uuid))
|
||||||
).execute(&**conn).and(Ok(()))
|
).execute(&**conn).and(Ok(()))
|
||||||
|
|
|
@ -154,6 +154,14 @@ impl User {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update_uuid_revision(uuid: &str, conn: &DbConn) {
|
||||||
|
if let Some(mut user) = User::find_by_uuid(&uuid, conn) {
|
||||||
|
if user.update_revision(conn).is_err(){
|
||||||
|
println!("Warning: Failed to update revision for {}", user.email);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update_revision(&mut self, conn: &DbConn) -> QueryResult<()> {
|
pub fn update_revision(&mut self, conn: &DbConn) -> QueryResult<()> {
|
||||||
self.updated_at = Utc::now().naive_utc();
|
self.updated_at = Utc::now().naive_utc();
|
||||||
diesel::update(
|
diesel::update(
|
||||||
|
|
Laden …
In neuem Issue referenzieren