Skip to content

Commit

Permalink
oauth: add patron pid
Browse files Browse the repository at this point in the history
* Adds `patron_pid` to scope.
* Closes #3710.

Co-Authored-by: Peter Weber <[email protected]>
  • Loading branch information
rerowep committed Nov 28, 2024
1 parent 930dd5c commit bc8b1a7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion rero_ils/modules/patrons/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion rero_ils/oauth/scopes.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down
4 changes: 3 additions & 1 deletion tests/api/patrons/test_patrons_rest.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bc8b1a7

Please sign in to comment.