From 0ae904e9bc8dd1d02b0457be833ac53f8198e788 Mon Sep 17 00:00:00 2001 From: Keepers Date: Fri, 3 Feb 2023 21:10:22 -0700 Subject: [PATCH] fix user query filtering on null userType (#2399) ## Description UserType can be null for users created before 2014. In order to not filter them out with the other guest users, we have to amend our user query to only exclude guests, and retain all other persons. ## Does this PR need a docs update or release note? - [x] :white_check_mark: Yes, it's included ## Type of change - [x] :bug: Bugfix ## Test Plan - [x] :muscle: Manual - [x] :zap: Unit test - [x] :green_heart: E2E --- CHANGELOG.md | 1 + src/internal/connector/discovery/api/users.go | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0303c9206..7c029b8f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Backing up a calendar that has the same name as the default calendar - Added additional backoff-retry to all OneDrive queries. +- Users with `null` userType values are no longer excluded from user queries. ### Known Issues diff --git a/src/internal/connector/discovery/api/users.go b/src/internal/connector/discovery/api/users.go index e4a8e0f00..c08297a9e 100644 --- a/src/internal/connector/discovery/api/users.go +++ b/src/internal/connector/discovery/api/users.go @@ -3,6 +3,7 @@ package api import ( "context" + absser "github.com/microsoft/kiota-abstractions-go" msgraphgocore "github.com/microsoftgraph/msgraph-sdk-go-core" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/microsoftgraph/msgraph-sdk-go/users" @@ -58,14 +59,27 @@ const ( // require more fine-tuned controls in the future. // https://stackoverflow.com/questions/64044266/error-message-unsupported-or-invalid-query-filter-clause-specified-for-property // +// ne 'Guest' ensures we don't filter out users where userType = null, which can happen +// for user accounts created prior to 2014. In order to use the `ne` comparator, we +// MUST include $count=true and the ConsistencyLevel: eventual header. +// https://stackoverflow.com/questions/49340485/how-to-filter-users-by-usertype-null +// //nolint:lll -var userFilterNoGuests = "onPremisesSyncEnabled eq true OR userType eq 'Member'" +var userFilterNoGuests = "onPremisesSyncEnabled eq true OR userType ne 'Guest'" + +// I can't believe I have to do this. +var t = true func userOptions(fs *string) *users.UsersRequestBuilderGetRequestConfiguration { + headers := absser.NewRequestHeaders() + headers.Add("ConsistencyLevel", "eventual") + return &users.UsersRequestBuilderGetRequestConfiguration{ + Headers: headers, QueryParameters: &users.UsersRequestBuilderGetQueryParameters{ Select: []string{userSelectID, userSelectPrincipalName, userSelectDisplayName}, Filter: fs, + Count: &t, }, } }