From 5aec6df063551ba4c71dfe37e70fed1feecd48f3 Mon Sep 17 00:00:00 2001 From: Sean Story Date: Mon, 18 Nov 2024 09:57:39 -0600 Subject: [PATCH] [outlook] Filter users to only include active ones (#2967) Co-authored-by: Artem Shelkovnikov --- connectors/sources/outlook.py | 4 +++- tests/sources/test_outlook.py | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/connectors/sources/outlook.py b/connectors/sources/outlook.py index 47a495162..1f3573fb0 100644 --- a/connectors/sources/outlook.py +++ b/connectors/sources/outlook.py @@ -44,6 +44,7 @@ html_to_text, iso_utc, retryable, + url_encode, ) RETRIES = 3 @@ -410,7 +411,8 @@ async def _fetch_token(self): ) async def get_users(self): access_token = await self._fetch_token() - url = f"https://graph.microsoft.com/v1.0/users?$top={TOP}" + filter_ = url_encode("accountEnabled eq true") + url = f"https://graph.microsoft.com/v1.0/users?$top={TOP}&$filter={filter_}" while True: try: async with self._get_session.get( diff --git a/tests/sources/test_outlook.py b/tests/sources/test_outlook.py index 31cc507c2..213717112 100644 --- a/tests/sources/test_outlook.py +++ b/tests/sources/test_outlook.py @@ -420,7 +420,10 @@ def side_effect_function(url, headers): Args: url, ssl: Params required for get call """ - if url == "https://graph.microsoft.com/v1.0/users?$top=999": + if ( + url + == "https://graph.microsoft.com/v1.0/users?$top=999&$filter=accountEnabled%20eq%20true" + ): return get_json_mock( mock_response={ "@odata.nextLink": "https://graph.microsoft.com/v1.0/users?$top=999&$skipToken=fake-skip-token",