Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/common.py
Show First 20 Lines • Show All 855 Lines • ▼ Show 20 Lines | ) -> Dict[str, Any]: | ||||
dict with 'error' detailing the problem. | dict with 'error' detailing the problem. | ||||
""" | """ | ||||
return {} | return {} | ||||
def checks( | def checks( | ||||
self, request: Request, collection_name: str, deposit: Optional[Deposit] = None | self, request: Request, collection_name: str, deposit: Optional[Deposit] = None | ||||
) -> ParsedRequestHeaders: | ) -> ParsedRequestHeaders: | ||||
self._collection = get_collection_by_name(collection_name) | if deposit is None: | ||||
collection = get_collection_by_name(collection_name) | |||||
else: | |||||
assert collection_name == deposit.collection.name | |||||
collection = deposit.collection | |||||
username = request.user.username | username = request.user.username | ||||
if username: # unauthenticated request can have the username empty | if username: # unauthenticated request can have the username empty | ||||
try: | try: | ||||
self._client: DepositClient = DepositClient.objects.get( # type: ignore | self._client: DepositClient = DepositClient.objects.get( # type: ignore | ||||
username=username | username=username | ||||
) | ) | ||||
except DepositClient.DoesNotExist: | except DepositClient.DoesNotExist: | ||||
raise DepositError(NOT_FOUND, f"Unknown client name {username}") | raise DepositError(NOT_FOUND, f"Unknown client name {username}") | ||||
collection_id = self._collection.id | collection_id = collection.id | ||||
collections = self._client.collections | collections = self._client.collections | ||||
assert collections is not None | assert collections is not None | ||||
if collection_id not in collections: | if collection_id not in collections: | ||||
raise DepositError( | raise DepositError( | ||||
FORBIDDEN, | FORBIDDEN, | ||||
f"Client {username} cannot access collection {collection_name}", | f"Client {username} cannot access collection {collection_name}", | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 258 Lines • Show Last 20 Lines |