commit 5fc0472d884876c974bfb78fa1adaa5140c6c27f
parent 410ee9f1f7a9ad814fac94af8f2bb87fdc016f89
Author: Daniel GarcĂa <dani-garcia@users.noreply.github.com>
Date: Tue, 12 Jun 2018 23:15:27 +0200
Removed unneeded cipher code for changing case (fixed by last commit)
Diffstat:
1 file changed, 10 insertions(+), 49 deletions(-)
diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs
@@ -14,7 +14,6 @@ use data_encoding::HEXLOWER;
use db::DbConn;
use db::models::*;
-use util;
use crypto;
use api::{self, PasswordData, JsonResult, EmptyResult, JsonUpcase};
@@ -157,24 +156,6 @@ 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 **********
- // To remove backwards compatibility, just create an empty values object,
- // and remove the compat code from cipher::to_json
- let mut values = json!({
- "Name": data.Name,
- "Notes": data.Notes
- });
-
- values["Fields"] = uppercase_fields.clone().unwrap_or(Value::Null);
- // TODO: ******* Backwards compat end **********
-
let type_data_opt = match data.Type {
1 => data.Login,
2 => data.SecureNote,
@@ -183,19 +164,24 @@ fn update_cipher_from_data(cipher: &mut Cipher, data: CipherData, headers: &Head
_ => err!("Invalid type")
};
- let type_data = match type_data_opt {
+ let mut type_data = match type_data_opt {
Some(data) => data,
None => err!("Data missing")
};
- // Copy the type data and change the names to the correct case
- copy_values(&type_data, &mut values);
+ // TODO: ******* Backwards compat start **********
+ // To remove backwards compatibility, just delete this code,
+ // and remove the compat code from cipher::to_json
+ type_data["Name"] = Value::String(data.Name.clone());
+ type_data["Notes"] = data.Notes.clone().map(Value::String).unwrap_or(Value::Null);
+ type_data["Fields"] = data.Fields.clone().unwrap_or(Value::Null);
+ // TODO: ******* Backwards compat end **********
cipher.favorite = data.Favorite.unwrap_or(false);
cipher.name = data.Name;
cipher.notes = data.Notes;
- cipher.fields = uppercase_fields.map(|f| f.to_string());
- cipher.data = values.to_string();
+ cipher.fields = data.Fields.map(|f| f.to_string());
+ cipher.data = type_data.to_string();
cipher.save(&conn);
@@ -206,31 +192,6 @@ fn update_cipher_from_data(cipher: &mut Cipher, data: CipherData, headers: &Head
Ok(())
}
-fn copy_values(from: &Value, to: &mut Value) {
- if let Some(map) = from.as_object() {
- for (key, val) in map {
- let processed_key = _process_key(key);
- copy_values(val, &mut to[processed_key]);
- }
- } else if let Some(array) = from.as_array() {
- // Initialize array with null values
- *to = json!(vec![Value::Null; array.len()]);
-
- for (index, val) in array.iter().enumerate() {
- copy_values(val, &mut to[index]);
- }
- } else {
- *to = from.clone();
- }
-}
-
-fn _process_key(key: &str) -> String {
- match key.to_lowercase().as_ref() {
- "ssn" => "SSN".into(),
- _ => util::upcase_first(key)
- }
-}
-
use super::folders::FolderData;
#[derive(Deserialize)]