From 72080a3ccab3e0eb633b9d67af29c8025eafcac2 Mon Sep 17 00:00:00 2001 From: Kostas Karmas Date: Thu, 8 Apr 2021 12:46:52 +0200 Subject: [PATCH] Delete the auth data on upgrade from 4.8 if the scope doesn't match If the user account scope is outdated, delete it when upgrading from 4.8 to 4.9. This means that the user will have to log in again, to make sure they get the correct account scope. CURA-8093 --- cura/API/Account.py | 10 ++++++---- .../VersionUpgrade48to49/VersionUpgrade48to49.py | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cura/API/Account.py b/cura/API/Account.py index d5ef2bfcb9..4e8c90e052 100644 --- a/cura/API/Account.py +++ b/cura/API/Account.py @@ -58,6 +58,11 @@ class Account(QObject): manualSyncEnabledChanged = pyqtSignal(bool) updatePackagesEnabledChanged = pyqtSignal(bool) + CLIENT_SCOPES = "account.user.read drive.backup.read drive.backup.write packages.download " \ + "packages.rating.read packages.rating.write connect.cluster.read connect.cluster.write " \ + "library.project.read library.project.write cura.printjob.read cura.printjob.write " \ + "cura.mesh.read cura.mesh.write" + def __init__(self, application: "CuraApplication", parent = None) -> None: super().__init__(parent) self._application = application @@ -79,10 +84,7 @@ class Account(QObject): CALLBACK_PORT=self._callback_port, CALLBACK_URL="http://localhost:{}/callback".format(self._callback_port), CLIENT_ID="um----------------------------ultimaker_cura", - CLIENT_SCOPES="account.user.read drive.backup.read drive.backup.write packages.download " - "packages.rating.read packages.rating.write connect.cluster.read connect.cluster.write " - "library.project.read library.project.write cura.printjob.read cura.printjob.write " - "cura.mesh.read cura.mesh.write", + CLIENT_SCOPES=self.CLIENT_SCOPES, AUTH_DATA_PREFERENCE_KEY="general/ultimaker_auth_data", AUTH_SUCCESS_REDIRECT="{}/app/auth-success".format(self._oauth_root), AUTH_FAILED_REDIRECT="{}/app/auth-error".format(self._oauth_root) diff --git a/plugins/VersionUpgrade/VersionUpgrade48to49/VersionUpgrade48to49.py b/plugins/VersionUpgrade/VersionUpgrade48to49/VersionUpgrade48to49.py index bf21a6867d..854c05bb25 100644 --- a/plugins/VersionUpgrade/VersionUpgrade48to49/VersionUpgrade48to49.py +++ b/plugins/VersionUpgrade/VersionUpgrade48to49/VersionUpgrade48to49.py @@ -4,8 +4,10 @@ import configparser from typing import Tuple, List import io +import json from UM.VersionUpgrade import VersionUpgrade +from cura.API import Account class VersionUpgrade48to49(VersionUpgrade): @@ -32,6 +34,11 @@ class VersionUpgrade48to49(VersionUpgrade): if "categories_expanded" in parser["cura"] and any([setting in parser["cura"]["categories_expanded"] for setting in self._moved_visibility_settings]): parser["cura"]["categories_expanded"] += ";top_bottom" + if "ultimaker_auth_data" in parser["general"]: + ultimaker_auth_data = json.loads(parser["general"]["ultimaker_auth_data"]) + if set(Account.CLIENT_SCOPES.split(" ")) - set(ultimaker_auth_data["scope"].split(" ")): + parser["general"]["ultimaker_auth_data"] = "{}" + result = io.StringIO() parser.write(result) return [filename], [result.getvalue()]