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 typing import Any, Dict | |||||
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 | ||||
Show All 29 Lines | ) -> None: | ||||
super().restrict_access(request, headers, deposit) | super().restrict_access(request, headers, deposit) | ||||
def process_put( | def process_put( | ||||
self, | self, | ||||
request, | request, | ||||
headers: ParsedRequestHeaders, | headers: ParsedRequestHeaders, | ||||
collection_name: str, | collection_name: str, | ||||
deposit_id: int, | deposit_id: int, | ||||
) -> Dict[str, Any]: | ) -> None: | ||||
"""This allows the following scenarios: | """This allows the following scenarios: | ||||
- multipart: replace all the deposit (status partial) metadata and archive | - multipart: replace all the deposit (status partial) metadata and archive | ||||
with the provided ones. | with the provided ones. | ||||
- atom: replace all the deposit (status partial) metadata with the | - atom: replace all the deposit (status partial) metadata with the | ||||
provided ones. | provided ones. | ||||
- with swhid, atom: Add new metatada to deposit (status done) with provided ones | - with swhid, atom: Add new metatada to deposit (status done) with provided ones | ||||
and push such metadata to the metadata storage directly. | and push such metadata to the metadata storage directly. | ||||
source: | source: | ||||
- http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html#protocoloperations_editingcontent_metadata | - http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html#protocoloperations_editingcontent_metadata | ||||
- http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html#protocoloperations_editingcontent_multipart | - http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html#protocoloperations_editingcontent_multipart | ||||
Raises: | Raises: | ||||
400 if any of the following occur: | 400 if any of the following occur: | ||||
- the swhid provided and the deposit swhid do not match | - the swhid provided and the deposit swhid do not match | ||||
- the provided metadata xml file is malformed | - the provided metadata xml file is malformed | ||||
- the provided xml atom entry is empty | - the provided xml atom entry is empty | ||||
- the provided swhid does not exist in the archive | - the provided swhid does not exist in the archive | ||||
Returns: | |||||
204 No content | |||||
""" # noqa | """ # noqa | ||||
swhid = headers.swhid | swhid = headers.swhid | ||||
if swhid is None: | if swhid is None: | ||||
if request.content_type.startswith("multipart/"): | if request.content_type.startswith("multipart/"): | ||||
return self._multipart_upload( | self._multipart_upload( | ||||
ardumont: hmm?
What do you do of the multipart_upload result? | |||||
vlorentzAuthorUnsubmitted Done Inline Actionsnothing. it's not used. $ grep "process_put(" -r swh/**/*.py swh/deposit/api/common.py: self.process_put(request, headers, collection_name, deposit_id) swh/deposit/api/common.py: def process_put( swh/deposit/api/edit.py: def process_put( swh/deposit/api/edit_media.py: def process_put( swh/deposit/api/private/deposit_update_status.py: def process_put( vlorentz: nothing. it's not used.
```
$ grep "process_put(" -r swh/**/*.py
swh/deposit/api/common.py… | |||||
request, | request, | ||||
headers, | headers, | ||||
collection_name, | collection_name, | ||||
deposit_id=deposit_id, | deposit_id=deposit_id, | ||||
replace_archives=True, | replace_archives=True, | ||||
replace_metadata=True, | replace_metadata=True, | ||||
) | ) | ||||
else: | |||||
# standard metadata update (replace all metadata already provided to the | # standard metadata update (replace all metadata already provided to the | ||||
# deposit by the new ones) | # deposit by the new ones) | ||||
return self._atom_entry( | self._atom_entry( | ||||
ardumontUnsubmitted Not Done Inline ActionsIs that a tab that got inserted? ardumont: Is that a tab that got inserted? | |||||
vlorentzAuthorUnsubmitted Done Inline ActionsI added an else, because it shouldn't run if request.content_type.startswith("multipart/") vlorentz: I added an else, because it shouldn't run if `request.content_type.startswith("multipart/")` | |||||
request, | request, | ||||
headers, | headers, | ||||
collection_name, | collection_name, | ||||
deposit_id=deposit_id, | deposit_id=deposit_id, | ||||
replace_metadata=True, | replace_metadata=True, | ||||
) | ) | ||||
ardumontUnsubmitted Not Done Inline Actionssame question about the _atom_entry result. ardumont: same question about the _atom_entry result. | |||||
vlorentzAuthorUnsubmitted Done Inline Actionsalso not used vlorentz: also not used | |||||
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 = Deposit.objects.get(pk=deposit_id) | ||||
assert deposit.status == DEPOSIT_STATUS_LOAD_SUCCESS | assert deposit.status == DEPOSIT_STATUS_LOAD_SUCCESS | ||||
Show All 22 Lines | ) -> None: | ||||
"Atom entry deposit is supposed to send for metadata. " | "Atom entry deposit is supposed to send for metadata. " | ||||
"If the body is empty, there is no metadata.", | "If the body is empty, there is no metadata.", | ||||
) | ) | ||||
_, _, deposit, deposit_request = self._store_metadata_deposit( | _, _, deposit, deposit_request = self._store_metadata_deposit( | ||||
deposit, parse_swhid(swhid), metadata, raw_metadata, deposit.origin_url, | deposit, parse_swhid(swhid), metadata, raw_metadata, deposit.origin_url, | ||||
) | ) | ||||
return { | def process_delete(self, req, collection_name: str, deposit_id: int) -> None: | ||||
"deposit_id": deposit.id, | |||||
"deposit_date": deposit_request.date, | |||||
"status": deposit.status, | |||||
"archive": None, | |||||
} | |||||
def process_delete(self, req, collection_name: str, deposit_id: int) -> Dict: | |||||
"""Delete the container (deposit). | """Delete the container (deposit). | ||||
source: http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html#protocoloperations_deleteconteiner # noqa | source: http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html#protocoloperations_deleteconteiner # noqa | ||||
""" | """ | ||||
return self._delete_deposit(collection_name, deposit_id) | self._delete_deposit(collection_name, deposit_id) |
hmm?
What do you do of the multipart_upload result?