Fix some formatting issues

This commit is contained in:
Steve Shipway 2020-01-03 15:57:07 +13:00
parent 765eab999a
commit cff4d0af53

View File

@ -201,11 +201,12 @@ def login():
return redirect(url_for('index.index')) return redirect(url_for('index.index'))
if 'azure_token' in session: if 'azure_token' in session:
azure_info = azure.get('me?$select=displayName,givenName,id,mail,surname,userPrincipalName,preferredName,memberOf').text azure_info = azure.get('me?$select=displayName,givenName,id,mail,surname,userPrincipalName,preferredName').text
current_app.logger.info('Azure login returned: '+azure_info) current_app.logger.info('Azure login returned: '+azure_info)
me = json.loads(azure_info) me = json.loads(azure_info)
azure_info = azure.post('me/getMemberGroups',json={'securityEnabledOnly': False}).text azure_info = azure.post('me/getMemberGroups',
json={'securityEnabledOnly': False}).text
current_app.logger.info('Azure groups returned: ' + azure_info) current_app.logger.info('Azure groups returned: ' + azure_info)
grouplookup = json.loads(azure_info) grouplookup = json.loads(azure_info)
# Groups are in mygroups['value'] which is an array # Groups are in mygroups['value'] which is an array
@ -252,20 +253,31 @@ def login():
# Handle group memberships, if defined # Handle group memberships, if defined
if Setting().get('azure_sg_enabled'): if Setting().get('azure_sg_enabled'):
if Setting().get('azure_admin_group') in mygroups: if Setting().get('azure_admin_group') in mygroups:
current_app.logger.info('Setting role for user '+azure_username+' to Administrator due to group membership') current_app.logger.info('Setting role for user ' +
azure_username +
' to Administrator due to group membership')
user.set_role("Administrator") user.set_role("Administrator")
else: else:
if Setting().get('azure_operator_group') in mygroups: if Setting().get('azure_operator_group') in mygroups:
current_app.logger.info('Setting role for user '+azure_username+' to Operator due to group membership') current_app.logger.info('Setting role for user ' +
azure_username +
' to Operator due to group membership')
user.set_role("Operator") user.set_role("Operator")
else: else:
if Setting().get('azure_user_group') in mygroups: if Setting().get('azure_user_group') in mygroups:
current_app.logger.info('Setting role for user '+azure_username+' to User due to group membership') current_app.logger.info('Setting role for user ' +
azure_username +
' to User due to group membership')
user.set_role("User") user.set_role("User")
else: else:
current_app.logger.warning('User '+azure_username+' has no relevant group memberships') current_app.logger.warning('User ' +
azure_username +
' has no relevant group memberships')
session.pop('azure_token', None) session.pop('azure_token', None)
return render_template('login.html', saml_enabled=SAML_ENABLED, error=('User '+azure_username+' is not in any authorised groups.')) return render_template('login.html',
saml_enabled=SAML_ENABLED,
error=('User ' + azure_username +
' is not in any authorised groups.'))
login_user(user, remember=False) login_user(user, remember=False)
signin_history(user.username, 'Azure OAuth', True) signin_history(user.username, 'Azure OAuth', True)