Skip to content

Commit

Permalink
location: implements UCL paging functionalities
Browse files Browse the repository at this point in the history
This commit implements tasks relative to UCL paging request in closed stack.
It allows to limit request for items belonging to specific location.
It also allows to restrict the pickup destination to some pickup locations
instead of all pickups locations of the organisation.
If an item of a "paging" location is requested, it also allows to send
a notification to notify a manager.

* Adds some tests function to cover new functionalities.
* Refactoring circulation actions permissions (can_request, ...)
* Increases general code coverage

Co-Authored-by: Renaud Michotte <[email protected]>
  • Loading branch information
zannkukai committed May 13, 2020
1 parent 9f436dc commit c1b0343
Show file tree
Hide file tree
Showing 28 changed files with 950 additions and 252 deletions.
98 changes: 65 additions & 33 deletions data/locations.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"$ref": "https://ils.rero.ch/api/libraries/1"
},
"is_pickup": true,
"pickup_name": "AOSTE CANT1: Espaces publics"
"pickup_name": "AOSTE CANT1: Espaces publics",
"allow_request": true
},
{
"pid": "2",
Expand All @@ -17,7 +18,8 @@
"name": "Bibliographie vald\u00f4taine",
"library": {
"$ref": "https://ils.rero.ch/api/libraries/1"
}
},
"allow_request": true
},
{
"pid": "3",
Expand All @@ -26,7 +28,8 @@
"name": "Magasin A",
"library": {
"$ref": "https://ils.rero.ch/api/libraries/1"
}
},
"allow_request": true
},
{
"pid": "4",
Expand All @@ -37,7 +40,8 @@
"library": {
"$ref": "https://ils.rero.ch/api/libraries/1"
},
"is_online": true
"is_online": true,
"allow_request": true
},
{
"pid": "5",
Expand All @@ -48,7 +52,8 @@
"$ref": "https://ils.rero.ch/api/libraries/2"
},
"is_pickup": true,
"pickup_name": "AOSTE CANT2: Espaces publics"
"pickup_name": "AOSTE CANT2: Espaces publics",
"allow_request": true
},
{
"pid": "7",
Expand All @@ -57,7 +62,8 @@
"name": "Section fiction",
"library": {
"$ref": "https://ils.rero.ch/api/libraries/3"
}
},
"allow_request": true
},
{
"pid": "8",
Expand All @@ -66,7 +72,8 @@
"name": "Section documentaires",
"library": {
"$ref": "https://ils.rero.ch/api/libraries/3"
}
},
"allow_request": true
},
{
"pid": "9",
Expand All @@ -75,7 +82,8 @@
"name": "Section enfants",
"library": {
"$ref": "https://ils.rero.ch/api/libraries/3"
}
},
"allow_request": true
},
{
"pid": "10",
Expand All @@ -84,7 +92,8 @@
"name": "Section multim\u00e9dia",
"library": {
"$ref": "https://ils.rero.ch/api/libraries/3"
}
},
"allow_request": true
},
{
"pid": "11",
Expand All @@ -95,7 +104,8 @@
"$ref": "https://ils.rero.ch/api/libraries/3"
},
"is_pickup": true,
"pickup_name": "AOSTE-AVISE-PUB: Espaces publics"
"pickup_name": "AOSTE-AVISE-PUB: Espaces publics",
"allow_request": true
},
{
"pid": "12",
Expand All @@ -106,7 +116,8 @@
"library": {
"$ref": "https://ils.rero.ch/api/libraries/3"
},
"is_online": true
"is_online": true,
"allow_request": true
},
{
"pid": "13",
Expand All @@ -117,7 +128,8 @@
"$ref": "https://ils.rero.ch/api/libraries/4"
},
"is_pickup": true,
"pickup_name": "AOSTE-LYCEE: Espaces publics"
"pickup_name": "AOSTE-LYCEE: Espaces publics",
"allow_request": true
},
{
"pid": "14",
Expand All @@ -126,7 +138,8 @@
"name": "Travaux de maturit\u00e9",
"library": {
"$ref": "https://ils.rero.ch/api/libraries/4"
}
},
"allow_request": true
},
{
"pid": "16",
Expand All @@ -135,7 +148,8 @@
"name": "Restricted Section",
"library": {
"$ref": "https://ils.rero.ch/api/libraries/5"
}
},
"allow_request": true
},
{
"pid": "17",
Expand All @@ -146,7 +160,8 @@
"pickup_name": "Public Section",
"library": {
"$ref": "https://ils.rero.ch/api/libraries/5"
}
},
"allow_request": true
},
{
"pid": "18",
Expand All @@ -157,7 +172,8 @@
"library": {
"$ref": "https://ils.rero.ch/api/libraries/5"
},
"is_online": true
"is_online": true,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -169,7 +185,8 @@
},
"is_pickup": true,
"pickup_name": "La Citadelle",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -181,7 +198,8 @@
},
"is_pickup": true,
"pickup_name": "Beast's Library",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -193,7 +211,8 @@
},
"is_pickup": true,
"pickup_name": "Dream's Library",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -205,7 +224,8 @@
},
"is_pickup": true,
"pickup_name": "Lux Foundation Library",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -217,7 +237,8 @@
},
"is_pickup": true,
"pickup_name": "Hogwarts Library",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -229,7 +250,8 @@
},
"is_pickup": true,
"pickup_name": "Biblioth\u00e8que de Babel",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -241,7 +263,8 @@
},
"is_pickup": true,
"pickup_name": "Biblioth\u00e8que de l\u2019abbaye",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -253,7 +276,8 @@
},
"is_pickup": true,
"pickup_name": "The University's Library",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -265,7 +289,8 @@
},
"is_pickup": true,
"pickup_name": "Cemetery of Forgotten Books",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -277,7 +302,8 @@
},
"is_pickup": true,
"pickup_name": "Ministry of Truth",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -289,7 +315,8 @@
},
"is_pickup": true,
"pickup_name": "Rivendell Library",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -301,7 +328,8 @@
},
"is_pickup": true,
"pickup_name": "Matilda's Library",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -313,7 +341,8 @@
},
"is_pickup": true,
"pickup_name": "Unseen University Library",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -325,7 +354,8 @@
},
"is_pickup": true,
"pickup_name": "Wan Shi Tong's Library",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -337,7 +367,8 @@
},
"is_pickup": true,
"pickup_name": "Sunnydale High School library",
"is_online": false
"is_online": false,
"allow_request": true
},
{
"$schema": "https://ils.rero.ch/schema/locations/location-v0.0.1.json",
Expand All @@ -349,6 +380,7 @@
},
"is_pickup": true,
"pickup_name": "Jedi Archives",
"is_online": false
"is_online": false,
"allow_request": true
}
]
]
13 changes: 13 additions & 0 deletions rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
from .modules.holdings.api import Holding
from .modules.item_types.api import ItemType
from .modules.items.api import Item
from .modules.items.models import ItemCirculationAction
from .modules.items.permissions import can_create_item_factory, \
can_update_delete_item_factory
from .modules.libraries.api import Library
Expand Down Expand Up @@ -1706,6 +1707,18 @@ def _(x):
)
)

CIRCULATION_ACTIONS_VALIDATION = {
ItemCirculationAction.REQUEST: [
Location.allow_request,
Item.can_request,
CircPolicy.allow_request,
Patron.can_request
],
ItemCirculationAction.EXTEND: [
Item.can_extend
]
}

WEBPACKEXT_PROJECT = 'rero_ils.webpack:project'

# WIKI
Expand Down
33 changes: 33 additions & 0 deletions rero_ils/modules/circ_policies/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,39 @@ def reasons_not_to_delete(self):
cannot_delete['links'] = links
return cannot_delete

@classmethod
def allow_request(cls, item, **kwargs):
"""Check if the cipo corresponding to item/patron allow request.
:param item : the item to check
:param kwargs : To be relevant, additional arguments should contains
'patron' argument.
:return a tuple with True|False and reasons to disallow if False.
"""
from ..patrons.api import Patron
required_arguments = ['patron', 'patron_barcode', 'patron_pid']
if not any(k in required_arguments for k in kwargs):
# 'patron' argument are present into kwargs. This check can't
# be relevant --> return True by default
return True, []
patron = kwargs.get('patron') \
or Patron.get_patron_by_barcode(kwargs.get('patron_barcode')) \
or Patron.get_record_by_pid(kwargs.get('patron_pid'))
if 'patron' not in patron.get('roles', []):
# without 'patron' role, we can't find any patron_type and so we
# can't find any corresponding cipo --> return False
return False, ["Patron doesn't have the correct role"]
library_pid = kwargs['library'].pid if kwargs.get('library') \
else item.library_pid
cipo = cls.provide_circ_policy(
library_pid,
patron.patron_type_pid,
item.item_type_pid
)
if not cipo.get('allow_requests', False):
return False, ["Circulation policy disallows the operation."]
return True, []


class CircPoliciesIndexer(IlsRecordsIndexer):
"""Indexing documents in Elasticsearch."""
Expand Down
Loading

0 comments on commit c1b0343

Please sign in to comment.