aboutsummaryrefslogtreecommitdiff
path: root/src/db/models
diff options
context:
space:
mode:
authorEmil Madsen <[email protected]>2019-05-20 21:12:41 +0200
committerEmil Madsen <[email protected]>2019-05-20 21:12:41 +0200
commitab95a69dc8be20401bcc3167c51fb5f8b99ed2a2 (patch)
tree97cdac13cbacfb3642d384766a607190dd258567 /src/db/models
parent85c8a01f4a0f51efb2432396743878477529b72f (diff)
downloadvaultwarden-ab95a69dc8be20401bcc3167c51fb5f8b99ed2a2.tar.gz
vaultwarden-ab95a69dc8be20401bcc3167c51fb5f8b99ed2a2.zip
Rework migrations for MySQL
Diffstat (limited to 'src/db/models')
-rw-r--r--src/db/models/attachment.rs6
-rw-r--r--src/db/models/cipher.rs20
-rw-r--r--src/db/models/collection.rs2
-rw-r--r--src/db/models/device.rs14
-rw-r--r--src/db/models/organization.rs16
-rw-r--r--src/db/models/two_factor.rs14
-rw-r--r--src/db/models/user.rs6
7 files changed, 39 insertions, 39 deletions
diff --git a/src/db/models/attachment.rs b/src/db/models/attachment.rs
index b27704f0..030400e7 100644
--- a/src/db/models/attachment.rs
+++ b/src/db/models/attachment.rs
@@ -12,7 +12,7 @@ pub struct Attachment {
pub cipher_uuid: String,
pub file_name: String,
pub file_size: i32,
- pub key: Option<String>,
+ pub akey: Option<String>,
}
/// Local methods
@@ -23,7 +23,7 @@ impl Attachment {
cipher_uuid,
file_name,
file_size,
- key: None,
+ akey: None,
}
}
@@ -43,7 +43,7 @@ impl Attachment {
"FileName": self.file_name,
"Size": self.file_size.to_string(),
"SizeName": display_size,
- "Key": self.key,
+ "Key": self.akey,
"Object": "attachment"
})
}
diff --git a/src/db/models/cipher.rs b/src/db/models/cipher.rs
index 21cabb90..0bd7673c 100644
--- a/src/db/models/cipher.rs
+++ b/src/db/models/cipher.rs
@@ -24,7 +24,7 @@ pub struct Cipher {
Card = 3,
Identity = 4
*/
- pub type_: i32,
+ pub atype: i32,
pub name: String,
pub notes: Option<String>,
pub fields: Option<String>,
@@ -37,7 +37,7 @@ pub struct Cipher {
/// Local methods
impl Cipher {
- pub fn new(type_: i32, name: String) -> Self {
+ pub fn new(atype: i32, name: String) -> Self {
let now = Utc::now().naive_utc();
Self {
@@ -48,7 +48,7 @@ impl Cipher {
user_uuid: None,
organization_uuid: None,
- type_,
+ atype,
favorite: false,
name,
@@ -94,7 +94,7 @@ impl Cipher {
// TODO: ******* Backwards compat start **********
// To remove backwards compatibility, just remove this entire section
// and remove the compat code from ciphers::update_cipher_from_data
- if self.type_ == 1 && data_json["Uris"].is_array() {
+ if self.atype == 1 && data_json["Uris"].is_array() {
let uri = data_json["Uris"][0]["Uri"].clone();
data_json["Uri"] = uri;
}
@@ -102,7 +102,7 @@ impl Cipher {
let mut json_object = json!({
"Id": self.uuid,
- "Type": self.type_,
+ "Type": self.atype,
"RevisionDate": format_date(&self.updated_at),
"FolderId": self.get_folder_uuid(&user_uuid, &conn),
"Favorite": self.favorite,
@@ -123,7 +123,7 @@ impl Cipher {
"PasswordHistory": password_history_json,
});
- let key = match self.type_ {
+ let key = match self.atype {
1 => "Login",
2 => "SecureNote",
3 => "Card",
@@ -237,7 +237,7 @@ impl Cipher {
// Cipher owner
users_organizations::access_all.eq(true).or(
// access_all in Organization
- users_organizations::type_.le(UserOrgType::Admin as i32).or(
+ users_organizations::atype.le(UserOrgType::Admin as i32).or(
// Org admin or owner
users_collections::user_uuid.eq(user_uuid).and(
users_collections::read_only.eq(false), //R/W access to collection
@@ -268,7 +268,7 @@ impl Cipher {
// Cipher owner
users_organizations::access_all.eq(true).or(
// access_all in Organization
- users_organizations::type_.le(UserOrgType::Admin as i32).or(
+ users_organizations::atype.le(UserOrgType::Admin as i32).or(
// Org admin or owner
users_collections::user_uuid.eq(user_uuid), // Access to Collection
),
@@ -315,7 +315,7 @@ impl Cipher {
))
.filter(ciphers::user_uuid.eq(user_uuid).or( // Cipher owner
users_organizations::access_all.eq(true).or( // access_all in Organization
- users_organizations::type_.le(UserOrgType::Admin as i32).or( // Org admin or owner
+ users_organizations::atype.le(UserOrgType::Admin as i32).or( // Org admin or owner
users_collections::user_uuid.eq(user_uuid).and( // Access to Collection
users_organizations::status.eq(UserOrgStatus::Confirmed as i32)
)
@@ -365,7 +365,7 @@ impl Cipher {
.filter(ciphers_collections::cipher_uuid.eq(&self.uuid))
.filter(users_collections::user_uuid.eq(user_id).or( // User has access to collection
users_organizations::access_all.eq(true).or( // User has access all
- users_organizations::type_.le(UserOrgType::Admin as i32) // User is admin or owner
+ users_organizations::atype.le(UserOrgType::Admin as i32) // User is admin or owner
)
))
.select(ciphers_collections::collection_uuid)
diff --git a/src/db/models/collection.rs b/src/db/models/collection.rs
index c6047aa7..e2b58cf1 100644
--- a/src/db/models/collection.rs
+++ b/src/db/models/collection.rs
@@ -146,7 +146,7 @@ impl Collection {
.filter(
users_collections::collection_uuid.eq(uuid).or( // Directly accessed collection
users_organizations::access_all.eq(true).or( // access_all in Organization
- users_organizations::type_.le(UserOrgType::Admin as i32) // Org admin or owner
+ users_organizations::atype.le(UserOrgType::Admin as i32) // Org admin or owner
)
)
).select(collections::all_columns)
diff --git a/src/db/models/device.rs b/src/db/models/device.rs
index 157bd9a3..83824bac 100644
--- a/src/db/models/device.rs
+++ b/src/db/models/device.rs
@@ -15,7 +15,7 @@ pub struct Device {
pub name: String,
/// https://github.com/bitwarden/core/tree/master/src/Core/Enums
- pub type_: i32,
+ pub atype: i32,
pub push_token: Option<String>,
pub refresh_token: String,
@@ -25,7 +25,7 @@ pub struct Device {
/// Local methods
impl Device {
- pub fn new(uuid: String, user_uuid: String, name: String, type_: i32) -> Self {
+ pub fn new(uuid: String, user_uuid: String, name: String, atype: i32) -> Self {
let now = Utc::now().naive_utc();
Self {
@@ -35,7 +35,7 @@ impl Device {
user_uuid,
name,
- type_,
+ atype,
push_token: None,
refresh_token: String::new(),
@@ -70,10 +70,10 @@ impl Device {
let time_now = Utc::now().naive_utc();
self.updated_at = time_now;
- let orgowner: Vec<_> = orgs.iter().filter(|o| o.type_ == 0).map(|o| o.org_uuid.clone()).collect();
- let orgadmin: Vec<_> = orgs.iter().filter(|o| o.type_ == 1).map(|o| o.org_uuid.clone()).collect();
- let orguser: Vec<_> = orgs.iter().filter(|o| o.type_ == 2).map(|o| o.org_uuid.clone()).collect();
- let orgmanager: Vec<_> = orgs.iter().filter(|o| o.type_ == 3).map(|o| o.org_uuid.clone()).collect();
+ let orgowner: Vec<_> = orgs.iter().filter(|o| o.atype == 0).map(|o| o.org_uuid.clone()).collect();
+ let orgadmin: Vec<_> = orgs.iter().filter(|o| o.atype == 1).map(|o| o.org_uuid.clone()).collect();
+ let orguser: Vec<_> = orgs.iter().filter(|o| o.atype == 2).map(|o| o.org_uuid.clone()).collect();
+ let orgmanager: Vec<_> = orgs.iter().filter(|o| o.atype == 3).map(|o| o.org_uuid.clone()).collect();
// Create the JWT claims struct, to send to the client
diff --git a/src/db/models/organization.rs b/src/db/models/organization.rs
index 491c4fc3..463e1d0f 100644
--- a/src/db/models/organization.rs
+++ b/src/db/models/organization.rs
@@ -23,7 +23,7 @@ pub struct UserOrganization {
pub access_all: bool,
pub key: String,
pub status: i32,
- pub type_: i32,
+ pub atype: i32,
}
pub enum UserOrgStatus {
@@ -198,7 +198,7 @@ impl UserOrganization {
access_all: false,
key: String::new(),
status: UserOrgStatus::Accepted as i32,
- type_: UserOrgType::User as i32,
+ atype: UserOrgType::User as i32,
}
}
}
@@ -268,7 +268,7 @@ impl UserOrganization {
// These are per user
"Key": self.key,
"Status": self.status,
- "Type": self.type_,
+ "Type": self.atype,
"Enabled": true,
"Object": "profileOrganization",
@@ -285,7 +285,7 @@ impl UserOrganization {
"Email": user.email,
"Status": self.status,
- "Type": self.type_,
+ "Type": self.atype,
"AccessAll": self.access_all,
"Object": "organizationUserUserDetails",
@@ -315,7 +315,7 @@ impl UserOrganization {
"UserId": self.user_uuid,
"Status": self.status,
- "Type": self.type_,
+ "Type": self.atype,
"AccessAll": self.access_all,
"Collections": coll_uuids,
@@ -357,7 +357,7 @@ impl UserOrganization {
}
pub fn has_full_access(self) -> bool {
- self.access_all || self.type_ >= UserOrgType::Admin
+ self.access_all || self.atype >= UserOrgType::Admin
}
pub fn find_by_uuid(uuid: &str, conn: &DbConn) -> Option<Self> {
@@ -405,10 +405,10 @@ impl UserOrganization {
.expect("Error loading user organizations")
}
- pub fn find_by_org_and_type(org_uuid: &str, type_: i32, conn: &DbConn) -> Vec<Self> {
+ pub fn find_by_org_and_type(org_uuid: &str, atype: i32, conn: &DbConn) -> Vec<Self> {
users_organizations::table
.filter(users_organizations::org_uuid.eq(org_uuid))
- .filter(users_organizations::type_.eq(type_))
+ .filter(users_organizations::atype.eq(atype))
.load::<Self>(&**conn)
.expect("Error loading user organizations")
}
diff --git a/src/db/models/two_factor.rs b/src/db/models/two_factor.rs
index fc48313d..30a7b475 100644
--- a/src/db/models/two_factor.rs
+++ b/src/db/models/two_factor.rs
@@ -9,7 +9,7 @@ use super::User;
pub struct TwoFactor {
pub uuid: String,
pub user_uuid: String,
- pub type_: i32,
+ pub atype: i32,
pub enabled: bool,
pub data: String,
}
@@ -32,11 +32,11 @@ pub enum TwoFactorType {
/// Local methods
impl TwoFactor {
- pub fn new(user_uuid: String, type_: TwoFactorType, data: String) -> Self {
+ pub fn new(user_uuid: String, atype: TwoFactorType, data: String) -> Self {
Self {
uuid: crate::util::get_uuid(),
user_uuid,
- type_: type_ as i32,
+ atype: atype as i32,
enabled: true,
data,
}
@@ -53,7 +53,7 @@ impl TwoFactor {
pub fn to_json_list(&self) -> Value {
json!({
"Enabled": self.enabled,
- "Type": self.type_,
+ "Type": self.atype,
"Object": "twoFactorProvider"
})
}
@@ -85,15 +85,15 @@ impl TwoFactor {
pub fn find_by_user(user_uuid: &str, conn: &DbConn) -> Vec<Self> {
twofactor::table
.filter(twofactor::user_uuid.eq(user_uuid))
- .filter(twofactor::type_.lt(1000)) // Filter implementation types
+ .filter(twofactor::atype.lt(1000)) // Filter implementation types
.load::<Self>(&**conn)
.expect("Error loading twofactor")
}
- pub fn find_by_user_and_type(user_uuid: &str, type_: i32, conn: &DbConn) -> Option<Self> {
+ pub fn find_by_user_and_type(user_uuid: &str, atype: i32, conn: &DbConn) -> Option<Self> {
twofactor::table
.filter(twofactor::user_uuid.eq(user_uuid))
- .filter(twofactor::type_.eq(type_))
+ .filter(twofactor::atype.eq(atype))
.first::<Self>(&**conn)
.ok()
}
diff --git a/src/db/models/user.rs b/src/db/models/user.rs
index 150a97b0..2f7183bf 100644
--- a/src/db/models/user.rs
+++ b/src/db/models/user.rs
@@ -20,7 +20,7 @@ pub struct User {
pub password_iterations: i32,
pub password_hint: Option<String>,
- pub key: String,
+ pub akey: String,
pub private_key: Option<String>,
pub public_key: Option<String>,
@@ -58,7 +58,7 @@ impl User {
updated_at: now,
name: email.clone(),
email,
- key: String::new(),
+ akey: String::new(),
password_hash: Vec::new(),
salt: crypto::get_random_64(),
@@ -140,7 +140,7 @@ impl User {
"MasterPasswordHint": self.password_hint,
"Culture": "en-US",
"TwoFactorEnabled": twofactor_enabled,
- "Key": self.key,
+ "Key": self.akey,
"PrivateKey": self.private_key,
"SecurityStamp": self.security_stamp,
"Organizations": orgs_json,