in ees_microsoft_teams/microsoft_teams_calendars.py [0:0]
def get_calendars(self, ids_list, start_time, end_time):
""" Fetches all calendar events from Microsoft Teams.
:param ids_list: List of ids
Returns:
permissions_dict: List of dictionaries containing calendar id and their members
documents: Documents to be indexed in Workplace Search
"""
self.logger.debug("Fetching users for Calendar Events")
users = self.users_obj.get_all_users()
self.logger.info("Fetched the users metadata. Attempting to extract the meetings from the calendar...")
documents = []
permissions_dict = defaultdict(list)
calendar_schema = get_schema_fields("calendar", self.object_type_to_index)
for user in users:
# Logic to append calendar for deletion
self.local_storage.insert_document_into_doc_id_storage(ids_list, user["userId"], constant.USER, "", "")
try:
response = self.client.get_calendars(
next_url=f'{constant.GRAPH_BASE_URL}/users/{user["userId"]}/events',
start_time=start_time,
end_time=end_time
)
if not response:
continue
for calendar in response:
if not calendar['isCancelled']:
# Logic to append calendar for deletion
self.local_storage.insert_document_into_doc_id_storage(
ids_list,
calendar["id"],
constant.CALENDAR,
user["userId"],
""
)
calendar_dict = {"type": MEETING}
permissions_dict[user["displayName"]].append(calendar["id"])
attendee_list = []
for att in calendar['attendees']:
attendee_list.append(f"{att['emailAddress']['name']}"
f"({att['emailAddress']['address']})")
attendees = ",".join(attendee_list)
body = self.get_calendar_detail(attendees, calendar)
for ws_field, ms_fields in calendar_schema.items():
calendar_dict[ws_field] = calendar[ms_fields]
calendar_dict['body'] = body
if calendar['onlineMeeting']:
calendar_dict['url'] = calendar["onlineMeeting"]['joinUrl']
calendar_dict["_allow_permissions"] = []
if self.config.get_value("enable_document_permission"):
calendar_dict["_allow_permissions"] = [calendar['id']]
documents.append(calendar_dict)
except Exception as exception:
self.logger.exception(f"Error while fetching the calendar events from teams. Error: {exception}")
raise exception
return permissions_dict, documents