Merge pull request #4 from Medality-Health/update-user-on-login

Add property to control user updates on login
This commit is contained in:
Jeff Cohen 2024-02-01 13:10:21 -05:00 committed by GitHub
commit 43a971c1ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 22 deletions

View File

@ -1 +1 @@
__version__ = "1.0.7"
__version__ = "1.0.8"

View File

@ -111,6 +111,9 @@ class WPOpenEdxOAuth2(BaseOAuth2):
# list can be delimited with commas, spaces, whatever.
SCOPE_SEPARATOR = " "
# Enable updates on the Django user object on successful WordPress login.
UPDATE_USER_ON_LOGIN = True
# private utility function. not part of psa.
def _urlopen(self, url):
"""
@ -409,28 +412,28 @@ class WPOpenEdxOAuth2(BaseOAuth2):
except User.DoesNotExist:
return self.user_details
if (user.is_superuser != self.user_details["is_superuser"]) or (
user.is_staff != self.user_details["is_staff"]
):
user.is_superuser = self.user_details["is_superuser"]
user.is_staff = self.user_details["is_staff"]
user.save()
logger.info(
"Updated the is_superuser/is_staff flags for user {username}".format(
username=user.username
if self.UPDATE_USER_ON_LOGIN:
if (user.is_superuser != self.user_details["is_superuser"]) or (
user.is_staff != self.user_details["is_staff"]
):
user.is_superuser = self.user_details["is_superuser"]
user.is_staff = self.user_details["is_staff"]
user.save()
logger.info(
"Updated the is_superuser/is_staff flags for user {username}".format(
username=user.username
)
)
)
if (user.first_name != self.user_details["first_name"]) or (
user.last_name != self.user_details["last_name"]
):
user.first_name = self.user_details["first_name"]
user.last_name = self.user_details["last_name"]
user.save()
logger.info(
"Updated first_name/last_name for user {username}".format(
username=user.username
if (user.first_name != self.user_details["first_name"]) or (
user.last_name != self.user_details["last_name"]
):
user.first_name = self.user_details["first_name"]
user.last_name = self.user_details["last_name"]
user.save()
logger.info(
"Updated first_name/last_name for user {username}".format(
username=user.username
)
)
)
return self.user_details