Spiegel von
https://github.com/dani-garcia/vaultwarden.git
synchronisiert 2024-11-16 04:12:53 +01:00
Merge pull request #206 from mprasil/collection_revision
Collection update updates User revision
Dieser Commit ist enthalten in:
Commit
2aabf14372
3 geänderte Dateien mit 48 neuen und 14 gelöschten Zeilen
|
@ -51,7 +51,9 @@ fn create_organization(headers: Headers, data: JsonUpcase<OrgData>, conn: DbConn
|
||||||
|
|
||||||
org.save(&conn);
|
org.save(&conn);
|
||||||
user_org.save(&conn);
|
user_org.save(&conn);
|
||||||
collection.save(&conn);
|
if collection.save(&conn).is_err() {
|
||||||
|
err!("Failed creating Collection");
|
||||||
|
}
|
||||||
|
|
||||||
Ok(Json(org.to_json()))
|
Ok(Json(org.to_json()))
|
||||||
}
|
}
|
||||||
|
@ -170,7 +172,9 @@ fn post_organization_collections(org_id: String, _headers: AdminHeaders, data: J
|
||||||
|
|
||||||
let mut collection = Collection::new(org.uuid.clone(), data.Name);
|
let mut collection = Collection::new(org.uuid.clone(), data.Name);
|
||||||
|
|
||||||
collection.save(&conn);
|
if collection.save(&conn).is_err() {
|
||||||
|
err!("Failed saving Collection");
|
||||||
|
}
|
||||||
|
|
||||||
Ok(Json(collection.to_json()))
|
Ok(Json(collection.to_json()))
|
||||||
}
|
}
|
||||||
|
@ -199,7 +203,9 @@ fn post_organization_collection_update(org_id: String, col_id: String, _headers:
|
||||||
}
|
}
|
||||||
|
|
||||||
collection.name = data.Name.clone();
|
collection.name = data.Name.clone();
|
||||||
collection.save(&conn);
|
if collection.save(&conn).is_err() {
|
||||||
|
err!("Failed updating Collection");
|
||||||
|
}
|
||||||
|
|
||||||
Ok(Json(collection.to_json()))
|
Ok(Json(collection.to_json()))
|
||||||
}
|
}
|
||||||
|
@ -623,8 +629,11 @@ fn post_org_import(query: OrgIdData, data: JsonUpcase<ImportData>, headers: Head
|
||||||
// Read and create the collections
|
// Read and create the collections
|
||||||
let collections: Vec<_> = data.Collections.into_iter().map(|coll| {
|
let collections: Vec<_> = data.Collections.into_iter().map(|coll| {
|
||||||
let mut collection = Collection::new(org_id.clone(), coll.Name);
|
let mut collection = Collection::new(org_id.clone(), coll.Name);
|
||||||
collection.save(&conn);
|
if collection.save(&conn).is_err() {
|
||||||
collection
|
err!("Failed to create Collection");
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(collection)
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
// Read the relations between collections and ciphers
|
// Read the relations between collections and ciphers
|
||||||
|
@ -643,7 +652,11 @@ fn post_org_import(query: OrgIdData, data: JsonUpcase<ImportData>, headers: Head
|
||||||
// Assign the collections
|
// Assign the collections
|
||||||
for (cipher_index, coll_index) in relations {
|
for (cipher_index, coll_index) in relations {
|
||||||
let cipher_id = &ciphers[cipher_index].uuid;
|
let cipher_id = &ciphers[cipher_index].uuid;
|
||||||
let coll_id = &collections[coll_index].uuid;
|
let coll = &collections[coll_index];
|
||||||
|
let coll_id = match coll {
|
||||||
|
Ok(coll) => coll.uuid.as_str(),
|
||||||
|
Err(_) => err!("Failed to assign to collection")
|
||||||
|
};
|
||||||
|
|
||||||
CollectionCipher::save(cipher_id, coll_id, &conn);
|
CollectionCipher::save(cipher_id, coll_id, &conn);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,13 +42,18 @@ use db::schema::*;
|
||||||
|
|
||||||
/// Database methods
|
/// Database methods
|
||||||
impl Collection {
|
impl Collection {
|
||||||
pub fn save(&mut self, conn: &DbConn) -> bool {
|
pub fn save(&mut self, conn: &DbConn) -> QueryResult<()> {
|
||||||
match diesel::replace_into(collections::table)
|
// Update affected users revision
|
||||||
.values(&*self)
|
UserOrganization::find_by_collection_and_org(&self.uuid, &self.org_uuid, conn)
|
||||||
.execute(&**conn) {
|
.iter()
|
||||||
Ok(1) => true, // One row inserted
|
.for_each(|user_org| {
|
||||||
_ => false,
|
User::update_uuid_revision(&user_org.user_uuid, conn);
|
||||||
}
|
});
|
||||||
|
|
||||||
|
diesel::replace_into(collections::table)
|
||||||
|
.values(&*self)
|
||||||
|
.execute(&**conn)
|
||||||
|
.and(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(self, conn: &DbConn) -> QueryResult<()> {
|
pub fn delete(self, conn: &DbConn) -> QueryResult<()> {
|
||||||
|
|
|
@ -331,6 +331,22 @@ impl UserOrganization {
|
||||||
.select(users_organizations::all_columns)
|
.select(users_organizations::all_columns)
|
||||||
.load::<Self>(&**conn).expect("Error loading user organizations")
|
.load::<Self>(&**conn).expect("Error loading user organizations")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn find_by_collection_and_org(collection_uuid: &str, org_uuid: &str, conn: &DbConn) -> Vec<Self> {
|
||||||
|
users_organizations::table
|
||||||
|
.filter(users_organizations::org_uuid.eq(org_uuid))
|
||||||
|
.left_join(users_collections::table.on(
|
||||||
|
users_collections::user_uuid.eq(users_organizations::user_uuid)
|
||||||
|
))
|
||||||
|
.filter(
|
||||||
|
users_organizations::access_all.eq(true).or( // AccessAll..
|
||||||
|
users_collections::collection_uuid.eq(&collection_uuid) // ..or access to collection with cipher
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.select(users_organizations::all_columns)
|
||||||
|
.load::<Self>(&**conn).expect("Error loading user organizations")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Laden …
In neuem Issue referenzieren