def get_channel_documents()

in ees_microsoft_teams/microsoft_teams_channels.py [0:0]


    def get_channel_documents(self, teams, ids_list, start_time, end_time):
        """ Fetches all the channel documents from the Microsoft Teams
            :param teams: List of dictionaries containing the team details
            :param ids_list: Shared storage for storing the document ids
            :param start_time: Starting time for fetching data
            :param end_time: Ending time for fetching data
            Returns:
                documents: Documents to be indexed in Workplace Search
        """
        documents = []
        self.logger.debug(
            f"Fetching channel documents for the interval of start time: {start_time} and end time: {end_time}."
        )

        for team in teams:
            team_id = team["id"]
            team_name = team["title"]
            self.logger.info(f"Fetching drives for team: {team_name}")

            drive_response = self.client.get_channel_drives_and_children(
                next_url=f"{constant.GRAPH_BASE_URL}/groups/{team_id}/drives", object_type=constant.DRIVE)

            drive_response_data = get_data_from_http_response(
                self.logger, drive_response,
                f"Could not fetch channels document drives for team:{team_id} Error: {drive_response}",
                f"Error while fetching channels document drives for team: {team_id} Error: {drive_response}")

            if drive_response_data:
                for drive in drive_response_data:
                    drive_id = drive["id"]
                    self.logger.info(f"Fetching root for drive: {drive['name']}")

                    # Logic to append team drives ids for deletion
                    self.local_storage.insert_document_into_doc_id_storage(ids_list, drive_id, constant.CHANNEL_DRIVE,
                                                                           team_id, "")
                    root_response = self.client.get(
                        url=f"{constant.GRAPH_BASE_URL}/groups/{team_id}/drives/{drive_id}/root",
                        object_type=constant.ROOT)

                    if root_response:
                        root_id = root_response["id"]
                        self.logger.info(f"Fetching channel drives for root: {root_response['name']}")

                        # Logic to append drive roots ids for deletion
                        self.local_storage.insert_document_into_doc_id_storage(
                            ids_list, root_id, constant.CHANNEL_ROOT, drive_id, team_id)

                        children_response = self.client.get_channel_drives_and_children(
                            next_url=f"{constant.GRAPH_BASE_URL}/groups/{team_id}/drives/{drive_id}/items/"
                                     f"{root_id}/children", object_type=constant.DRIVE)

                        children_response_data = get_data_from_http_response(
                            self.logger, children_response,
                            f"Could not fetch channels document drive items for team:{team_id} "
                            f"Error: {children_response}",
                            f"Error while fetching channels document drive items for team: {team_id} "
                            f"Error: {children_response}")

                        if children_response_data:
                            document_schema = get_schema_fields("channel_documents", self.object_type_to_index)

                            for child in children_response_data:
                                # Logic to append drive item ids for deletion
                                self.local_storage.insert_document_into_doc_id_storage(
                                    ids_list, child["id"], constant.CHANNEL_DRIVE_ITEM, root_id, drive_id)

                                folder_documents = self.get_folder_documents(
                                    team_id, drive_id, child["id"],
                                    document_schema, [],
                                    ids_list, child["id"],
                                    start_time, end_time, team_name)

                                if folder_documents:
                                    documents.extend(folder_documents)
        return list(unique_everseen(documents))