Skip to content

Commit

Permalink
fix: adding headers and count on all potential advanced aad queries (#…
Browse files Browse the repository at this point in the history
…2920)

Adding headers + count on requests when userFilters are present
  • Loading branch information
sebastienlevert committed Jan 9, 2024
1 parent 1cf2bc4 commit 90b2dd1
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions packages/mgt-components/src/graph/graph.user.ts
Expand Up @@ -72,7 +72,7 @@ export const getUsers = async (graph: IGraph, userFilters = '', top = 10): Promi
const graphClient: GraphRequest = graph.api(apiString).top(top);

if (userFilters) {
graphClient.filter(userFilters);
graphClient.filter(userFilters).header('ConsistencyLevel', 'eventual').count(true);
}

try {
Expand Down Expand Up @@ -242,9 +242,9 @@ export const getUsersForUserIds = async (
} else {
apiUrl = `/users/${id}`;
if (userFilters) {
apiUrl += `${apiUrl}?$filter=${userFilters}`;
apiUrl += `${apiUrl}?$filter=${userFilters}&$count=true`;
}
batch.get(id, apiUrl, validUserByIdScopes);
batch.get(id, apiUrl, validUserByIdScopes, userFilters ? { ConsistencyLevel: 'eventual' } : {});
notInCache.push(id);
}
}
Expand Down Expand Up @@ -418,15 +418,11 @@ export const findUsers = async (graph: IGraph, query: string, top = 10, userFilt
}

const encodedQuery = `${query.replace(/#/g, '%2523')}`;
const graphBuilder = graph
.api('users')
.header('ConsistencyLevel', 'eventual')
.count(true)
.search(`"displayName:${encodedQuery}" OR "mail:${encodedQuery}"`);
const graphBuilder = graph.api('users').search(`"displayName:${encodedQuery}" OR "mail:${encodedQuery}"`);
let graphResult: CollectionResponse<User>;

if (userFilters !== '') {
graphBuilder.filter(userFilters);
graphBuilder.filter(userFilters).header('ConsistencyLevel', 'eventual').count(true);
}
try {
graphResult = (await graphBuilder.top(top).middlewareOptions(prepScopes(scopes)).get()) as CollectionResponse<User>;
Expand Down Expand Up @@ -503,12 +499,14 @@ export const findGroupMembers = async (
if (peopleFilters) {
filter += query ? ` and ${peopleFilters}` : peopleFilters;
}
const graphResult = (await graph
.api(apiUrl)
.count(true)
.top(top)
.filter(filter)
.header('ConsistencyLevel', 'eventual')

const graphClient: GraphRequest = graph.api(apiUrl).top(top).filter(filter);

if (userFilters) {
graphClient.header('ConsistencyLevel', 'eventual').count(true);
}

const graphResult = (await graphClient
.middlewareOptions(prepScopes(allValidScopes))
.get()) as CollectionResponse<User>;

Expand Down

0 comments on commit 90b2dd1

Please sign in to comment.