From 39e0c4f155d893ad046fae3be7cb8831fa116f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Fri, 29 May 2026 10:11:42 +0200 Subject: [PATCH] Introduce MINIMUM_USER_SELECT with id and accountEnabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace ensureSelectContains with ensureMinimumSelect that adds all fields our code requires (id for photo fetching and Map keys, accountEnabled for disabled user filtering). Separates the minimum viable set from the default projection list. Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: Fredrik Adelöw --- .../src/microsoftGraph/read.test.ts | 2 +- .../src/microsoftGraph/read.ts | 33 ++++++++----------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/read.test.ts b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/read.test.ts index 7c697fd837..a9677ed6b1 100644 --- a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/read.test.ts +++ b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/read.test.ts @@ -1540,7 +1540,7 @@ describe('read microsoft graph', () => { expect(client.getUsers).toHaveBeenCalledTimes(1); expect(client.getUsers).toHaveBeenCalledWith( { - select: ['mail', 'accountEnabled'], + select: ['mail', 'id', 'accountEnabled'], top: 999, }, undefined, diff --git a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/read.ts b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/read.ts index 678c762c4a..783bbcb881 100644 --- a/plugins/catalog-backend-module-msgraph/src/microsoftGraph/read.ts +++ b/plugins/catalog-backend-module-msgraph/src/microsoftGraph/read.ts @@ -44,11 +44,9 @@ const PAGE_SIZE = 999; // The default properties returned by the Microsoft Graph API for User // objects when no $select is specified. accountEnabled is NOT included -// in this set — it requires an explicit $select. We always request it -// so that filterDisabledUsers can work. +// in this set — it requires an explicit $select. // https://learn.microsoft.com/en-us/graph/api/user-list#optional-query-parameters const DEFAULT_USER_SELECT = [ - 'accountEnabled', 'businessPhones', 'displayName', 'givenName', @@ -62,19 +60,17 @@ const DEFAULT_USER_SELECT = [ 'userPrincipalName', ]; -function ensureSelectContains( - select: string[] | undefined, - field: string, -): string[] { +// Fields that our code requires regardless of what the user or default +// projection provides. These are always added to the $select list. +const MINIMUM_USER_SELECT = ['id', 'accountEnabled']; + +function ensureMinimumSelect(select: string[] | undefined): string[] { const base = select ?? DEFAULT_USER_SELECT; - if ( - base.some( - s => s.toLocaleLowerCase('en-US') === field.toLocaleLowerCase('en-US'), - ) - ) { - return base; - } - return [...base, field]; + const lower = new Set(base.map(s => s.toLocaleLowerCase('en-US'))); + const missing = MINIMUM_USER_SELECT.filter( + f => !lower.has(f.toLocaleLowerCase('en-US')), + ); + return missing.length > 0 ? [...base, ...missing] : base; } async function* filterDisabledUsers( @@ -108,7 +104,7 @@ export async function readMicrosoftGraphUsers( { filter: options.userFilter, expand: options.userExpand, - select: ensureSelectContains(options.userSelect, 'accountEnabled'), + select: ensureMinimumSelect(options.userSelect), top: PAGE_SIZE, }, options.queryMode, @@ -172,10 +168,7 @@ export async function readMicrosoftGraphUsersInGroups( group.id!, { expand: options.userExpand, - select: ensureSelectContains( - options.userSelect, - 'accountEnabled', - ), + select: ensureMinimumSelect(options.userSelect), top: PAGE_SIZE, }, options.queryMode,