From da736cc4be16c5706bd1fdfae16f10dd3229782b Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 25 Apr 2019 14:11:42 +0200 Subject: [PATCH 1/2] Add import redirects with deprecation warning so we don't break plugin compatibility --- cura/PrinterOutput/PrintJobOutputModel.py | 4 ++++ cura/PrinterOutput/PrinterOutputModel.py | 4 ++++ cura/PrinterOutputDevice.py | 4 ++++ 3 files changed, 12 insertions(+) create mode 100644 cura/PrinterOutput/PrintJobOutputModel.py create mode 100644 cura/PrinterOutput/PrinterOutputModel.py create mode 100644 cura/PrinterOutputDevice.py diff --git a/cura/PrinterOutput/PrintJobOutputModel.py b/cura/PrinterOutput/PrintJobOutputModel.py new file mode 100644 index 0000000000..a810d40e9a --- /dev/null +++ b/cura/PrinterOutput/PrintJobOutputModel.py @@ -0,0 +1,4 @@ +import warnings +warnings.warn("Importing cura.PrinterOutput.PrintJobOutputModel has been deprecated since 4.1, use cura.PrinterOutput.Models.PrintJobOutputModel inststad", DeprecationWarning, stacklevel=2) +# We moved the the models to one submodule deeper +from cura.PrinterOutput.Models.PrintJobOutputModel import PrintJobOutputModel \ No newline at end of file diff --git a/cura/PrinterOutput/PrinterOutputModel.py b/cura/PrinterOutput/PrinterOutputModel.py new file mode 100644 index 0000000000..736e6c7aa3 --- /dev/null +++ b/cura/PrinterOutput/PrinterOutputModel.py @@ -0,0 +1,4 @@ +import warnings +warnings.warn("Importing cura.PrinterOutput.PrinterOutputModel has been deprecated since 4.1, use cura.PrinterOutput.Models.PrinterOutputModel inststad", DeprecationWarning, stacklevel=2) +# We moved the the models to one submodule deeper +from cura.PrinterOutput.Models.PrinterOutputModel import PrinterOutputModel \ No newline at end of file diff --git a/cura/PrinterOutputDevice.py b/cura/PrinterOutputDevice.py new file mode 100644 index 0000000000..0da1ae349d --- /dev/null +++ b/cura/PrinterOutputDevice.py @@ -0,0 +1,4 @@ +import warnings +warnings.warn("Importing cura.PrinterOutputDevice has been deprecated since 4.1, use cura.PrinterOutput.PrinterOutputDevice inststad", DeprecationWarning, stacklevel=2) +# We moved the PrinterOutput device to it's own submodule. +from cura.PrinterOutput.PrinterOutputDevice import PrinterOutputDevice, ConnectionState \ No newline at end of file From 5f76070f051832d921c7fc287934a4c79dafae44 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 25 Apr 2019 16:16:44 +0200 Subject: [PATCH 2/2] Fix situation where authtoken wasnt updated for the toolbox request headers --- cura/API/Account.py | 7 ++++++- cura/OAuth2/AuthorizationService.py | 4 ++++ plugins/Toolbox/src/Toolbox.py | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cura/API/Account.py b/cura/API/Account.py index 30401454b3..0e3af0e6c1 100644 --- a/cura/API/Account.py +++ b/cura/API/Account.py @@ -29,6 +29,7 @@ i18n_catalog = i18nCatalog("cura") class Account(QObject): # Signal emitted when user logged in or out. loginStateChanged = pyqtSignal(bool) + accessTokenChanged = pyqtSignal() def __init__(self, application: "CuraApplication", parent = None) -> None: super().__init__(parent) @@ -59,8 +60,12 @@ class Account(QObject): self._authorization_service.initialize(self._application.getPreferences()) self._authorization_service.onAuthStateChanged.connect(self._onLoginStateChanged) self._authorization_service.onAuthenticationError.connect(self._onLoginStateChanged) + self._authorization_service.accessTokenChanged.connect(self._onAccessTokenChanged) self._authorization_service.loadAuthDataFromPreferences() + def _onAccessTokenChanged(self): + self.accessTokenChanged.emit() + ## Returns a boolean indicating whether the given authentication is applied against staging or not. @property def is_staging(self) -> bool: @@ -105,7 +110,7 @@ class Account(QObject): return None return user_profile.profile_image_url - @pyqtProperty(str, notify=loginStateChanged) + @pyqtProperty(str, notify=accessTokenChanged) def accessToken(self) -> Optional[str]: return self._authorization_service.getAccessToken() diff --git a/cura/OAuth2/AuthorizationService.py b/cura/OAuth2/AuthorizationService.py index 209e79c0cf..27041b1f80 100644 --- a/cura/OAuth2/AuthorizationService.py +++ b/cura/OAuth2/AuthorizationService.py @@ -34,6 +34,8 @@ class AuthorizationService: # Emit signal when authentication failed. onAuthenticationError = Signal() + accessTokenChanged = Signal() + def __init__(self, settings: "OAuth2Settings", preferences: Optional["Preferences"] = None) -> None: self._settings = settings self._auth_helpers = AuthorizationHelpers(settings) @@ -214,6 +216,8 @@ class AuthorizationService: self._user_profile = None self._preferences.resetPreference(self._settings.AUTH_DATA_PREFERENCE_KEY) + self.accessTokenChanged.emit() + def _onMessageActionTriggered(self, _, action): if action == "retry": self.loadAuthDataFromPreferences() diff --git a/plugins/Toolbox/src/Toolbox.py b/plugins/Toolbox/src/Toolbox.py index 6d21b8e6f0..82ee60f70b 100644 --- a/plugins/Toolbox/src/Toolbox.py +++ b/plugins/Toolbox/src/Toolbox.py @@ -105,6 +105,7 @@ class Toolbox(QObject, Extension): self._application.initializationFinished.connect(self._onAppInitialized) self._application.getCuraAPI().account.loginStateChanged.connect(self._updateRequestHeader) + self._application.getCuraAPI().account.accessTokenChanged.connect(self._updateRequestHeader) # Signals: # --------------------------------------------------------------------------