Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/superannotate/lib/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@
ATTACH_PROJECT_LIMIT_ERROR_MESSAGE = "The number of items you want to attach exceeds the limit of 500 000 items per project."
ATTACH_USER_LIMIT_ERROR_MESSAGE = "The number of items you want to attach exceeds the limit of your subscription plan."

COPY_ITEMS_LIMIT_ERROR_MESSAGE = (
"The number of items you want to copy exceeds the limit of 50 000 items per folder."
)
COPY_ITEM_PROJECT_LIMIT_ERROR_MESSAGE = (
"The copy exceeds the limit of 50 0000 items per project."
)
MOVE_ITEMS_LIMIT_ERROR_MESSAGE = (
"The number of items you want to move exceeds the limit of 50 000 items per folder."
)
MOVE_ITEM_PROJECT_LIMIT_ERROR_MESSAGE = (
"The number of items you want to move exceeds the limit of 50 000 items per folder."
)

COPY_FOLDER_LIMIT_ERROR_MESSAGE = (
"The number of items you want to copy exceeds the limit of 50 000 items per folder."
)
Expand Down
60 changes: 24 additions & 36 deletions src/superannotate/lib/core/usecases/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,15 +592,10 @@ def _validate_limitations(self, images_to_copy_count):
project_id=self._project.uuid,
folder_id=self._to_folder.uuid,
)
errors = []
if not response.ok:
raise AppValidationException(response.error)
if images_to_copy_count > response.data.folder_limit.remaining_image_count:
errors.append(constances.UPLOAD_FOLDER_LIMIT_ERROR_MESSAGE)
elif images_to_copy_count > response.data.project_limit.remaining_image_count:
errors.append(constances.UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE)
if errors:
raise AppValidationException(errors)
AppValidationException(constances.COPY_ITEMS_LIMIT_ERROR_MESSAGE)

def validate_project_type(self):
if self._project.project_type in constances.LIMITED_FUNCTIONS:
Expand Down Expand Up @@ -740,7 +735,7 @@ def validate_limitations(self):
if not response.ok:
raise AppValidationException(response.error)
if to_upload_count > response.data.folder_limit.remaining_image_count:
raise AppValidationException(constances.UPLOAD_FOLDER_LIMIT_ERROR_MESSAGE)
raise AppValidationException(constances.MOVE_ITEMS_LIMIT_ERROR_MESSAGE)

def execute(self):
if self.is_valid():
Expand Down Expand Up @@ -1137,18 +1132,15 @@ def validate_limitations(self):
project_id=self._project.uuid,
folder_id=self._folder.uuid,
)
errors = []
if response.data.folder_limit.remaining_image_count < 1:
errors.append(constances.UPLOAD_FOLDER_LIMIT_ERROR_MESSAGE)
raise AppValidationException(constances.UPLOAD_FOLDER_LIMIT_ERROR_MESSAGE)
elif response.data.project_limit.remaining_image_count < 1:
errors.append(constances.UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE)
raise AppValidationException(constances.UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE)
elif (
response.data.super_user_limit
and response.data.super_user_limit.remaining_image_count < 1
):
errors.append(constances.UPLOAD_USER_LIMIT_ERROR_MESSAGE)
if errors:
raise AppValidationException("\n".join(errors))
raise AppValidationException(constances.UPLOAD_USER_LIMIT_ERROR_MESSAGE)

@property
def auth_data(self):
Expand Down Expand Up @@ -1278,18 +1270,15 @@ def validate_limitations(self):
if not response.ok:
raise AppValidationException(response.error)
to_upload_count = len(self.images_to_upload)
errors = []
if to_upload_count > response.data.folder_limit.remaining_image_count:
errors.append(constances.UPLOAD_FOLDER_LIMIT_ERROR_MESSAGE)
raise AppValidationException(constances.UPLOAD_FOLDER_LIMIT_ERROR_MESSAGE)
elif to_upload_count > response.data.project_limit.remaining_image_count:
errors.append(constances.UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE)
raise AppValidationException(constances.UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE)
elif (
response.data.super_user_limit
and to_upload_count > response.data.super_user_limit.remaining_image_count
):
errors.append(constances.UPLOAD_USER_LIMIT_ERROR_MESSAGE)
if errors:
raise AppValidationException("\n".join(errors))
raise AppValidationException(constances.UPLOAD_USER_LIMIT_ERROR_MESSAGE)

def validate_annotation_status(self):
if (
Expand Down Expand Up @@ -1598,18 +1587,15 @@ def validate_limitations(self):
if not response.ok:
raise AppValidationException(response.error)
to_upload_count = len(self._image_urls)
errors = []
if to_upload_count > response.data.folder_limit.remaining_image_count:
errors.append(constances.UPLOAD_FOLDER_LIMIT_ERROR_MESSAGE)
raise AppValidationException(constances.UPLOAD_FOLDER_LIMIT_ERROR_MESSAGE)
elif to_upload_count > response.data.project_limit.remaining_image_count:
errors.append(constances.UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE)
raise AppValidationException(constances.UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE)
elif (
response.data.super_user_limit
and to_upload_count > response.data.super_user_limit.remaining_image_count
):
errors.append(constances.UPLOAD_USER_LIMIT_ERROR_MESSAGE)
if errors:
raise AppValidationException("\n".join(errors))
raise AppValidationException(constances.UPLOAD_USER_LIMIT_ERROR_MESSAGE)

def validate_image_names(self):
if self._image_names and len(self._image_names) != len(self._image_urls):
Expand Down Expand Up @@ -1893,18 +1879,15 @@ def validate_limitations(self):
)
if not response.ok:
raise AppValidationException(response.error)
errors = []
if attachments_count > response.data.folder_limit.remaining_image_count:
errors.append(constances.ATTACH_FOLDER_LIMIT_ERROR_MESSAGE)
raise AppValidationException(constances.ATTACH_FOLDER_LIMIT_ERROR_MESSAGE)
elif attachments_count > response.data.project_limit.remaining_image_count:
errors.append(constances.ATTACH_PROJECT_LIMIT_ERROR_MESSAGE)
raise AppValidationException(constances.ATTACH_PROJECT_LIMIT_ERROR_MESSAGE)
elif (
response.data.super_user_limit
and attachments_count > response.data.super_user_limit.remaining_image_count
):
errors.append(constances.ATTACH_USER_LIMIT_ERROR_MESSAGE)
if errors:
raise AppValidationException("\n".join(errors))
raise AppValidationException(constances.ATTACH_USER_LIMIT_ERROR_MESSAGE)

@property
def annotation_status_code(self):
Expand Down Expand Up @@ -1999,16 +1982,21 @@ def validate_limitations(self):
)
if not response.ok:
raise AppValidationException(response.error)
errors = []
if response.data.folder_limit.remaining_image_count < 1:
errors.append(constances.ATTACH_FOLDER_LIMIT_ERROR_MESSAGE)
if self._move:
raise AppValidationException(constances.MOVE_ITEMS_LIMIT_ERROR_MESSAGE)
raise AppValidationException(constances.COPY_ITEMS_LIMIT_ERROR_MESSAGE)
elif (
self._to_project.uuid != self._from_project.uuid
and response.data.project_limit.remaining_image_count < 1
):
errors.append(constances.ATTACH_PROJECT_LIMIT_ERROR_MESSAGE)
if errors:
raise AppValidationException("\n".join(errors))
if self._move:
raise AppValidationException(
constances.MOVE_ITEM_PROJECT_LIMIT_ERROR_MESSAGE
)
raise AppValidationException(
constances.COPY_ITEM_PROJECT_LIMIT_ERROR_MESSAGE
)

def execute(self) -> Response:
if self.is_valid():
Expand Down