mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
Digital Library: Allow 'personal users' to DL.
Users with an account and an UM printer should have some basic access to the Digital Library. To this end, and to remain future proof, the online team has made an extension to its API so now feature budgets can be gauge. At the moment it's only checked wether the user has any access to personal projects at all. If so, the interface shows Digital Library functionality. Known issue: Removing the last printer from DF while still logged in leaves the DL access in the Cura interface until logged out or Cura restarted. Additionally, I think the response for a logged in user without any printer from the API is just 'data = empty list' instead of everything set to False and 0 (which should be the case as they're all listed as required fields in their docs ... maybe I'm missing something). In any case, the code as is now can handle that as well. CURA-8138
This commit is contained in:
parent
920e220bdb
commit
c78618bc15
5 changed files with 84 additions and 6 deletions
|
@ -89,6 +89,9 @@ class DigitalFactoryController(QObject):
|
|||
uploadFileError = Signal()
|
||||
uploadFileFinished = Signal()
|
||||
|
||||
"""Signal to inform about the state of user access."""
|
||||
userAccessStateChanged = pyqtSignal(bool)
|
||||
|
||||
def __init__(self, application: CuraApplication) -> None:
|
||||
super().__init__(parent = None)
|
||||
|
||||
|
@ -106,6 +109,7 @@ class DigitalFactoryController(QObject):
|
|||
self._has_more_projects_to_load = False
|
||||
|
||||
self._account = self._application.getInstance().getCuraAPI().account # type: Account
|
||||
self._account.loginStateChanged.connect(self._onLoginStateChanged)
|
||||
self._current_workspace_information = CuraApplication.getInstance().getCurrentWorkspaceInformation()
|
||||
|
||||
# Initialize the project model
|
||||
|
@ -131,6 +135,8 @@ class DigitalFactoryController(QObject):
|
|||
self._application.engineCreatedSignal.connect(self._onEngineCreated)
|
||||
self._application.initializationFinished.connect(self._applicationInitializationFinished)
|
||||
|
||||
self._user_has_access = False
|
||||
|
||||
def clear(self) -> None:
|
||||
self._project_model.clearProjects()
|
||||
self._api.clear()
|
||||
|
@ -143,16 +149,24 @@ class DigitalFactoryController(QObject):
|
|||
|
||||
self.setSelectedProjectIndex(-1)
|
||||
|
||||
def _onLoginStateChanged(self, logged_in: bool) -> None:
|
||||
def callback(has_access, **kwargs):
|
||||
self._user_has_access = has_access
|
||||
self.userAccessStateChanged.emit(logged_in)
|
||||
|
||||
self._api.checkUserHasAccess(callback)
|
||||
|
||||
def userAccountHasLibraryAccess(self) -> bool:
|
||||
"""
|
||||
Checks whether the currently logged in user account has access to the Digital Library
|
||||
|
||||
:return: True if the user account has Digital Library access, else False
|
||||
"""
|
||||
subscriptions = [] # type: List[Dict[str, Any]]
|
||||
if self._account.userProfile:
|
||||
subscriptions = self._account.userProfile.get("subscriptions", [])
|
||||
return len(subscriptions) > 0
|
||||
if len(subscriptions) > 0:
|
||||
return True
|
||||
return self._user_has_access
|
||||
|
||||
def initialize(self, preselected_project_id: Optional[str] = None) -> None:
|
||||
self.clear()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue