diff --git a/plugins/DigitalLibrary/src/DigitalFactoryApiClient.py b/plugins/DigitalLibrary/src/DigitalFactoryApiClient.py index c0c6099b0d..91f1daf2f7 100644 --- a/plugins/DigitalLibrary/src/DigitalFactoryApiClient.py +++ b/plugins/DigitalLibrary/src/DigitalFactoryApiClient.py @@ -89,9 +89,9 @@ class DigitalFactoryApiClient: def callbackWrap(response: Optional[Any] = None, *args, **kwargs) -> None: if response is not None: - if self._library_max_private_projects == -1 or isinstance(response, DigitalFactoryProjectResponse): + if isinstance(response, DigitalFactoryProjectResponse): # The user has only one private project callback(True) - elif isinstance(response, list) and all(isinstance(r, DigitalFactoryProjectResponse) for r in response) and self._library_max_private_projects is not None: + elif isinstance(response, list) and all(isinstance(r, DigitalFactoryProjectResponse) for r in response): callback(len(response) < self._library_max_private_projects) else: Logger.warning(f"Digital Factory: Incorrect response type received when requesting private projects: {str(response)}") @@ -100,7 +100,21 @@ class DigitalFactoryApiClient: Logger.warning(f"Digital Factory: Response is empty, likely an error: {str(response)}") callback(False) - self.getProjectsFirstPage(on_finished = callbackWrap, failed = callbackWrap) + if self._library_max_private_projects is not None and self._library_max_private_projects > 0: + # The user has a limit in the number of private projects they can create. Check whether they have already + # reached that limit. + # Note: Set the pagination manager to None when doing this get request, or else the next/previous links + # of the pagination will become corrupted + url = f"{self.CURA_API_ROOT}/projects?shared=false&limit={self._library_max_private_projects}" + self._http.get(url, + scope = self._scope, + callback = self._parseCallback(callbackWrap, DigitalFactoryProjectResponse, callbackWrap, pagination_manager = None), + error_callback = callbackWrap, + timeout = self.DEFAULT_REQUEST_TIMEOUT) + else: + # If the limit is -1, then the user is allowed unlimited projects. If its 0 then they are not allowed to + # create any projects + callback(self._library_max_private_projects == -1) def getProject(self, library_project_id: str, on_finished: Callable[[DigitalFactoryProjectResponse], Any], failed: Callable) -> None: """