Browse Source

group: external id is now optional

pull/2667/head
MFijak 3 years ago
parent
commit
85e82b3774
  1. 8
      src/api/core/organizations.rs
  2. 33
      src/db/models/group.rs
  3. 2
      src/db/schemas/mysql/schema.rs
  4. 2
      src/db/schemas/postgresql/schema.rs
  5. 2
      src/db/schemas/sqlite/schema.rs

8
src/api/core/organizations.rs

@ -1755,7 +1755,7 @@ async fn get_groups(org_id: String, _headers: AdminHeaders, conn: DbConn) -> Jso
struct GroupRequest {
Name: String,
AccessAll: Option<bool>,
ExternalId: String,
ExternalId: Option<String>,
Collections: Vec<SelectionReadOnly>,
}
@ -1777,7 +1777,7 @@ impl GroupRequest {
group.name = self.Name.clone();
group.access_all = access_all_value;
group.external_id = self.ExternalId.clone();
group.set_external_id(self.ExternalId.clone());
Ok(group)
}
@ -1882,7 +1882,7 @@ async fn add_update_group(mut group: Group, collections: Vec<SelectionReadOnly>,
"OrganizationId": group.organizations_uuid,
"Name": group.name,
"AccessAll": group.access_all,
"ExternalId": group.external_id
"ExternalId": group.get_external_id()
})))
}
@ -1904,7 +1904,7 @@ async fn get_group_details(_org_id: String, group_id: String, _headers: AdminHea
"OrganizationId": group.organizations_uuid,
"Name": group.name,
"AccessAll": group.access_all,
"ExternalId": group.external_id,
"ExternalId": group.get_external_id(),
"Collections": collections_groups
})))
}

33
src/db/models/group.rs

@ -10,7 +10,7 @@ db_object! {
pub organizations_uuid: String,
pub name: String,
pub access_all: bool,
pub external_id: String,
external_id: Option<String>,
pub creation_date: NaiveDateTime,
pub revision_date: NaiveDateTime,
}
@ -36,18 +36,22 @@ db_object! {
/// Local methods
impl Group {
pub fn new(organizations_uuid: String, name: String, access_all: bool, external_id: String) -> Self {
pub fn new(organizations_uuid: String, name: String, access_all: bool, external_id: Option<String>) -> Self {
let now = Utc::now().naive_utc();
Self {
let mut new_model = Self {
uuid: crate::util::get_uuid(),
organizations_uuid,
name,
access_all,
external_id,
external_id: None,
creation_date: now,
revision_date: now,
}
};
new_model.set_external_id(external_id);
new_model
}
pub fn to_json(&self) -> Value {
@ -63,6 +67,25 @@ impl Group {
"RevisionDate": format_date(&self.revision_date)
})
}
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 fn get_external_id(&self) -> Option<String> {
self.external_id.clone()
}
}
impl CollectionGroup {

2
src/db/schemas/mysql/schema.rs

@ -226,7 +226,7 @@ table! {
organizations_uuid -> Text,
name -> Text,
access_all -> Bool,
external_id -> Text,
external_id -> Nullable<Text>,
creation_date -> Timestamp,
revision_date -> Timestamp,
}

2
src/db/schemas/postgresql/schema.rs

@ -226,7 +226,7 @@ table! {
organizations_uuid -> Text,
name -> Text,
access_all -> Bool,
external_id -> Text,
external_id -> Nullable<Text>,
creation_date -> Timestamp,
revision_date -> Timestamp,
}

2
src/db/schemas/sqlite/schema.rs

@ -226,7 +226,7 @@ table! {
organizations_uuid -> Text,
name -> Text,
access_all -> Bool,
external_id -> Text,
external_id -> Nullable<Text>,
creation_date -> Timestamp,
revision_date -> Timestamp,
}

Loading…
Cancel
Save