mirror of
https://github.com/dani-garcia/vaultwarden
synced 2024-11-14 16:17:10 +00:00
Can now remove notes and fields correctly. Also fixed fields, that should go in uppercase
This commit is contained in:
parent
0037f0819b
commit
f578019df6
1 changed files with 12 additions and 24 deletions
|
@ -129,8 +129,6 @@ fn update_cipher_from_data(cipher: &mut Cipher, data: CipherData, headers: &Head
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cipher.folder_uuid = data.folderId;
|
|
||||||
|
|
||||||
if let Some(org_id) = data.organizationId {
|
if let Some(org_id) = data.organizationId {
|
||||||
match UserOrganization::find_by_user_and_org(&headers.user.uuid, &org_id, &conn) {
|
match UserOrganization::find_by_user_and_org(&headers.user.uuid, &org_id, &conn) {
|
||||||
None => err!("You don't have permission to add item to organization"),
|
None => err!("You don't have permission to add item to organization"),
|
||||||
|
@ -142,6 +140,13 @@ fn update_cipher_from_data(cipher: &mut Cipher, data: CipherData, headers: &Head
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let uppercase_fields = data.fields.map(|f| {
|
||||||
|
let mut value = json!({});
|
||||||
|
// Copy every field object and change the names to the correct case
|
||||||
|
copy_values(&f, &mut value);
|
||||||
|
value
|
||||||
|
});
|
||||||
|
|
||||||
// TODO: ******* Backwards compat start **********
|
// TODO: ******* Backwards compat start **********
|
||||||
// To remove backwards compatibility, just create an empty values object,
|
// To remove backwards compatibility, just create an empty values object,
|
||||||
// and remove the compat code from cipher::to_json
|
// and remove the compat code from cipher::to_json
|
||||||
|
@ -150,29 +155,9 @@ fn update_cipher_from_data(cipher: &mut Cipher, data: CipherData, headers: &Head
|
||||||
"Notes": data.notes
|
"Notes": data.notes
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(ref fields) = data.fields {
|
values["Fields"] = uppercase_fields.clone().unwrap_or(Value::Null);
|
||||||
values["Fields"] = Value::Array(fields.as_array().unwrap().iter().map(|f| {
|
|
||||||
let mut value = json!({});
|
|
||||||
|
|
||||||
// Copy every field object and change the names to the correct case
|
|
||||||
copy_values(&f, &mut value);
|
|
||||||
|
|
||||||
value
|
|
||||||
}).collect());
|
|
||||||
} else {
|
|
||||||
values["Fields"] = Value::Null;
|
|
||||||
}
|
|
||||||
// TODO: ******* Backwards compat end **********
|
// TODO: ******* Backwards compat end **********
|
||||||
|
|
||||||
if let notes @ Some(_) = data.notes {
|
|
||||||
cipher.notes = notes;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(fields) = data.fields {
|
|
||||||
use serde_json::to_string;
|
|
||||||
cipher.fields = to_string(&fields).ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
let type_data_opt = match data.type_ {
|
let type_data_opt = match data.type_ {
|
||||||
1 => data.login,
|
1 => data.login,
|
||||||
2 => data.secureNote,
|
2 => data.secureNote,
|
||||||
|
@ -188,8 +173,11 @@ fn update_cipher_from_data(cipher: &mut Cipher, data: CipherData, headers: &Head
|
||||||
|
|
||||||
// Copy the type data and change the names to the correct case
|
// Copy the type data and change the names to the correct case
|
||||||
copy_values(&type_data, &mut values);
|
copy_values(&type_data, &mut values);
|
||||||
cipher.name = data.name;
|
|
||||||
|
|
||||||
|
cipher.folder_uuid = data.folderId;
|
||||||
|
cipher.name = data.name;
|
||||||
|
cipher.notes = data.notes;
|
||||||
|
cipher.fields = uppercase_fields.map(|f| f.to_string());
|
||||||
cipher.data = values.to_string();
|
cipher.data = values.to_string();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue