Skip to content

Commit 34cd095

Browse files
Vaghinak BasentsyanVaghinak Basentsyan
authored andcommitted
tod
1 parent 76d0276 commit 34cd095

File tree

3 files changed

+50
-41
lines changed

3 files changed

+50
-41
lines changed

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3492,7 +3492,7 @@ def delete_annotations(
34923492
def attach_document_urls_to_project(
34933493
project: Union[NotEmptyStr, dict],
34943494
attachments: Union[Path, NotEmptyStr],
3495-
annotation_status: Optional[NotEmptyStr] = "NotStarted",
3495+
annotation_status: Optional[Status] = "NotStarted",
34963496
):
34973497
"""Link documents on external storage to SuperAnnotate.
34983498

src/superannotate/lib/core/service_types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ class ErrorMessage(BaseModel):
1313

1414

1515
class Limit(BaseModel):
16-
max_image_count: int
16+
max_image_count: Optional[int]
1717
remaining_image_count: int
1818

1919

2020
class UserLimits(BaseModel):
21-
super_user_limit: Optional[Limit]
21+
user_limit: Optional[Limit]
2222
project_limit: Limit
2323
folder_limit: Limit
2424

src/superannotate/lib/core/usecases/images.py

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ def _validate_limitations(self, to_upload_count):
234234
elif to_upload_count > response.data.project_limit.remaining_image_count:
235235
errors.append(constances.ATTACH_PROJECT_LIMIT_ERROR_MESSAGE)
236236
elif (
237-
response.data.super_user_limit
238-
and to_upload_count > response.data.super_user_limit.remaining_image_count
237+
response.data.user_limit
238+
and to_upload_count > response.data.user_limit.remaining_image_count
239239
):
240240
errors.append(constances.ATTACH_USER_LIMIT_ERROR_MESSAGE)
241241
if errors:
@@ -1151,8 +1151,8 @@ def validate_limitations(self):
11511151
elif response.data.project_limit.remaining_image_count < 1:
11521152
raise AppValidationException(constances.UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE)
11531153
elif (
1154-
response.data.super_user_limit
1155-
and response.data.super_user_limit.remaining_image_count < 1
1154+
response.data.user_limit
1155+
and response.data.user_limit.remaining_image_count < 1
11561156
):
11571157
raise AppValidationException(constances.UPLOAD_USER_LIMIT_ERROR_MESSAGE)
11581158

@@ -1289,8 +1289,8 @@ def validate_limitations(self):
12891289
elif to_upload_count > response.data.project_limit.remaining_image_count:
12901290
raise AppValidationException(constances.UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE)
12911291
elif (
1292-
response.data.super_user_limit
1293-
and to_upload_count > response.data.super_user_limit.remaining_image_count
1292+
response.data.user_limit
1293+
and to_upload_count > response.data.user_limit.remaining_image_count
12941294
):
12951295
raise AppValidationException(constances.UPLOAD_USER_LIMIT_ERROR_MESSAGE)
12961296

@@ -1317,18 +1317,17 @@ def validate_project_type(self):
13171317
constances.LIMITED_FUNCTIONS[self._project.project_type]
13181318
)
13191319

1320-
def validate_auth_data(self):
1321-
response = self._backend_client.get_s3_upload_auth_token(
1322-
team_id=self._project.team_id,
1323-
folder_id=self._folder.uuid,
1324-
project_id=self._project.uuid,
1325-
)
1326-
if "error" in response:
1327-
raise AppException(response.get("error"))
1328-
self._auth_data = response
1329-
13301320
@property
13311321
def auth_data(self):
1322+
if not self._auth_data:
1323+
response = self._backend_client.get_s3_upload_auth_token(
1324+
team_id=self._project.team_id,
1325+
folder_id=self._folder.uuid,
1326+
project_id=self._project.uuid,
1327+
)
1328+
if "error" in response:
1329+
raise AppException(response.get("error"))
1330+
self._auth_data = response
13321331
return self._auth_data
13331332

13341333
@property
@@ -1627,8 +1626,8 @@ def validate_limitations(self):
16271626
elif to_upload_count > response.data.project_limit.remaining_image_count:
16281627
raise AppValidationException(constances.UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE)
16291628
elif (
1630-
response.data.super_user_limit
1631-
and to_upload_count > response.data.super_user_limit.remaining_image_count
1629+
response.data.user_limit
1630+
and to_upload_count > response.data.user_limit.remaining_image_count
16321631
):
16331632
raise AppValidationException(constances.UPLOAD_USER_LIMIT_ERROR_MESSAGE)
16341633

@@ -1905,8 +1904,8 @@ def validate_limitations(self):
19051904
elif attachments_count > response.data.project_limit.remaining_image_count:
19061905
raise AppValidationException(constances.ATTACH_PROJECT_LIMIT_ERROR_MESSAGE)
19071906
elif (
1908-
response.data.super_user_limit
1909-
and attachments_count > response.data.super_user_limit.remaining_image_count
1907+
response.data.user_limit
1908+
and attachments_count > response.data.user_limit.remaining_image_count
19101909
):
19111910
raise AppValidationException(constances.ATTACH_USER_LIMIT_ERROR_MESSAGE)
19121911

@@ -2026,8 +2025,8 @@ def validate_limitations(self):
20262025
constances.COPY_PROJECT_LIMIT_ERROR_MESSAGE
20272026
)
20282027
if (
2029-
response.data.super_user_limit
2030-
and response.data.super_user_limit.remaining_image_count < 1
2028+
response.data.user_limit
2029+
and response.data.user_limit.remaining_image_count < 1
20312030
):
20322031
raise AppValidationException(constances.COPY_SUPER_LIMIT_ERROR_MESSAGE)
20332032

@@ -3546,27 +3545,37 @@ def __init__(
35463545
self._annotation_status_code = annotation_status_code
35473546
self._image_quality_in_editor = image_quality_in_editor
35483547
self._limit = limit
3549-
self._auth_data = None
3550-
3551-
def validate_auth_data(self):
3552-
response = self._backend_service.get_s3_upload_auth_token(
3553-
team_id=self._project.team_id,
3554-
folder_id=self._folder.uuid,
3555-
project_id=self._project.uuid,
3556-
)
3557-
if "error" in response:
3558-
raise AppException(response.get("error"))
3559-
self._auth_data = response
3548+
self._limitation_response = None
35603549

35613550
@property
3562-
def upload_auth_data(self):
3563-
return self._auth_data
3551+
def limitation_response(self):
3552+
if not self._limitation_response:
3553+
self._limitation_response = self._backend_service.get_limitations(
3554+
team_id=self._project.team_id,
3555+
project_id=self._project.uuid,
3556+
folder_id=self._folder.uuid,
3557+
)
3558+
if not self._limitation_response.ok:
3559+
raise AppValidationException(self._limitation_response.error)
3560+
return self._limitation_response
3561+
3562+
def validate_limitations(self):
3563+
response = self.limitation_response
3564+
if not response.ok:
3565+
raise AppValidationException(response.error)
3566+
if not response.data.folder_limit.remaining_image_count:
3567+
raise AppValidationException(constances.UPLOAD_FOLDER_LIMIT_ERROR_MESSAGE)
3568+
elif not response.data.project_limit.remaining_image_count:
3569+
raise AppValidationException(constances.UPLOAD_PROJECT_LIMIT_ERROR_MESSAGE)
3570+
elif (
3571+
response.data.user_limit
3572+
and response.data.user_limit.remaining_image_count > 0
3573+
):
3574+
raise AppValidationException(constances.UPLOAD_USER_LIMIT_ERROR_MESSAGE)
35643575

35653576
@property
35663577
def limit(self):
3567-
if not self._limit:
3568-
return self.upload_auth_data.get("availableImageCount")
3569-
return self._limit
3578+
return self._limitation_response.data.folder_limit.remaining_image_count
35703579

35713580
def validate_project_type(self):
35723581
if self._project.project_type in constances.LIMITED_FUNCTIONS:

0 commit comments

Comments
 (0)