From 68fdfb2b7be95d3e2dfdae07052c5c9243b5cac0 Mon Sep 17 00:00:00 2001 From: Setu Shah Date: Sun, 19 Jul 2020 14:46:15 -0700 Subject: [PATCH] Batch user save calls --- app/server/social_auth.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/server/social_auth.py b/app/server/social_auth.py index 32c6400d..62b819ac 100644 --- a/app/server/social_auth.py +++ b/app/server/social_auth.py @@ -96,12 +96,17 @@ def fetch_okta_oauth2_permissions(strategy, details, user=None, is_new=False, *a is_superuser = admin_group_name in response.get("groups", []) is_staff = admin_group_name in response.get("groups", []) + user_changed = False + if user.is_superuser != is_superuser: user.is_superuser = is_superuser - user.save() + user_changed = user_changed or True if user.is_staff != is_staff: user.is_staff = is_staff + user_changed = user_changed or True + + if user_changed: user.save() @@ -124,10 +129,15 @@ def fetch_okta_openidconnect_permissions(strategy, details, user=None, is_new=Fa is_superuser = admin_group_name in response.get("groups", []) is_staff = admin_group_name in response.get("groups", []) + user_changed = False + if user.is_superuser != is_superuser: user.is_superuser = is_superuser - user.save() + user_changed = user_changed or True if user.is_staff != is_staff: user.is_staff = is_staff + user_changed = user_changed or True + + if user_changed: user.save()