From ff478559b0f169a0606fbb2e34429dc929130dcb Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Wed, 17 Jan 2024 19:50:46 +0100 Subject: [PATCH] Change bool setting to more flexible callback function --- cura/OAuth2/AuthorizationService.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cura/OAuth2/AuthorizationService.py b/cura/OAuth2/AuthorizationService.py index 06478e911b..29c426e46f 100644 --- a/cura/OAuth2/AuthorizationService.py +++ b/cura/OAuth2/AuthorizationService.py @@ -34,7 +34,7 @@ class AuthorizationService: def __init__(self, settings: "OAuth2Settings", preferences: Optional["Preferences"] = None, - get_user_profile: bool = True) -> None: + callback_auth_data_retrieved: Callable[[], None] = None) -> None: # Emit signal when authentication is completed. self.onAuthStateChanged = Signal() @@ -48,7 +48,7 @@ class AuthorizationService: self._auth_url = "{}/authorize".format(self._settings.OAUTH_SERVER_URL) self._auth_data: Optional[AuthenticationResponse] = None self._user_profile: Optional["UserProfile"] = None - self._get_user_profile: bool = get_user_profile + self._callback_auth_data_retrieved = self.getUserProfile if callback_auth_data_retrieved is None else callback_auth_data_retrieved self._preferences = preferences self._server = LocalAuthorizationServer(self._auth_helpers, self._onAuthStateChanged, daemon=True) self._currently_refreshing_token = False # Whether we are currently in the process of refreshing auth. Don't make new requests while busy. @@ -298,8 +298,7 @@ class AuthorizationService: self._auth_data = auth_data self._currently_refreshing_token = False if auth_data: - if self._get_user_profile: - self.getUserProfile() + self._callback_auth_data_retrieved() self._preferences.setValue(self._settings.AUTH_DATA_PREFERENCE_KEY, json.dumps(auth_data.dump())) else: Logger.log("d", "Clearing the user profile")