in ees_sharepoint/sync_sharepoint.py [0:0]
def fetch_sites(self, parent_site_url, sites, ids, index, start_time, end_time):
"""This method fetches sites from a collection and invokes the
index permission method to get the document level permissions.
If the fetching is not successful, it logs proper message.
:param parent_site_url: parent site relative path
:param sites: dictionary of site path and it's last updated time
:param ids: structure containing id's of all objects
:param index: index, boolean value
:param start_time: start time for fetching the data
:param end_time: end time for fetching the data
Returns:
sites: list of site paths
documents: response of sharepoint GET call with fields specified in the schema
"""
rel_url = f"{parent_site_url}/_api/web/webs"
self.logger.info("Fetching the sites detail from url: %s" % (rel_url))
query = self.sharepoint_client.get_query(start_time, end_time, SITES)
response = self.sharepoint_client.get(rel_url, query, SITES)
document_list = []
response_data = get_results(self.logger, response, SITES)
if not response_data:
self.logger.info(
"No sites were created in %s for this interval: start time: %s and end time: %s"
% (parent_site_url, start_time, end_time)
)
return sites, []
self.logger.info(
"Successfully fetched and parsed %s sites response from SharePoint"
% len(response_data)
)
schema = self.get_schema_fields(SITES)
if index:
for i, _ in enumerate(response_data):
doc = {"type": SITE}
# need to convert date to iso else workplace search throws error on date format Invalid field
# value: Value '2021-09-29T08:13:00' cannot be parsed as a date (RFC 3339)"]}
response_data[i]["Created"] += "Z"
for field, response_field in schema.items():
doc[field] = response_data[i].get(response_field)
if self.enable_permission is True:
doc["_allow_permissions"] = self.fetch_permissions(
key=SITES, site=response_data[i]["ServerRelativeUrl"]
)
document_list.append(doc)
ids["sites"].update({doc["id"]: response_data[i]["ServerRelativeUrl"]})
for result in response_data:
site_server_url = result.get("ServerRelativeUrl")
sites.update({site_server_url: result.get("LastItemModifiedDate")})
_, documents = self.fetch_sites(site_server_url, sites, ids, index, start_time, end_time)
document_list.extend(documents)
return sites, document_list