Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/common.py
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | from ..errors import ( | ||||
PARSING_ERROR, | PARSING_ERROR, | ||||
ParserError, | ParserError, | ||||
make_error_dict, | make_error_dict, | ||||
make_error_response, | make_error_response, | ||||
make_error_response_from_dict, | make_error_response_from_dict, | ||||
) | ) | ||||
from ..models import Deposit, DepositClient, DepositCollection, DepositRequest | from ..models import Deposit, DepositClient, DepositCollection, DepositRequest | ||||
from ..parsers import parse_xml | from ..parsers import parse_xml | ||||
from .checks import check_metadata | |||||
from .converters import convert_status_detail | |||||
ACCEPT_PACKAGINGS = ["http://purl.org/net/sword/package/SimpleZip"] | ACCEPT_PACKAGINGS = ["http://purl.org/net/sword/package/SimpleZip"] | ||||
ACCEPT_ARCHIVE_CONTENT_TYPES = ["application/zip", "application/x-tar"] | ACCEPT_ARCHIVE_CONTENT_TYPES = ["application/zip", "application/x-tar"] | ||||
class AuthenticatedAPIView(APIView): | class AuthenticatedAPIView(APIView): | ||||
"""Mixin intended as a based API view to enforce the basic | """Mixin intended as a based API view to enforce the basic | ||||
authentication check | authentication check | ||||
▲ Show 20 Lines • Show All 583 Lines • ▼ Show 20 Lines | ) -> Dict[str, Any]: | ||||
except ParserError: | except ParserError: | ||||
return make_error_dict( | return make_error_dict( | ||||
BAD_REQUEST, | BAD_REQUEST, | ||||
"Malformed xml metadata", | "Malformed xml metadata", | ||||
"The xml received is malformed. " | "The xml received is malformed. " | ||||
"Please ensure your metadata file is correctly formatted.", | "Please ensure your metadata file is correctly formatted.", | ||||
) | ) | ||||
if not metadata: | metadata_ok, error_details = check_metadata(metadata or {}) | ||||
if not metadata_ok: | |||||
assert error_details, "Details should be set when a failure occurs" | |||||
return make_error_dict( | return make_error_dict( | ||||
BAD_REQUEST, | BAD_REQUEST, | ||||
"Empty body request is not supported", | "Functional metadata checks failure", | ||||
"Atom entry deposit is supposed to send for metadata. " | convert_status_detail(error_details), | ||||
"If the body is empty, there is no metadata.", | |||||
) | ) | ||||
external_id = headers["slug"] | external_id = headers["slug"] | ||||
if ( | if ( | ||||
"external_identifier" in metadata | "external_identifier" in metadata | ||||
and metadata["external_identifier"] != external_id | and metadata["external_identifier"] != external_id | ||||
): | ): | ||||
# TODO: When clients stopped using it, raise this error | # TODO: When clients stopped using it, raise this error | ||||
▲ Show 20 Lines • Show All 383 Lines • Show Last 20 Lines |