in ees_sharepoint/sync_sharepoint.py [0:0]
def fetch_lists(self, sites, ids, index):
"""This method fetches lists from all sites in 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 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
Returns:
document: response of sharepoint GET call, with fields specified in the schema
"""
self.logger.info("Fetching lists for all the sites")
responses = []
document = []
if not sites:
self.logger.info(
"No list was created in this interval: start time: %s and end time: %s"
% (self.start_time, self.end_time)
)
return [], [], {}
schema_list = self.get_schema_fields(LISTS)
for site_details in sites:
for site, time_modified in site_details.items():
if parse(self.start_time) > parse(time_modified):
continue
rel_url = f"{site}/_api/web/lists"
self.logger.info(
"Fetching the lists for site: %s from url: %s" % (site, rel_url)
)
query = self.sharepoint_client.get_query(
self.start_time, self.end_time, LISTS
)
response = self.sharepoint_client.get(rel_url, query, LISTS)
response_data = get_results(self.logger, response, LISTS)
if not response_data:
self.logger.info(
"No list was created for the site : %s in this interval: start time: %s and end time: %s"
% (site, self.start_time, self.end_time)
)
continue
self.logger.info(
"Successfully fetched and parsed %s list response for site: %s from SharePoint"
% (len(response_data), site)
)
if index:
if not ids["lists"].get(site):
ids["lists"].update({site: {}})
for i, _ in enumerate(response_data):
doc = {"type": LIST}
for field, response_field in schema_list.items():
doc[field] = response_data[i].get(response_field)
relative_url = response_data[i]["RootFolder"].get('ServerRelativeUrl')
if self.enable_permission is True:
doc["_allow_permissions"] = self.fetch_permissions(
key=LISTS,
site=site,
list_id=doc["id"],
list_url=response_data[i]["ParentWebUrl"],
itemid=None,
)
doc["url"] = urljoin(
self.sharepoint_host,
relative_url,
)
document.append(doc)
ids["lists"][site].update(
{doc["id"]: response_data[i]["Title"]}
)
responses.append(response_data)
lists = {}
libraries = {}
for response in responses:
for result in response:
if result.get("BaseType") == 1:
libraries[result.get("Id")] = [
result.get("ParentWebUrl"),
result.get("Title"),
result.get("LastItemModifiedDate"),
]
else:
lists[result.get("Id")] = [
result.get("ParentWebUrl"),
result.get("Title"),
result.get("LastItemModifiedDate"),
]
documents = {"type": LISTS, "data": document}
return lists, libraries, documents