From f42bf61d1b5814f8c9f614b21c783ea79251227c Mon Sep 17 00:00:00 2001 From: Roman Sebastian Karwacik <roman.karwacik@rwth-aachen.de> Date: Thu, 7 May 2020 16:37:02 +0200 Subject: [PATCH] If moodleauth fails, send request to admins, no personal data shared as \`Data\` has to be empty fix fix --- l2pauth.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/l2pauth.py b/l2pauth.py index 4944806..daa68a5 100644 --- a/l2pauth.py +++ b/l2pauth.py @@ -1,5 +1,6 @@ from server import * import requests +from mail import notify_admins L2P_BASE = 'https://www3.elearning.rwth-aachen.de/_vti_bin/l2pservices/api.svc/v1/' OAUTH_BASE = 'https://oauth.campus.rwth-aachen.de/oauth2waitress/oauth2.svc/' @@ -66,7 +67,12 @@ def finish_oauth(): session['l2p_courses'].append(course['uniqueid']) elif session['oauthscope'] == 'moodle': session['moodle_courses'] = [] - for course in moodleget('getmyenrolledcourses', token['access_token'])['Data']: - session['moodle_courses'].append(str(course['id'])) + data = moodleget('getmyenrolledcourses', token['access_token']) + if data and data.get('Data'): + for course in data['Data']: + session['moodle_courses'].append(str(course['id'])) + else: + notify_admins('endpoint_exception', traceback=f"finish_oauth failed while getting moodle courses, data={str(data)}") + raise del session['oauthscope'] oauthget('token', refresh_token=token['refresh_token'], grant_type='invalidate') -- GitLab