6969 TextSection ,
7070)
7171from onyx .connectors .sharepoint .connector_utils import (
72+ SharepointPermissionCache ,
7273 get_sharepoint_external_access ,
7374 get_sharepoint_hierarchy_node_external_access ,
7475)
@@ -464,6 +465,9 @@ class SharepointConnectorCheckpoint(ConnectorCheckpoint):
464465 # Track yielded document IDs to avoid processing the same document twice.
465466 # The Microsoft Graph delta API can return the same item on multiple pages.
466467 seen_document_ids : set [str ] = Field (default_factory = set )
468+ permission_cache : SharepointPermissionCache = Field (
469+ default_factory = SharepointPermissionCache
470+ )
467471
468472
469473class SharepointAuthMethod (Enum ):
@@ -799,12 +803,14 @@ def _convert_driveitem_to_document_with_permissions(
799803 access_token : str | None = None ,
800804 treat_sharing_link_as_public : bool = False ,
801805 raw_file_callback : RawFileCallback | None = None ,
806+ permission_cache : SharepointPermissionCache | None = None ,
802807) -> Document | ConnectorFailure | None :
803808 if not driveitem .name or not driveitem .id :
804809 raise ValueError ("DriveItem name/id is required" )
805810
806811 if include_permissions and ctx is None :
807812 raise ValueError ("ClientContext is required for permissions" )
813+ permission_cache = permission_cache or SharepointPermissionCache ()
808814
809815 mime_type = driveitem .mime_type
810816 if not mime_type or mime_type in OnyxMimeTypes .EXCLUDED_IMAGE_TYPES :
@@ -939,6 +945,7 @@ def _convert_driveitem_to_document_with_permissions(
939945 external_access = get_sharepoint_external_access (
940946 ctx = ctx ,
941947 graph_client = graph_client ,
948+ permission_cache = permission_cache ,
942949 drive_item = sdk_item ,
943950 drive_name = drive_name ,
944951 add_prefix = True ,
@@ -981,6 +988,7 @@ def _convert_sitepage_to_document(
981988 site_name : str | None ,
982989 ctx : ClientContext | None ,
983990 graph_client : GraphClient ,
991+ permission_cache : SharepointPermissionCache ,
984992 include_permissions : bool = False ,
985993 parent_hierarchy_raw_node_id : str | None = None ,
986994 treat_sharing_link_as_public : bool = False ,
@@ -1111,6 +1119,7 @@ def _convert_sitepage_to_document(
11111119 external_access = get_sharepoint_external_access (
11121120 ctx = ctx , # ty: ignore[invalid-argument-type]
11131121 graph_client = graph_client ,
1122+ permission_cache = permission_cache ,
11141123 site_page = site_page ,
11151124 add_prefix = True ,
11161125 treat_sharing_link_as_public = treat_sharing_link_as_public ,
@@ -1155,6 +1164,7 @@ def _convert_driveitem_to_slim_document(
11551164 drive_name : str ,
11561165 ctx : ClientContext ,
11571166 graph_client : GraphClient ,
1167+ permission_cache : SharepointPermissionCache ,
11581168 parent_hierarchy_raw_node_id : str | None = None ,
11591169 treat_sharing_link_as_public : bool = False ,
11601170) -> SlimDocument :
@@ -1165,6 +1175,7 @@ def _convert_driveitem_to_slim_document(
11651175 external_access = get_sharepoint_external_access (
11661176 ctx = ctx ,
11671177 graph_client = graph_client ,
1178+ permission_cache = permission_cache ,
11681179 drive_item = sdk_item ,
11691180 drive_name = drive_name ,
11701181 treat_sharing_link_as_public = treat_sharing_link_as_public ,
@@ -1186,6 +1197,7 @@ def _convert_sitepage_to_slim_document(
11861197 site_page : dict [str , Any ],
11871198 ctx : ClientContext | None ,
11881199 graph_client : GraphClient ,
1200+ permission_cache : SharepointPermissionCache ,
11891201 parent_hierarchy_raw_node_id : str | None = None ,
11901202 treat_sharing_link_as_public : bool = False ,
11911203) -> SlimDocument :
@@ -1197,6 +1209,7 @@ def _convert_sitepage_to_slim_document(
11971209 external_access = get_sharepoint_external_access (
11981210 ctx = ctx , # ty: ignore[invalid-argument-type]
11991211 graph_client = graph_client ,
1212+ permission_cache = permission_cache ,
12001213 site_page = site_page ,
12011214 treat_sharing_link_as_public = treat_sharing_link_as_public ,
12021215 )
@@ -2323,6 +2336,7 @@ def _fetch_slim_documents_from_sharepoint(
23232336 drive_name ,
23242337 ctx ,
23252338 self .graph_client ,
2339+ temp_checkpoint .permission_cache ,
23262340 parent_hierarchy_raw_node_id = parent_hierarchy_url ,
23272341 treat_sharing_link_as_public = self .treat_sharing_link_as_public ,
23282342 )
@@ -2372,6 +2386,7 @@ def _fetch_slim_documents_from_sharepoint(
23722386 site_page ,
23732387 ctx ,
23742388 self .graph_client ,
2389+ temp_checkpoint .permission_cache ,
23752390 parent_hierarchy_raw_node_id = site_descriptor .url ,
23762391 treat_sharing_link_as_public = self .treat_sharing_link_as_public ,
23772392 )
@@ -2570,6 +2585,7 @@ def _yield_site_hierarchy_node(
25702585 external_access = get_sharepoint_hierarchy_node_external_access (
25712586 ctx ,
25722587 self .graph_client ,
2588+ checkpoint .permission_cache ,
25732589 HierarchyNodeType .SITE ,
25742590 )
25752591
@@ -2604,6 +2620,7 @@ def _yield_drive_hierarchy_node(
26042620 external_access = get_sharepoint_hierarchy_node_external_access (
26052621 ctx ,
26062622 self .graph_client ,
2623+ checkpoint .permission_cache ,
26072624 HierarchyNodeType .DRIVE ,
26082625 drive_name = drive_name ,
26092626 )
@@ -2657,6 +2674,7 @@ def _yield_folder_hierarchy_nodes(
26572674 external_access = get_sharepoint_hierarchy_node_external_access (
26582675 ctx ,
26592676 self .graph_client ,
2677+ checkpoint .permission_cache ,
26602678 HierarchyNodeType .FOLDER ,
26612679 folder_url = folder_url ,
26622680 )
@@ -2794,6 +2812,7 @@ def _process_drive_item(
27942812 drive_name ,
27952813 ctx ,
27962814 self .graph_client ,
2815+ permission_cache = checkpoint .permission_cache ,
27972816 include_permissions = include_permissions ,
27982817 parent_hierarchy_raw_node_id = parent_hierarchy_url ,
27992818 graph_api_base = self .graph_api_base ,
@@ -3187,6 +3206,7 @@ def _load_from_checkpoint(
31873206 site_descriptor .drive_name ,
31883207 client_ctx ,
31893208 self .graph_client ,
3209+ permission_cache = checkpoint .permission_cache ,
31903210 include_permissions = include_permissions ,
31913211 # Site pages have the site as their parent
31923212 parent_hierarchy_raw_node_id = site_descriptor .url ,
@@ -3449,6 +3469,7 @@ def _reindex_site_page(
34493469 site_descriptor .drive_name ,
34503470 ctx ,
34513471 self .graph_client ,
3472+ permission_cache = dedup .permission_cache ,
34523473 include_permissions = include_permissions ,
34533474 parent_hierarchy_raw_node_id = site_descriptor .url ,
34543475 treat_sharing_link_as_public = self .treat_sharing_link_as_public ,
0 commit comments