Skip to content

Commit d7675f0

Browse files
authored
Merge pull request #94 from itk-dev-rpa/hotfix/child_folder_not_found
Hotfix/child folder not found
2 parents d142c36 + d5ae7d2 commit d7675f0

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Child folders in Graph are now found, even with more than 10 child folders to go through.
13+
- Approving eflyt cases when the person is marked as "Afsluttet" now works.
14+
1015
## [2.8.1] - 2024-12-02
1116

1217
### Fixed

itk_dev_shared_components/eflyt/eflyt_case.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def check_all_approved(browser: webdriver.Chrome) -> bool:
171171

172172
for row in rows:
173173
row_status = row.find_element(By.XPATH, "td[6]").text
174-
if row_status != "Godkendt":
174+
if row_status not in ("Godkendt", "Afsluttet"):
175175
return False
176176
return True
177177

itk_dev_shared_components/graph/mail.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,33 @@ def get_folder_id_from_path(user: str, folder_path: str, graph_access: GraphAcce
122122
# Get child folders
123123
for child_folder in child_folders:
124124
endpoint = f"https://graph.microsoft.com/v1.0/users/{user}/mailFolders/{folder_id}/childFolders"
125-
response = get_request(endpoint, graph_access).json()
126-
folder_id = _find_folder(response, child_folder)
125+
folder_id = recursive_find_folder(endpoint, graph_access, child_folder)
127126
if folder_id is None:
128127
raise ValueError(f"Child folder '{child_folder}' not found under '{main_folder}' for user '{user}'.")
129128

130129
return folder_id
131130

132131

132+
def recursive_find_folder(endpoint: str, graph_access: GraphAccess, target_folder: str) -> str:
133+
"""Look for target folder at endpoint, recursively going through pagination if available and necessary.
134+
135+
Args:
136+
endpoint: Graph endpoint to lookup folder.
137+
graph_access: Access token for Graph API.
138+
target_folder: ID of target folder.
139+
140+
Returns:
141+
Return folder ID.
142+
"""
143+
response = get_request(endpoint, graph_access).json()
144+
folder_id = _find_folder(response, target_folder)
145+
146+
if folder_id is None and '@odata.nextLink' in response:
147+
return recursive_find_folder(response['@odata.nextLink'], graph_access, target_folder)
148+
149+
return folder_id
150+
151+
133152
def list_email_attachments(email: Email, graph_access: GraphAccess) -> tuple[Attachment]:
134153
"""List all attachments of the given email. This function only gets the id, name and size
135154
of the attachment. Use get_attachment_data to get the actual data of an attachment.

tests/test_graph/test_mail.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def setUpClass(cls) -> None:
2626

2727
# Define mail user and folders
2828
cls.user = os.environ['MAIL_USER']
29+
cls.folder_prefix = os.environ['MAIL_FOLDER_PREFIX']
30+
cls.folder_count = os.environ['MAIL_FOLDER_COUNT']
2931
cls.folder1 = os.environ['MAIL_FOLDER1']
3032
cls.folder2 = os.environ['MAIL_FOLDER2']
3133

@@ -40,6 +42,10 @@ def test_correct_usage(self):
4042
self.assertEqual(len(emails), 1, "More than 1 email found in test folder!")
4143
email = emails[0]
4244

45+
# Check more than 10 folders
46+
for i in range(int(self.folder_count)):
47+
mail.get_emails_from_folder(self.user, f"{self.folder_prefix}{i}", self.graph_access)
48+
4349
# Check email subject and body
4450
self.assertEqual(email.subject, "Test subject")
4551
self.assertTrue(email.get_text().startswith("Test text"))

0 commit comments

Comments
 (0)