From b53d92c2baae9739bcf29ff7b0ec4a16e4275a9e Mon Sep 17 00:00:00 2001 From: Stefan Melmuk <509385+stefan0xC@users.noreply.github.com> Date: Thu, 1 Aug 2024 19:45:42 +0200 Subject: [PATCH] make access_all optional (#4812) * make access_all optional * use #[serde(default)] instead of unwrapping --- src/api/core/organizations.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs index 745a281147..b21f9d76f8 100644 --- a/src/api/core/organizations.rs +++ b/src/api/core/organizations.rs @@ -844,7 +844,8 @@ struct InviteData { groups: Vec, r#type: NumberOrString, collections: Option>, - access_all: Option, + #[serde(default)] + access_all: bool, } #[post("/organizations//users/invite", data = "")] @@ -896,7 +897,7 @@ async fn send_invite(org_id: &str, data: Json, headers: AdminHeaders }; let mut new_user = UserOrganization::new(user.uuid.clone(), String::from(org_id)); - let access_all = data.access_all.unwrap_or(false); + let access_all = data.access_all; new_user.access_all = access_all; new_user.atype = new_type; new_user.status = user_org_status; @@ -1297,6 +1298,7 @@ struct EditUserData { r#type: NumberOrString, collections: Option>, groups: Option>, + #[serde(default)] access_all: bool, } @@ -2223,7 +2225,8 @@ async fn get_groups(org_id: &str, _headers: ManagerHeadersLoose, mut conn: DbCon #[serde(rename_all = "camelCase")] struct GroupRequest { name: String, - access_all: Option, + #[serde(default)] + access_all: bool, external_id: Option, collections: Vec, users: Vec, @@ -2231,17 +2234,12 @@ struct GroupRequest { impl GroupRequest { pub fn to_group(&self, organizations_uuid: &str) -> Group { - Group::new( - String::from(organizations_uuid), - self.name.clone(), - self.access_all.unwrap_or(false), - self.external_id.clone(), - ) + Group::new(String::from(organizations_uuid), self.name.clone(), self.access_all, self.external_id.clone()) } pub fn update_group(&self, mut group: Group) -> Group { group.name.clone_from(&self.name); - group.access_all = self.access_all.unwrap_or(false); + group.access_all = self.access_all; // Group Updates do not support changing the external_id // These input fields are in a disabled state, and can only be updated/added via ldap_import