Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding headers and count on all potential advanced aad queries #2920

Merged
merged 4 commits into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions packages/mgt-components/src/graph/graph.user.ts
Original file line number Diff line number Diff line change
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
Loading