diff --git a/pyproject.toml b/pyproject.toml index 442976224e..5359026e8b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -325,6 +325,7 @@ fullname = "rero_ils.oauth.scopes:fullname" institution = "rero_ils.oauth.scopes:institution" patron_type = "rero_ils.oauth.scopes:patron_type" patron_types = "rero_ils.oauth.scopes:patron_types" +patron_pid = "rero_ils.oauth.scopes:patron_pid" [tool.poetry.plugins."invenio_pidstore.fetchers"] acq_account_id = "rero_ils.modules.acquisition.acq_accounts.api:acq_account_id_fetcher" diff --git a/rero_ils/modules/patrons/views.py b/rero_ils/modules/patrons/views.py index 54967e5dad..68e8a69504 100644 --- a/rero_ils/modules/patrons/views.py +++ b/rero_ils/modules/patrons/views.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # RERO ILS -# Copyright (C) 2019-2023 RERO +# Copyright (C) 2024 RERO # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -371,6 +371,9 @@ def get_institution_code(institution): # Get the main patron patron = get_main_patron(patrons) + # Patrin pid + if "patron_pid" in token_scopes: + data["patron_pid"] = patron.pid # Barcode if patron.get("patron", {}).get("barcode"): data["barcode"] = patron["patron"]["barcode"][0] diff --git a/rero_ils/oauth/scopes.py b/rero_ils/oauth/scopes.py index 93922c449c..3c9b6c1596 100644 --- a/rero_ils/oauth/scopes.py +++ b/rero_ils/oauth/scopes.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # RERO ILS -# Copyright (C) 2021 RERO +# Copyright (C) 2024 RERO # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -25,3 +25,4 @@ expiration_date = Scope("expiration_date", help_text="Expiration date", group="User") patron_type = Scope("patron_type", help_text="Patron type", group="User") patron_types = Scope("patron_types", help_text="Patron types", group="User") +patron_pid = Scope("patron_pid", help_text="Patron pid", group="User") diff --git a/setup.py b/setup.py index 0137a76b43..7b34c0a56c 100644 --- a/setup.py +++ b/setup.py @@ -373,7 +373,8 @@ def run(self): 'institution = rero_ils.oauth.scopes:institution', 'expiration_date = rero_ils.oauth.scopes:expiration_date', 'patron_type = rero_ils.oauth.scopes:patron_type', - 'patron_types = rero_ils.oauth.scopes:patron_types' + 'patron_types = rero_ils.oauth.scopes:patron_types', + 'patron_pid = rero_ils.oauth.scopes:patron_pid' ] }, classifiers=[ diff --git a/tests/api/patrons/test_patrons_rest.py b/tests/api/patrons/test_patrons_rest.py index 855e9de4f5..c256f7d91a 100644 --- a/tests/api/patrons/test_patrons_rest.py +++ b/tests/api/patrons/test_patrons_rest.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # # RERO ILS -# Copyright (C) 2019 RERO +# Copyright (C) 2024 RERO # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -478,6 +478,7 @@ def test_patron_info(app, client, patron_martigny, librarian_martigny): "expiration_date", "patron_type", "patron_types", + "patron_pid", ] # create a oauth client liked to the librarian account @@ -562,6 +563,7 @@ def test_patron_info(app, client, patron_martigny, librarian_martigny): "patron_type": "patron-code", } ], + "patron_pid": patron_martigny.pid, } # librarian information with all scopes