From f01ef40a8ec1c59f81a575faad90bde73d3e9d48 Mon Sep 17 00:00:00 2001 From: Stefan Melmuk <509385+stefan0xC@users.noreply.github.com> Date: Sat, 25 May 2024 15:20:36 +0200 Subject: [PATCH] differentiate external groups by organization id (#4586) --- src/api/core/public.rs | 3 ++- src/db/models/group.rs | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/api/core/public.rs b/src/api/core/public.rs index 1056f4bb..19cd0de8 100644 --- a/src/api/core/public.rs +++ b/src/api/core/public.rs @@ -137,7 +137,8 @@ async fn ldap_import(data: JsonUpcase, token: PublicToken, mut co if CONFIG.org_groups_enabled() { for group_data in &data.Groups { - let group_uuid = match Group::find_by_external_id(&group_data.ExternalId, &mut conn).await { + let group_uuid = match Group::find_by_external_id_and_org(&group_data.ExternalId, &org_id, &mut conn).await + { Some(group) => group.uuid, None => { let mut group = diff --git a/src/db/models/group.rs b/src/db/models/group.rs index e50853e2..7faf7566 100644 --- a/src/db/models/group.rs +++ b/src/db/models/group.rs @@ -203,10 +203,11 @@ impl Group { }} } - pub async fn find_by_external_id(id: &str, conn: &mut DbConn) -> Option { + pub async fn find_by_external_id_and_org(external_id: &str, org_uuid: &str, conn: &mut DbConn) -> Option { db_run! { conn: { groups::table - .filter(groups::external_id.eq(id)) + .filter(groups::external_id.eq(external_id)) + .filter(groups::organizations_uuid.eq(org_uuid)) .first::(conn) .ok() .from_db()