Skip to content

Commit

Permalink
[Google Drive] Fix permission fetching bug for domain-wide delegation…
Browse files Browse the repository at this point in the history
… sync (#2024)
  • Loading branch information
jedrazb authored and elastic committed Jan 9, 2024
1 parent b3199df commit c7aa134
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions connectors/sources/google_drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ async def list_files(self, fetch_permissions=False):
yield file

async def list_files_from_my_drive(self, fetch_permissions=False):
"""Get files from Google Drive. Files can have any type.
"""Retrieves files from Google Drive, with an option to fetch permissions (DLS).
This function optimizes the retrieval process based on the 'fetch_permissions' flag.
If 'fetch_permissions' is True, the function filters for files the user can edit
("trashed=false and 'me' in writers") as permission fetching requires write access.
If 'fetch_permissions' is False, it simply filters out trashed files ("trashed=false"),
allowing a broader file retrieval.
Args:
include_permissions (bool): flag to select permissions in the request query
Expand All @@ -181,17 +187,19 @@ async def list_files_from_my_drive(self, fetch_permissions=False):
dict: Documents from Google Drive.
"""

files_fields = (
DRIVE_ITEMS_FIELDS_WITH_PERMISSIONS
if fetch_permissions
else DRIVE_ITEMS_FIELDS
)
if fetch_permissions:
files_fields = DRIVE_ITEMS_FIELDS_WITH_PERMISSIONS
# Google Drive API required write access to fetch file's permissions
list_query = "trashed=false and 'me' in writers"
else:
files_fields = DRIVE_ITEMS_FIELDS
list_query = "trashed=false"

async for file in self.api_call_paged(
resource="files",
method="list",
corpora="user",
q="trashed=false",
q=list_query,
orderBy="modifiedTime desc",
fields=f"files({files_fields}),incompleteSearch,nextPageToken",
includeItemsFromAllDrives=False,
Expand Down

0 comments on commit c7aa134

Please sign in to comment.