Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/edit.py
# Copyright (C) 2017-2020 The Software Heritage developers | # Copyright (C) 2017-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from rest_framework.request import Request | from rest_framework.request import Request | ||||
from swh.deposit.models import Deposit | from swh.deposit.models import Deposit | ||||
from swh.model.identifiers import parse_swhid | from swh.model.identifiers import parse_swhid | ||||
from ..config import DEPOSIT_STATUS_LOAD_SUCCESS | from ..config import DEPOSIT_STATUS_LOAD_SUCCESS | ||||
from ..errors import BAD_REQUEST, DepositError, ParserError | from ..errors import BAD_REQUEST, DepositError, ParserError | ||||
from ..parsers import SWHAtomEntryParser, SWHMultiPartParser | from ..parsers import SWHAtomEntryParser, SWHMultiPartParser | ||||
from .common import APIDelete, APIPut, ParsedRequestHeaders | from .common import APIDelete, APIPut, ParsedRequestHeaders, get_deposit_by_id | ||||
class EditAPI(APIPut, APIDelete): | class EditAPI(APIPut, APIDelete): | ||||
"""Deposit request class defining api endpoints for sword deposit. | """Deposit request class defining api endpoints for sword deposit. | ||||
What's known as 'Edit-IRI' in the sword specification. | What's known as 'Edit-IRI' in the sword specification. | ||||
HTTP verbs supported: PUT, DELETE | HTTP verbs supported: PUT, DELETE | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | ) -> None: | ||||
replace_metadata=True, | replace_metadata=True, | ||||
) | ) | ||||
return | return | ||||
# Update metadata on a deposit already ingested | # Update metadata on a deposit already ingested | ||||
# Write to the metadata storage (and the deposit backend) | # Write to the metadata storage (and the deposit backend) | ||||
# no ingestion triggered | # no ingestion triggered | ||||
deposit = Deposit.objects.get(pk=deposit_id) | deposit = get_deposit_by_id(deposit_id, collection_name) | ||||
assert deposit.status == DEPOSIT_STATUS_LOAD_SUCCESS | assert deposit.status == DEPOSIT_STATUS_LOAD_SUCCESS | ||||
if swhid != deposit.swhid: | if swhid != deposit.swhid: | ||||
raise DepositError( | raise DepositError( | ||||
BAD_REQUEST, | BAD_REQUEST, | ||||
f"Mismatched provided SWHID {swhid} with deposit's {deposit.swhid}.", | f"Mismatched provided SWHID {swhid} with deposit's {deposit.swhid}.", | ||||
"The provided SWHID does not match the deposit to update. " | "The provided SWHID does not match the deposit to update. " | ||||
"Please ensure you send the correct deposit SWHID.", | "Please ensure you send the correct deposit SWHID.", | ||||
Show All 31 Lines |