|
18 | 18 | from app.models.ura import UraNumber |
19 | 19 | from app.services.auth.auth_context import AuthContextService |
20 | 20 | from app.services.exceptions import ( |
| 21 | + BundleTooLargeError, |
| 22 | + InvalidModelError, |
21 | 23 | InvalidResourceError, |
22 | 24 | UnauthorizedManagingRequestError, |
23 | 25 | UnauthorizedScopeError, |
@@ -48,11 +50,9 @@ def _entry_for_exception(index: int, exc: Exception) -> BundleEntry[Any]: |
48 | 50 |
|
49 | 51 |
|
50 | 52 | class BundleService: |
51 | | - def __init__( |
52 | | - self, |
53 | | - localization_list_service: LocalizationListService, |
54 | | - ) -> None: |
| 53 | + def __init__(self, localization_list_service: LocalizationListService, max_entries: int) -> None: |
55 | 54 | self.localization_list_service = localization_list_service |
| 55 | + self.max_entries = max_entries |
56 | 56 |
|
57 | 57 | def process_entry(self, ctx: AuthContext, entry: BundleEntry[Any], index: int) -> BundleEntry[Any]: |
58 | 58 | if entry.request is None: |
@@ -258,9 +258,11 @@ def requires_managing_request(method: str) -> bool: |
258 | 258 | """Whether an entry is a managing operation and so needs a source_id""" |
259 | 259 | return method in ("POST", "DELETE") |
260 | 260 |
|
261 | | - @staticmethod |
262 | | - def validate_localization_bundle_structure(bundle: Bundle[Any]) -> bool: |
263 | | - return len(bundle.entry) > 0 |
| 261 | + def validate_entry_count(self, bundle: Bundle[Any]) -> None: |
| 262 | + if not bundle.entry: |
| 263 | + raise InvalidModelError("Bundle.entry is invalid") |
| 264 | + if len(bundle.entry) > self.max_entries: |
| 265 | + raise BundleTooLargeError(f"Bundle.entry holds more than the maximum of {self.max_entries} entries") |
264 | 266 |
|
265 | 267 | def resolve_request_url(self, url: str, index: int) -> EntryRequestDto | BundleEntry[LocalizationList]: |
266 | 268 | try: |
|
0 commit comments