From e22e290f677c01354446bf784287114696f2eeaa Mon Sep 17 00:00:00 2001 From: Emil Madsen Date: Mon, 20 May 2019 21:24:29 +0200 Subject: [PATCH] Fix key and type variable names for mysql --- src/api/core/accounts.rs | 10 +++++----- src/api/core/ciphers.rs | 6 +++--- src/api/core/mod.rs | 2 +- src/api/core/organizations.rs | 28 ++++++++++++++-------------- src/api/identity.rs | 8 ++++---- src/auth.rs | 2 +- src/db/models/organization.rs | 6 +++--- src/db/models/user.rs | 2 +- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/api/core/accounts.rs b/src/api/core/accounts.rs index bc2d2868..3b16514a 100644 --- a/src/api/core/accounts.rs +++ b/src/api/core/accounts.rs @@ -106,7 +106,7 @@ fn register(data: JsonUpcase, conn: DbConn) -> EmptyResult { } user.set_password(&data.MasterPasswordHash); - user.key = data.Key; + user.akey = data.Key; // Add extra fields if present if let Some(name) = data.Name { @@ -204,7 +204,7 @@ fn post_password(data: JsonUpcase, headers: Headers, conn: DbCon } user.set_password(&data.NewMasterPasswordHash); - user.key = data.Key; + user.akey = data.Key; user.save(&conn) } @@ -231,7 +231,7 @@ fn post_kdf(data: JsonUpcase, headers: Headers, conn: DbConn) -> user.client_kdf_iter = data.KdfIterations; user.client_kdf_type = data.Kdf; user.set_password(&data.NewMasterPasswordHash); - user.key = data.Key; + user.akey = data.Key; user.save(&conn) } @@ -306,7 +306,7 @@ fn post_rotatekey(data: JsonUpcase, headers: Headers, conn: DbConn, nt: // Update user data let mut user = headers.user; - user.key = data.Key; + user.akey = data.Key; user.private_key = Some(data.PrivateKey); user.reset_security_stamp(); @@ -377,7 +377,7 @@ fn post_email(data: JsonUpcase, headers: Headers, conn: DbConn) user.email = data.NewEmail; user.set_password(&data.NewMasterPasswordHash); - user.key = data.Key; + user.akey = data.Key; user.save(&conn) } diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs index f44ad513..05ee7e10 100644 --- a/src/api/core/ciphers.rs +++ b/src/api/core/ciphers.rs @@ -267,7 +267,7 @@ pub fn update_cipher_from_data( err!("Attachment is not owned by the cipher") } - saved_att.key = Some(attachment.Key); + saved_att.akey = Some(attachment.Key); saved_att.file_name = attachment.FileName; saved_att.save(&conn)?; @@ -691,7 +691,7 @@ fn post_attachment( }; let mut attachment = Attachment::new(file_name, cipher.uuid.clone(), name, size); - attachment.key = attachment_key.clone(); + attachment.akey = attachment_key.clone(); attachment.save(&conn).expect("Error saving attachment"); } _ => error!("Invalid multipart name"), @@ -899,7 +899,7 @@ fn delete_all( match UserOrganization::find_by_user_and_org(&user.uuid, &org_data.org_id, &conn) { None => err!("You don't have permission to purge the organization vault"), Some(user_org) => { - if user_org.type_ == UserOrgType::Owner { + if user_org.atype == UserOrgType::Owner { Cipher::delete_all_by_organization(&org_data.org_id, &conn)?; Collection::delete_all_by_organization(&org_data.org_id, &conn)?; nt.send_user_update(UpdateType::Vault, &user); diff --git a/src/api/core/mod.rs b/src/api/core/mod.rs index 4abe31a4..6be0f9c1 100644 --- a/src/api/core/mod.rs +++ b/src/api/core/mod.rs @@ -63,7 +63,7 @@ fn put_device_token(uuid: String, data: JsonUpcase, headers: Headers) -> Ok(Json(json!({ "Id": headers.device.uuid, "Name": headers.device.name, - "Type": headers.device.type_, + "Type": headers.device.atype, "Identifier": headers.device.uuid, "CreationDate": crate::util::format_date(&headers.device.created_at), }))) diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs index 43967331..0a6a9db1 100644 --- a/src/api/core/organizations.rs +++ b/src/api/core/organizations.rs @@ -80,9 +80,9 @@ fn create_organization(headers: Headers, data: JsonUpcase, conn: DbConn let mut user_org = UserOrganization::new(headers.user.uuid.clone(), org.uuid.clone()); let collection = Collection::new(org.uuid.clone(), data.CollectionName); - user_org.key = data.Key; + user_org.akey = data.Key; user_org.access_all = true; - user_org.type_ = UserOrgType::Owner as i32; + user_org.atype = UserOrgType::Owner as i32; user_org.status = UserOrgStatus::Confirmed as i32; org.save(&conn)?; @@ -127,7 +127,7 @@ fn leave_organization(org_id: String, headers: Headers, conn: DbConn) -> EmptyRe match UserOrganization::find_by_user_and_org(&headers.user.uuid, &org_id, &conn) { None => err!("User not part of organization"), Some(user_org) => { - if user_org.type_ == UserOrgType::Owner { + if user_org.atype == UserOrgType::Owner { let num_owners = UserOrganization::find_by_org_and_type(&org_id, UserOrgType::Owner as i32, &conn).len(); @@ -505,7 +505,7 @@ fn send_invite(org_id: String, data: JsonUpcase, headers: AdminHeade let mut new_user = UserOrganization::new(user.uuid.clone(), org_id.clone()); let access_all = data.AccessAll.unwrap_or(false); new_user.access_all = access_all; - new_user.type_ = new_type; + new_user.atype = new_type; new_user.status = user_org_status; // If no accessAll, add the collections received @@ -657,7 +657,7 @@ fn confirm_invite( None => err!("The specified user isn't a member of the organization"), }; - if user_to_confirm.type_ != UserOrgType::User && headers.org_user_type != UserOrgType::Owner { + if user_to_confirm.atype != UserOrgType::User && headers.org_user_type != UserOrgType::Owner { err!("Only Owners can confirm Managers, Admins or Owners") } @@ -666,7 +666,7 @@ fn confirm_invite( } user_to_confirm.status = UserOrgStatus::Confirmed as i32; - user_to_confirm.key = match data["Key"].as_str() { + user_to_confirm.akey = match data["Key"].as_str() { Some(key) => key.to_string(), None => err!("Invalid key provided"), }; @@ -735,18 +735,18 @@ fn edit_user( None => err!("The specified user isn't member of the organization"), }; - if new_type != user_to_edit.type_ - && (user_to_edit.type_ >= UserOrgType::Admin || new_type >= UserOrgType::Admin) + if new_type != user_to_edit.atype + && (user_to_edit.atype >= UserOrgType::Admin || new_type >= UserOrgType::Admin) && headers.org_user_type != UserOrgType::Owner { err!("Only Owners can grant and remove Admin or Owner privileges") } - if user_to_edit.type_ == UserOrgType::Owner && headers.org_user_type != UserOrgType::Owner { + if user_to_edit.atype == UserOrgType::Owner && headers.org_user_type != UserOrgType::Owner { err!("Only Owners can edit Owner users") } - if user_to_edit.type_ == UserOrgType::Owner && new_type != UserOrgType::Owner { + if user_to_edit.atype == UserOrgType::Owner && new_type != UserOrgType::Owner { // Removing owner permmission, check that there are at least another owner let num_owners = UserOrganization::find_by_org_and_type(&org_id, UserOrgType::Owner as i32, &conn).len(); @@ -756,7 +756,7 @@ fn edit_user( } user_to_edit.access_all = data.AccessAll; - user_to_edit.type_ = new_type as i32; + user_to_edit.atype = new_type as i32; // Delete all the odd collections for c in CollectionUser::find_by_organization_and_user_uuid(&org_id, &user_to_edit.user_uuid, &conn) { @@ -785,11 +785,11 @@ fn delete_user(org_id: String, org_user_id: String, headers: AdminHeaders, conn: None => err!("User to delete isn't member of the organization"), }; - if user_to_delete.type_ != UserOrgType::User && headers.org_user_type != UserOrgType::Owner { + if user_to_delete.atype != UserOrgType::User && headers.org_user_type != UserOrgType::Owner { err!("Only Owners can delete Admins or Owners") } - if user_to_delete.type_ == UserOrgType::Owner { + if user_to_delete.atype == UserOrgType::Owner { // Removing owner, check that there are at least another owner let num_owners = UserOrganization::find_by_org_and_type(&org_id, UserOrgType::Owner as i32, &conn).len(); @@ -842,7 +842,7 @@ fn post_org_import( None => err!("User is not part of the organization"), }; - if org_user.type_ < UserOrgType::Admin { + if org_user.atype < UserOrgType::Admin { err!("Only admins or owners can import into an organization") } diff --git a/src/api/identity.rs b/src/api/identity.rs index 0645dad1..3602dc97 100644 --- a/src/api/identity.rs +++ b/src/api/identity.rs @@ -68,7 +68,7 @@ fn _refresh_login(data: ConnectData, conn: DbConn) -> JsonResult { "expires_in": expires_in, "token_type": "Bearer", "refresh_token": device.refresh_token, - "Key": user.key, + "Key": user.akey, "PrivateKey": user.private_key, }))) } @@ -132,7 +132,7 @@ fn _password_login(data: ConnectData, conn: DbConn, ip: ClientIp) -> JsonResult "expires_in": expires_in, "token_type": "Bearer", "refresh_token": device.refresh_token, - "Key": user.key, + "Key": user.akey, "PrivateKey": user.private_key, //"TwoFactorToken": "11122233333444555666777888999" }); @@ -158,7 +158,7 @@ fn twofactor_auth( return Ok(None); } - let twofactor_ids: Vec<_> = twofactors.iter().map(|tf| tf.type_).collect(); + let twofactor_ids: Vec<_> = twofactors.iter().map(|tf| tf.atype).collect(); let selected_id = data.two_factor_provider.unwrap_or(twofactor_ids[0]); // If we aren't given a two factor provider, asume the first one let twofactor_code = match data.two_factor_token { @@ -166,7 +166,7 @@ fn twofactor_auth( None => err_json!(_json_err_twofactor(&twofactor_ids, user_uuid, conn)?), }; - let selected_twofactor = twofactors.into_iter().filter(|tf| tf.type_ == selected_id).nth(0); + let selected_twofactor = twofactors.into_iter().filter(|tf| tf.atype == selected_id).nth(0); use crate::api::core::two_factor as _tf; use crate::crypto::ct_eq; diff --git a/src/auth.rs b/src/auth.rs index 7c65dea3..eab1e900 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -286,7 +286,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for OrgHeaders { device: headers.device, user, org_user_type: { - if let Some(org_usr_type) = UserOrgType::from_i32(org_user.type_) { + if let Some(org_usr_type) = UserOrgType::from_i32(org_user.atype) { org_usr_type } else { // This should only happen if the DB is corrupted diff --git a/src/db/models/organization.rs b/src/db/models/organization.rs index 463e1d0f..2e5ec0f5 100644 --- a/src/db/models/organization.rs +++ b/src/db/models/organization.rs @@ -21,7 +21,7 @@ pub struct UserOrganization { pub org_uuid: String, pub access_all: bool, - pub key: String, + pub akey: String, pub status: i32, pub atype: i32, } @@ -196,7 +196,7 @@ impl UserOrganization { org_uuid, access_all: false, - key: String::new(), + akey: String::new(), status: UserOrgStatus::Accepted as i32, atype: UserOrgType::User as i32, } @@ -266,7 +266,7 @@ impl UserOrganization { "MaxStorageGb": 10, // The value doesn't matter, we don't check server-side // These are per user - "Key": self.key, + "Key": self.akey, "Status": self.status, "Type": self.atype, "Enabled": true, diff --git a/src/db/models/user.rs b/src/db/models/user.rs index 2f7183bf..c0d2f73d 100644 --- a/src/db/models/user.rs +++ b/src/db/models/user.rs @@ -163,7 +163,7 @@ impl User { pub fn delete(self, conn: &DbConn) -> EmptyResult { for user_org in UserOrganization::find_by_user(&self.uuid, &*conn) { - if user_org.type_ == UserOrgType::Owner { + if user_org.atype == UserOrgType::Owner { let owner_type = UserOrgType::Owner as i32; if UserOrganization::find_by_org_and_type(&user_org.org_uuid, owner_type, &conn).len() <= 1 { err!("Can't delete last owner")