mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
Check for the maximum **private** projects
When checking whether the user is allowed to create a new library project, we need to retrieve the **private** (aka non-shared) projects that are linked to the user's account. If the user has reached the maximum private projects, then they are no longer allowed to create new ones. **Note**: We need to set the `pagination_manager` to `None` when doing this get request, or else the next/previous links of the pagination will become mixed up with the pagination links of the list of projects shown to the user, corrupting them and creating the wrong "get more projects" link. CURA-8112
This commit is contained in:
parent
3dbbe7276b
commit
300176cdc6
1 changed files with 17 additions and 3 deletions
|
@ -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:
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue