Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

items: Add call number validation to ItemSchema #911

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cds_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ def query_params_modifier(extra_params):
"text/csv": "cds_ils.series.serializers:csv_v1_search",
}
RECORDS_REST_ENDPOINTS[SERIES_PID_TYPE]["search_query_parser"] = query_params_modifier
RECORDS_REST_ENDPOINTS[ITEM_PID_TYPE]["record_loaders"] = {
"application/json": "cds_ils.items.loaders:item_loader"
}
RECORDS_REST_ENDPOINTS[ITEM_PID_TYPE][
"list_permission_factory_imp"
] = authenticated_user_permission
Expand Down
8 changes: 8 additions & 0 deletions cds_ils/items/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2024 CERN.
#
# CDS-ILS is free software; you can redistribute it and/or modify it under
# the terms of the MIT License; see LICENSE file for more details.

"""CDS-ILS items module."""
36 changes: 36 additions & 0 deletions cds_ils/items/loaders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2024 CERN.
#
# CDS-ILS is free software; you can redistribute it and/or modify it under
# the terms of the MIT License; see LICENSE file for more details.

"""CDS-ILS items loaders."""

from invenio_app_ils.items.loaders.jsonschemas.items import (
ItemSchemaV1 as ILSItemSchemaV1,
)
from invenio_app_ils.records.loaders import ils_marshmallow_loader
from invenio_app_ils.records.loaders.schemas.identifiers import IdentifierSchema
from marshmallow import ValidationError, fields


def validate_call_number_exists(identifiers):
"""Check if Call number exists."""
for identifier in identifiers:
if identifier["scheme"] == "CALL_NUMBER":
return
raise ValidationError("The Call number identifier field is mandatory.")


class ItemSchemaV1(ILSItemSchemaV1):
"""Item schema."""

identifiers = fields.List(
fields.Nested(IdentifierSchema),
required=True,
validate=validate_call_number_exists,
)


item_loader = ils_marshmallow_loader(ItemSchemaV1)
1 change: 1 addition & 0 deletions ui/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export const config = {
"document_pid",
"circulation_restriction",
"medium",
"identifiers",
],
},
editorUiSchema: {
Expand Down
Loading