Skip to content

Commit

Permalink
item: make barcode uppercase
Browse files Browse the repository at this point in the history
  • Loading branch information
ntarocco committed Oct 16, 2024
1 parent 8221ccc commit 91ff204
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 46 deletions.
4 changes: 2 additions & 2 deletions invenio_app_ils/circulation/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ def checkout_loan(
)

# check if there is an existing request
loan = patron_has_request_on_document(patron_pid, kwargs.get("document_pid"))
loan = patron_has_request_on_document(patron_pid, kwargs["document_pid"])
if loan:
loan = loan_cls.get_record_by_pid(loan.pid)
pid = IlsCirculationLoanIdProvider.get(loan["pid"]).pid
pid = IlsCirculationLoanIdProvider[loan["pid"]].pid
loan.update(new_loan)
else:
pid = ils_circulation_loan_pid_minter(record_uuid, data=new_loan)
Expand Down
2 changes: 1 addition & 1 deletion invenio_app_ils/circulation/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
PatronOwnerPermission,
authenticated_user_permission,
backoffice_permission,
loan_checkout_permission,
loan_extend_circulation_permission,
patron_owner_permission,
superuser_permission,
loan_checkout_permission,
)

from .api import ILS_CIRCULATION_LOAN_FETCHER, ILS_CIRCULATION_LOAN_MINTER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import arrow
from flask import current_app
from invenio_circulation.records.loaders.schemas.json import DateString
from invenio_app_ils.proxies import current_app_ils
from marshmallow import (
Schema,
ValidationError,
Expand All @@ -22,6 +21,8 @@
validates_schema,
)

from invenio_app_ils.proxies import current_app_ils

from .base import LoanBaseSchemaV1


Expand Down
2 changes: 1 addition & 1 deletion invenio_app_ils/documents/jsonresolvers/document_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import jsonresolver
from werkzeug.routing import Rule

from invenio_app_ils.proxies import current_app_ils
from invenio_app_ils.eitems.api import EItem
from invenio_app_ils.proxies import current_app_ils

# Note: there must be only one resolver per file,
# otherwise only the last one is registered
Expand Down
2 changes: 1 addition & 1 deletion invenio_app_ils/documents/loaders/jsonschemas/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
ChangedBySchema,
set_changed_by,
)
from invenio_app_ils.records.loaders.schemas.identifiers import IdentifierSchema
from invenio_app_ils.records.loaders.schemas.preserve_cover_metadata import (
preserve_cover_metadata,
)
from invenio_app_ils.records.loaders.schemas.identifiers import IdentifierSchema


class AffiliationSchema(Schema):
Expand Down
2 changes: 1 addition & 1 deletion invenio_app_ils/eitems/loaders/jsonschemas/eitems.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
from marshmallow import EXCLUDE, Schema, fields, pre_load, validate

from invenio_app_ils.eitems.api import EItem
from invenio_app_ils.records.loaders.schemas.identifiers import IdentifierSchema
from invenio_app_ils.records.loaders.schemas.changed_by import (
ChangedBySchema,
set_changed_by,
)
from invenio_app_ils.records.loaders.schemas.identifiers import IdentifierSchema


class URLSchema(Schema):
Expand Down
2 changes: 2 additions & 0 deletions invenio_app_ils/items/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,13 @@ def build_resolver_fields(cls, data):
def create(cls, data, id_=None, **kwargs):
"""Create Item record."""
cls.build_resolver_fields(data)
data["barcode"] = data["barcode"].upper()
return super().create(data, id_=id_, **kwargs)

def update(self, *args, **kwargs):
"""Update Item record."""
super().update(*args, **kwargs)
self["barcode"] = self["barcode"].upper()
self.build_resolver_fields(self)

def delete(self, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion invenio_app_ils/items/loaders/jsonschemas/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
ChangedBySchema,
set_changed_by,
)
from invenio_app_ils.records.loaders.schemas.price import PriceSchema
from invenio_app_ils.records.loaders.schemas.identifiers import IdentifierSchema
from invenio_app_ils.records.loaders.schemas.price import PriceSchema


class ISBNSchema(Schema):
Expand Down
8 changes: 4 additions & 4 deletions invenio_app_ils/items/serializers/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def transform_record(self, pid, record, links_factory=None, **kwargs):
pid, record, links_factory=links_factory, **kwargs
)
filter_circulation(item)
field_cover_metadata(item.get('metadata', {}).get("document", {}))
field_cover_metadata(item.get("metadata", {}).get("document", {}))
return item

def transform_search_hit(self, pid, record_hit, links_factory=None, **kwargs):
Expand All @@ -58,7 +58,7 @@ def transform_search_hit(self, pid, record_hit, links_factory=None, **kwargs):
pid, record_hit, links_factory=links_factory, **kwargs
)
filter_circulation(hit)
field_cover_metadata(hit.get('metadata', {}).get("document", {}))
field_cover_metadata(hit.get("metadata", {}).get("document", {}))
return hit


Expand All @@ -71,7 +71,7 @@ def transform_record(self, pid, record, links_factory=None, **kwargs):
pid, record, links_factory=links_factory, **kwargs
)
filter_circulation(item)
field_cover_metadata(item.get('metadata', {}).get("document", {}))
field_cover_metadata(item.get("metadata", {}).get("document", {}))
return item

def transform_search_hit(self, pid, record_hit, links_factory=None, **kwargs):
Expand All @@ -80,5 +80,5 @@ def transform_search_hit(self, pid, record_hit, links_factory=None, **kwargs):
pid, record_hit, links_factory=links_factory, **kwargs
)
filter_circulation(hit)
field_cover_metadata(hit.get('metadata', {}).get("document", {}))
field_cover_metadata(hit.get("metadata", {}).get("document", {}))
return hit
59 changes: 29 additions & 30 deletions invenio_app_ils/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ def loan_checkout_permission(*args, **kwargs):
loan = kwargs["record"]
is_patron_current_user = current_user.id == int(loan["patron_pid"])

if (
current_app.config["ILS_SELF_CHECKOUT_ENABLED"]
and is_patron_current_user
):
if current_app.config["ILS_SELF_CHECKOUT_ENABLED"] and is_patron_current_user:
return authenticated_user_permission()

raise LoanCheckoutByPatronForbidden(int(loan["patron_pid"]), current_user.id)
Expand All @@ -168,36 +165,38 @@ def __init__(self, record):
super().__init__(UserNeed(int(record["patron_pid"])), backoffice_access_action)


_is_authenticated_user = [
"circulation-loan-request",
"patron-loans",
"bulk-loan-extension",
]
_is_backoffice_permission = [
"circulation-loan-force-checkout",
"circulation-overdue-loan-notification",
"circulation-loan-update-dates",
"relations-create",
"relations-delete",
"stats-most-loaned",
"document-request-actions",
"bucket-create",
"ill-brwreq-patron-loan-create",
"ill-brwreq-patron-loan-extension-accept",
"ill-brwreq-patron-loan-extension-decline",
"send-notification-to-patron",
]
_is_patron_owner_permission = [
"document-request-decline",
"ill-brwreq-patron-loan-extension-request",
]


def views_permissions_factory(action):
"""Return ILS views permissions factory."""
is_authenticated_user = [
"circulation-loan-request",
"patron-loans",
"bulk-loan-extension",
]
is_backoffice_permission = [
"circulation-loan-force-checkout",
"circulation-overdue-loan-notification",
"circulation-loan-update-dates",
"relations-create",
"relations-delete",
"stats-most-loaned",
"document-request-actions",
"bucket-create",
"ill-brwreq-patron-loan-create",
"ill-brwreq-patron-loan-extension-accept",
"ill-brwreq-patron-loan-extension-decline",
"send-notification-to-patron",
]
is_patron_owner_permission = [
"document-request-decline",
"ill-brwreq-patron-loan-extension-request",
]
if action in is_authenticated_user:
if action in _is_authenticated_user:
return authenticated_user_permission()
elif action in is_backoffice_permission:
elif action in _is_backoffice_permission:
return backoffice_permission()
elif action in is_patron_owner_permission:
elif action in _is_patron_owner_permission:
return PatronOwnerPermission
elif action == "circulation-loan-checkout":
if current_app.config["ILS_SELF_CHECKOUT_ENABLED"]:
Expand Down
2 changes: 1 addition & 1 deletion invenio_app_ils/records/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from invenio_app_ils.permissions import backoffice_permission
from invenio_app_ils.records.permissions import RecordPermission
from invenio_app_ils.series.api import SERIES_PID_TYPE
from invenio_app_ils.signals import record_viewed, file_downloaded
from invenio_app_ils.signals import file_downloaded, record_viewed


def create_document_stats_blueprint(app):
Expand Down
1 change: 1 addition & 0 deletions invenio_app_ils/records_relations/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ class IlsRecordWithRelations(IlsRecord):
def relations(self):
"""Get record relations."""
from .retriever import get_relations

return get_relations(self)

def clear(self):
Expand Down
7 changes: 6 additions & 1 deletion invenio_app_ils/relations/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
from invenio_app_ils.errors import RecordRelationsError

ILS_RELATION_TYPE = namedtuple(
"IlsRelationType", RelationType._fields + ("relation_class", "sort_by",)
"IlsRelationType",
RelationType._fields
+ (
"relation_class",
"sort_by",
),
)

LANGUAGE_RELATION = ILS_RELATION_TYPE(
Expand Down
2 changes: 1 addition & 1 deletion invenio_app_ils/series/loaders/jsonschemas/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
ChangedBySchema,
set_changed_by,
)
from invenio_app_ils.records.loaders.schemas.identifiers import IdentifierSchema
from invenio_app_ils.records.loaders.schemas.preserve_cover_metadata import (
preserve_cover_metadata,
)
from invenio_app_ils.records.loaders.schemas.identifiers import IdentifierSchema
from invenio_app_ils.series.api import Series


Expand Down
3 changes: 2 additions & 1 deletion tests/api/ils/items/test_items_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ def test_item_refs(app, testdata):
document_pid="docid-1",
internal_location_pid="ilocid-4",
created_by=dict(type="script", value="demo"),
barcode="348048",
barcode="cm-348048",
status="CAN_CIRCULATE",
circulation_restriction="NO_RESTRICTION",
medium="PAPER",
)
)
assert "$schema" in item
assert "document" in item and "$ref" in item["document"]
assert item["barcode"] == "CM-348048"
assert "internal_location" in item and "$ref" in item["internal_location"]

item = Item.get_record_by_pid("itemid-1")
Expand Down
5 changes: 5 additions & 0 deletions tests/api/ils/items/test_items_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def get_active_loan_pid_and_item_pid():
if total > 0:
return t["pid"], active_loan[0]["pid"]

item = Item.get_record_by_pid("itmeid-1")

Check failure on line 29 in tests/api/ils/items/test_items_update.py

View workflow job for this annotation

GitHub Actions / Tests (ils, 3.9, pypi, postgresql14, opensearch2)

test_update_item invenio_pidstore.errors.PIDDoesNotExistError
item["barcode"] = "aaabbbccc"
item.commit()
assert Item.get_record_by_pid("itmeid-1")["barcode"] == "AAABBBCCC"

# change document pid while is on loan
item_pid, loan_pid = get_active_loan_pid_and_item_pid()
item = Item.get_record_by_pid(item_pid)
Expand Down

0 comments on commit 91ff204

Please sign in to comment.