Skip to content

Commit

Permalink
items: Add call number validation to ItemSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshamarora1 committed Jun 21, 2024
1 parent 3fdf092 commit f081d00
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cds_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ def _parse_env_bool(var_name, default=None):
"application/json": "cds_ils.series.serializers:json_v1_search",
"text/csv": "cds_ils.series.serializers:csv_v1_search",
}
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."""
35 changes: 35 additions & 0 deletions cds_ils/items/loaders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-

Check failure on line 1 in cds_ils/items/loaders.py

View workflow job for this annotation

GitHub Actions / Python_Tests (3.9, postgresql14, opensearch2)

pydocstyle-check /home/runner/work/cds-ils/cds-ils/cds_ils/items/loaders.py:27 in public class `ItemSchemaV1`: D101: Missing docstring in public class

Check failure on line 1 in cds_ils/items/loaders.py

View workflow job for this annotation

GitHub Actions / Python_Tests (3.9, postgresql14, opensearch2)

isort-check """CDS-ILS items loaders.""" -from marshmallow import fields, ValidationError - -from invenio_app_ils.records.loaders.schemas.identifiers import IdentifierSchema 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):
#
# 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 marshmallow import fields, ValidationError

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


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):
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

0 comments on commit f081d00

Please sign in to comment.