From 023697e778eda2cedfd01dc7dcd6f3768868a010 Mon Sep 17 00:00:00 2001
From: Emanuel Ferreira <contatoferreirads@gmail.com>
Date: Wed, 13 Nov 2024 23:11:32 -0300
Subject: [PATCH] feat: add get_permission_info to resource reader mixin +
 readers (#16835)

---
 .../llama_index/core/readers/base.py             | 16 ++++++++++++++++
 llama-index-core/pyproject.toml                  |  2 +-
 .../readers/microsoft_onedrive/base.py           | 15 +++++++++++++++
 .../pyproject.toml                               |  2 +-
 .../readers/microsoft_sharepoint/base.py         | 16 +++++++++++++++-
 .../pyproject.toml                               |  2 +-
 6 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/llama-index-core/llama_index/core/readers/base.py b/llama-index-core/llama_index/core/readers/base.py
index e233058277..8cfc76cc83 100644
--- a/llama-index-core/llama_index/core/readers/base.py
+++ b/llama-index-core/llama_index/core/readers/base.py
@@ -82,6 +82,22 @@ class ResourcesReaderMixin(ABC):
         """
         return self.list_resources(*args, **kwargs)
 
+    def get_permission_info(self, resource_id: str, *args: Any, **kwargs: Any) -> Dict:
+        """
+        Get a dictionary of information about the permissions of a specific resource.
+        """
+        raise NotImplementedError(
+            f"{self.__class__.__name__} does not provide get_permission_info method currently"
+        )
+
+    async def aget_permission_info(
+        self, resource_id: str, *args: Any, **kwargs: Any
+    ) -> Dict:
+        """
+        Get a dictionary of information about the permissions of a specific resource asynchronously.
+        """
+        return self.get_permission_info(resource_id, *args, **kwargs)
+
     @abstractmethod
     def get_resource_info(self, resource_id: str, *args: Any, **kwargs: Any) -> Dict:
         """
diff --git a/llama-index-core/pyproject.toml b/llama-index-core/pyproject.toml
index ee5d7d7aa8..fabe167ef5 100644
--- a/llama-index-core/pyproject.toml
+++ b/llama-index-core/pyproject.toml
@@ -46,7 +46,7 @@ name = "llama-index-core"
 packages = [{include = "llama_index"}]
 readme = "README.md"
 repository = "https://github.com/run-llama/llama_index"
-version = "0.11.23"
+version = "0.11.24"
 
 [tool.poetry.dependencies]
 SQLAlchemy = {extras = ["asyncio"], version = ">=1.4.49"}
diff --git a/llama-index-integrations/readers/llama-index-readers-microsoft-onedrive/llama_index/readers/microsoft_onedrive/base.py b/llama-index-integrations/readers/llama-index-readers-microsoft-onedrive/llama_index/readers/microsoft_onedrive/base.py
index 81cff6103c..320a2e9b2a 100644
--- a/llama-index-integrations/readers/llama-index-readers-microsoft-onedrive/llama_index/readers/microsoft_onedrive/base.py
+++ b/llama-index-integrations/readers/llama-index-readers-microsoft-onedrive/llama_index/readers/microsoft_onedrive/base.py
@@ -653,6 +653,21 @@ class OneDriveReader(BasePydanticReader, ResourcesReaderMixin, FileSystemReaderM
                 f"An error occurred while loading the data: {e}", exc_info=True
             )
 
+    def get_permission_info(self, resource_id: str, *args: Any, **kwargs: Any) -> Dict:
+        payloads = self._get_downloaded_files_metadata(
+            file_paths=[resource_id], *args, **kwargs
+        )
+
+        item = next(
+            payload.resource_info
+            for payload in payloads
+            if payload.resource_info["file_path"] == resource_id
+        )
+
+        access_token = self._authenticate_with_msal()
+
+        return self._get_permissions_info(item, self.userprincipalname, access_token)
+
     def _get_permissions_info(
         self, item: Dict[str, Any], userprincipalname: str, access_token: str
     ) -> Dict[str, Any]:
diff --git a/llama-index-integrations/readers/llama-index-readers-microsoft-onedrive/pyproject.toml b/llama-index-integrations/readers/llama-index-readers-microsoft-onedrive/pyproject.toml
index 03c61a94d8..432af9e2d8 100644
--- a/llama-index-integrations/readers/llama-index-readers-microsoft-onedrive/pyproject.toml
+++ b/llama-index-integrations/readers/llama-index-readers-microsoft-onedrive/pyproject.toml
@@ -29,7 +29,7 @@ license = "MIT"
 maintainers = ["godwin3737"]
 name = "llama-index-readers-microsoft-onedrive"
 readme = "README.md"
-version = "0.2.2"
+version = "0.2.3"
 
 [tool.poetry.dependencies]
 python = ">=3.8.1,<4.0"
diff --git a/llama-index-integrations/readers/llama-index-readers-microsoft-sharepoint/llama_index/readers/microsoft_sharepoint/base.py b/llama-index-integrations/readers/llama-index-readers-microsoft-sharepoint/llama_index/readers/microsoft_sharepoint/base.py
index 12d94bd6f0..8ec1bac73c 100644
--- a/llama-index-integrations/readers/llama-index-readers-microsoft-sharepoint/llama_index/readers/microsoft_sharepoint/base.py
+++ b/llama-index-integrations/readers/llama-index-readers-microsoft-sharepoint/llama_index/readers/microsoft_sharepoint/base.py
@@ -770,13 +770,27 @@ class SharePointReader(BasePydanticReader, ResourcesReaderMixin, FileSystemReade
 
         return response.json()
 
+    def get_permission_info(self, resource_id: str, **kwargs) -> Dict:
+        """
+        Get a dictionary of information about the permissions of a specific resource.
+        """
+        try:
+            item = self._get_item_from_path(Path(resource_id))
+            return self._get_permissions_info(item)
+        except Exception as exp:
+            logger.error(
+                "An error occurred while fetching file information from SharePoint: %s",
+                exp,
+            )
+            raise
+
     def get_resource_info(self, resource_id: str, **kwargs) -> Dict:
         """
         Retrieves metadata for a specified file in SharePoint without downloading it.
 
         Args:
             input_file (Path): The path of the file in SharePoint. The path should include
-                                the SharePoint site name and the folder path. e.g. "site_name/folder_path/file_name".
+                the SharePoint site name and the folder path. e.g. "site_name/folder_path/file_name".
         """
         try:
             item = self._get_item_from_path(Path(resource_id))
diff --git a/llama-index-integrations/readers/llama-index-readers-microsoft-sharepoint/pyproject.toml b/llama-index-integrations/readers/llama-index-readers-microsoft-sharepoint/pyproject.toml
index 8101f5f49d..3fb136bbd7 100644
--- a/llama-index-integrations/readers/llama-index-readers-microsoft-sharepoint/pyproject.toml
+++ b/llama-index-integrations/readers/llama-index-readers-microsoft-sharepoint/pyproject.toml
@@ -29,7 +29,7 @@ license = "MIT"
 maintainers = ["arun-soliton"]
 name = "llama-index-readers-microsoft-sharepoint"
 readme = "README.md"
-version = "0.4.0"
+version = "0.4.1"
 
 [tool.poetry.dependencies]
 python = ">=3.8.1,<4.0"
-- 
GitLab