From 3eb47441dc32cf53783032f4abdf6a4f2e0313e7 Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Fri, 3 May 2024 18:08:04 +0200 Subject: [PATCH] PICARD-2886: If MB server OAuth2 logout fails, show a dialog box Offer the user the options to retry the request, cancel or remove locally stored credentials anyway. This prevents the user being unable to remove local credentials and being stuck with broken credentials due to some technical error. --- picard/ui/options/general.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/picard/ui/options/general.py b/picard/ui/options/general.py index ee8ebbf53..dec305c65 100644 --- a/picard/ui/options/general.py +++ b/picard/ui/options/general.py @@ -28,7 +28,10 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -from PyQt6 import QtCore +from PyQt6 import ( + QtCore, + QtWidgets, +) from picard.config import get_config from picard.const import ( @@ -165,7 +168,27 @@ class GeneralOptionsPage(OptionsPage): self.tagger.mb_logout(self.on_logout_finished) def on_logout_finished(self, successful, error_msg=None): - self.update_login_logout(error_msg) + if not successful: + msg = QtWidgets.QMessageBox(self) + msg.setIcon(QtWidgets.QMessageBox.Icon.Warning) + msg.setWindowTitle(_("Logout error")) + msg.setText(_( + "A server error occurred while revoking access to the MusicBrainz server: %s\n" + "\n" + "Remove locally stored credentials anyway?" + ) % error_msg) + msg.setStandardButtons( + QtWidgets.QMessageBox.StandardButton.Yes + | QtWidgets.QMessageBox.StandardButton.No + | QtWidgets.QMessageBox.StandardButton.Retry) + result = msg.exec() + if result == QtWidgets.QMessageBox.StandardButton.Yes: + oauth_manager = self.tagger.webservice.oauth_manager + oauth_manager.forget_access_token() + oauth_manager.forget_refresh_token() + elif result == QtWidgets.QMessageBox.StandardButton.Retry: + self.logout() + self.update_login_logout() def restore_defaults(self): super().restore_defaults()