aboutsummaryrefslogtreecommitdiff
path: root/src/db/models
diff options
context:
space:
mode:
authorFolke Ashberg <[email protected]>2023-06-28 20:37:13 +0200
committerMathijs van Veluw <[email protected]>2023-07-04 20:26:03 +0200
commit6050c8dac50ad892d8ed8e00cd0c930c42dff039 (patch)
treea74f0e20a96f91a581f6702e04ddb3fd0875c5d7 /src/db/models
parent19e671ff25bffa47424b5af44264c2c74c2cc84b (diff)
downloadvaultwarden-6050c8dac50ad892d8ed8e00cd0c930c42dff039.tar.gz
vaultwarden-6050c8dac50ad892d8ed8e00cd0c930c42dff039.zip
Added-External_id for Collections
Diffstat (limited to 'src/db/models')
-rw-r--r--src/db/models/collection.rs29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/db/models/collection.rs b/src/db/models/collection.rs
index 6a9acab8..c534fa4f 100644
--- a/src/db/models/collection.rs
+++ b/src/db/models/collection.rs
@@ -10,6 +10,7 @@ db_object! {
pub uuid: String,
pub org_uuid: String,
pub name: String,
+ pub external_id: Option<String>,
}
#[derive(Identifiable, Queryable, Insertable)]
@@ -33,18 +34,21 @@ db_object! {
/// Local methods
impl Collection {
- pub fn new(org_uuid: String, name: String) -> Self {
- Self {
+ pub fn new(org_uuid: String, name: String, external_id: Option<String>) -> Self {
+ let mut new_model = Self {
uuid: crate::util::get_uuid(),
-
org_uuid,
name,
- }
+ external_id: None,
+ };
+
+ new_model.set_external_id(external_id);
+ new_model
}
pub fn to_json(&self) -> Value {
json!({
- "ExternalId": null, // Not support by us
+ "ExternalId": self.external_id,
"Id": self.uuid,
"OrganizationId": self.org_uuid,
"Name": self.name,
@@ -52,6 +56,21 @@ impl Collection {
})
}
+ pub fn set_external_id(&mut self, external_id: Option<String>) {
+ //Check if external id is empty. We don't want to have
+ //empty strings in the database
+ match external_id {
+ Some(external_id) => {
+ if external_id.is_empty() {
+ self.external_id = None;
+ } else {
+ self.external_id = Some(external_id)
+ }
+ }
+ None => self.external_id = None,
+ }
+ }
+
pub async fn to_json_details(
&self,
user_uuid: &str,