Spiegel von
https://github.com/dani-garcia/vaultwarden.git
synchronisiert 2024-08-18 09:55:25 +02:00
Merge pull request #3623 from fashberg/main
Added-External_id for Collections
Dieser Commit ist enthalten in:
Commit
1bee46f64b
11 geänderte Dateien mit 36 neuen und 8 gelöschten Zeilen
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE collections ADD COLUMN external_id TEXT;
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE collections ADD COLUMN external_id TEXT;
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE collections ADD COLUMN external_id TEXT;
|
|
@ -106,6 +106,7 @@ struct OrgData {
|
||||||
CollectionName: String,
|
CollectionName: String,
|
||||||
Key: String,
|
Key: String,
|
||||||
Name: String,
|
Name: String,
|
||||||
|
ExternalId: String,
|
||||||
Keys: Option<OrgKeyData>,
|
Keys: Option<OrgKeyData>,
|
||||||
#[serde(rename = "PlanType")]
|
#[serde(rename = "PlanType")]
|
||||||
_PlanType: NumberOrString, // Ignored, always use the same plan
|
_PlanType: NumberOrString, // Ignored, always use the same plan
|
||||||
|
@ -124,6 +125,7 @@ struct NewCollectionData {
|
||||||
Name: String,
|
Name: String,
|
||||||
Groups: Vec<NewCollectionObjectData>,
|
Groups: Vec<NewCollectionObjectData>,
|
||||||
Users: Vec<NewCollectionObjectData>,
|
Users: Vec<NewCollectionObjectData>,
|
||||||
|
ExternalId: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
@ -168,7 +170,7 @@ async fn create_organization(headers: Headers, data: JsonUpcase<OrgData>, mut co
|
||||||
|
|
||||||
let org = Organization::new(data.Name, data.BillingEmail, private_key, public_key);
|
let org = Organization::new(data.Name, data.BillingEmail, private_key, public_key);
|
||||||
let mut user_org = UserOrganization::new(headers.user.uuid, org.uuid.clone());
|
let mut user_org = UserOrganization::new(headers.user.uuid, org.uuid.clone());
|
||||||
let collection = Collection::new(org.uuid.clone(), data.CollectionName);
|
let collection = Collection::new(org.uuid.clone(), data.CollectionName, Some(data.ExternalId));
|
||||||
|
|
||||||
user_org.akey = data.Key;
|
user_org.akey = data.Key;
|
||||||
user_org.access_all = true;
|
user_org.access_all = true;
|
||||||
|
@ -390,7 +392,7 @@ async fn post_organization_collections(
|
||||||
None => err!("Can't find organization details"),
|
None => err!("Can't find organization details"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let collection = Collection::new(org.uuid, data.Name);
|
let collection = Collection::new(org.uuid, data.Name, data.ExternalId);
|
||||||
collection.save(&mut conn).await?;
|
collection.save(&mut conn).await?;
|
||||||
|
|
||||||
log_event(
|
log_event(
|
||||||
|
@ -467,6 +469,7 @@ async fn post_organization_collection_update(
|
||||||
}
|
}
|
||||||
|
|
||||||
collection.name = data.Name;
|
collection.name = data.Name;
|
||||||
|
collection.external_id = data.ExternalId;
|
||||||
collection.save(&mut conn).await?;
|
collection.save(&mut conn).await?;
|
||||||
|
|
||||||
log_event(
|
log_event(
|
||||||
|
@ -1580,7 +1583,7 @@ async fn post_org_import(
|
||||||
|
|
||||||
let mut collections = Vec::new();
|
let mut collections = Vec::new();
|
||||||
for coll in data.Collections {
|
for coll in data.Collections {
|
||||||
let collection = Collection::new(org_id.clone(), coll.Name);
|
let collection = Collection::new(org_id.clone(), coll.Name, coll.ExternalId);
|
||||||
if collection.save(&mut conn).await.is_err() {
|
if collection.save(&mut conn).await.is_err() {
|
||||||
collections.push(Err(Error::new("Failed to create Collection", "Failed to create Collection")));
|
collections.push(Err(Error::new("Failed to create Collection", "Failed to create Collection")));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -10,6 +10,7 @@ db_object! {
|
||||||
pub uuid: String,
|
pub uuid: String,
|
||||||
pub org_uuid: String,
|
pub org_uuid: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub external_id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Identifiable, Queryable, Insertable)]
|
#[derive(Identifiable, Queryable, Insertable)]
|
||||||
|
@ -33,18 +34,21 @@ db_object! {
|
||||||
|
|
||||||
/// Local methods
|
/// Local methods
|
||||||
impl Collection {
|
impl Collection {
|
||||||
pub fn new(org_uuid: String, name: String) -> Self {
|
pub fn new(org_uuid: String, name: String, external_id: Option<String>) -> Self {
|
||||||
Self {
|
let mut new_model = Self {
|
||||||
uuid: crate::util::get_uuid(),
|
uuid: crate::util::get_uuid(),
|
||||||
|
|
||||||
org_uuid,
|
org_uuid,
|
||||||
name,
|
name,
|
||||||
}
|
external_id: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
new_model.set_external_id(external_id);
|
||||||
|
new_model
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_json(&self) -> Value {
|
pub fn to_json(&self) -> Value {
|
||||||
json!({
|
json!({
|
||||||
"ExternalId": null, // Not support by us
|
"ExternalId": self.external_id,
|
||||||
"Id": self.uuid,
|
"Id": self.uuid,
|
||||||
"OrganizationId": self.org_uuid,
|
"OrganizationId": self.org_uuid,
|
||||||
"Name": self.name,
|
"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(
|
pub async fn to_json_details(
|
||||||
&self,
|
&self,
|
||||||
user_uuid: &str,
|
user_uuid: &str,
|
||||||
|
|
|
@ -38,6 +38,7 @@ table! {
|
||||||
uuid -> Text,
|
uuid -> Text,
|
||||||
org_uuid -> Text,
|
org_uuid -> Text,
|
||||||
name -> Text,
|
name -> Text,
|
||||||
|
external_id -> Nullable<Text>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ table! {
|
||||||
uuid -> Text,
|
uuid -> Text,
|
||||||
org_uuid -> Text,
|
org_uuid -> Text,
|
||||||
name -> Text,
|
name -> Text,
|
||||||
|
external_id -> Nullable<Text>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ table! {
|
||||||
uuid -> Text,
|
uuid -> Text,
|
||||||
org_uuid -> Text,
|
org_uuid -> Text,
|
||||||
name -> Text,
|
name -> Text,
|
||||||
|
external_id -> Nullable<Text>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Laden …
In neuem Issue referenzieren