-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix/metadata_extensions
- Loading branch information
Showing
16 changed files
with
313 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -193,17 +193,17 @@ def run_command(command, catch_exceptions=False, verbose=True): | |
|
||
# Create users | ||
run_command("users create [email protected] -a --password=123456") # ID 1 | ||
create_userprofile_for("[email protected]", "patron1", "Yannic Vilma") | ||
create_userprofile_for("[email protected]", "patron1", "VILMA, Yannic") | ||
run_command("users create [email protected] -a --password=123456") # ID 2 | ||
create_userprofile_for("[email protected]", "patron2", "Diana Adi") | ||
create_userprofile_for("[email protected]", "patron2", "ADI, Diana") | ||
run_command("users create [email protected] -a --password=123456") # ID 3 | ||
create_userprofile_for("[email protected]", "admin", "Zeki Ryoichi") | ||
create_userprofile_for("[email protected]", "admin", "RYOICHI, Zeki") | ||
run_command("users create [email protected] -a --password=123456") # ID 4 | ||
create_userprofile_for("[email protected]", "librarian", "Hector Nabu") | ||
create_userprofile_for("[email protected]", "librarian", "NABU, Hector") | ||
run_command("users create [email protected] -a --password=123456") # ID 5 | ||
create_userprofile_for("[email protected]", "patron3", "Medrod Tara") | ||
create_userprofile_for("[email protected]", "patron3", "TARA, Medrod") | ||
run_command("users create [email protected] -a --password=123456") # ID 6 | ||
create_userprofile_for("[email protected]", "patron4", "Devi Cupid") | ||
create_userprofile_for("[email protected]", "patron4", "CUPID, Devi") | ||
|
||
# Assign roles | ||
run_command("roles add [email protected] admin") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,8 @@ class LdapClient(object): | |
Response example: | ||
[ | ||
{'displayName': [b'Joe Foe'], | ||
{'givenName': [b'Joe'], | ||
'sn': [b'FOE'], | ||
'department': [b'IT/CDA'], | ||
'uidNumber': [b'100000'], | ||
'mail': [b'[email protected]'], | ||
|
@@ -32,7 +33,8 @@ class LdapClient(object): | |
|
||
LDAP_USER_RESP_FIELDS = [ | ||
"mail", | ||
"displayName", | ||
"givenName", | ||
"sn", | ||
"department", | ||
"cernAccountType", | ||
"employeeID", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,8 @@ class LdapUserImporter: | |
Expected input format for ldap users: | ||
[ | ||
{'displayName': [b'Joe Foe'], | ||
{'givenName': [b'Joe'], | ||
'sn': [b'FOE'], | ||
'department': [b'IT/CDA'], | ||
'uidNumber': [b'100000'], | ||
'mail': [b'[email protected]'], | ||
|
@@ -54,7 +55,9 @@ def create_invenio_user_identity(self, user_id, ldap_user): | |
|
||
def create_invenio_user_profile(self, user_id, ldap_user): | ||
"""Return new user profile.""" | ||
display_name = ldap_user["user_profile_full_name"] | ||
display_name = "{0}, {1}".format( | ||
ldap_user["user_profile_last_name"], ldap_user["user_profile_first_name"] | ||
) | ||
return UserProfile( | ||
user_id=user_id, | ||
_displayname="id_{}".format(user_id), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# 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 oauth overrides.""" | ||
from flask import current_app, flash, g, redirect | ||
from invenio_oauthclient.contrib.cern_openid import get_resource | ||
from invenio_oauthclient.errors import OAuthCERNRejectedAccountError | ||
from invenio_oauthclient.handlers.rest import response_handler | ||
|
||
|
||
def _account_info(remote, resp): | ||
"""Retrieve remote account information used to find local user.""" | ||
g.oauth_logged_in_with_remote = remote | ||
resource = get_resource(remote, resp) | ||
|
||
valid_roles = current_app.config.get("OAUTHCLIENT_CERN_OPENID_ALLOWED_ROLES") | ||
cern_roles = resource.get("cern_roles") | ||
if cern_roles is None or not set(cern_roles).issubset(valid_roles): | ||
raise OAuthCERNRejectedAccountError( | ||
"User roles {0} are not one of {1}".format(cern_roles, valid_roles), | ||
remote, | ||
resp, | ||
) | ||
|
||
email = resource["email"] | ||
external_id = resource["cern_upn"] | ||
nice = resource["preferred_username"] | ||
name = "{0}, {1}".format(resource["family_name"].upper(), resource["given_name"]) | ||
|
||
return dict( | ||
user=dict(email=email.lower(), profile=dict(username=nice, full_name=name)), | ||
external_id=external_id, | ||
external_method="cern_openid", | ||
active=True, | ||
) | ||
|
||
|
||
def account_info(remote, resp): | ||
"""Retrieve remote account information used to find local user.""" | ||
try: | ||
return _account_info(remote, resp) | ||
except OAuthCERNRejectedAccountError as e: | ||
current_app.logger.warning(e.message, exc_info=True) | ||
flash(_("CERN account not allowed."), category="danger") | ||
return redirect("/") | ||
|
||
|
||
def account_info_rest(remote, resp): | ||
"""Retrieve remote account information used to find local user.""" | ||
try: | ||
return _account_info(remote, resp) | ||
except OAuthCERNRejectedAccountError as e: | ||
current_app.logger.warning(e.message, exc_info=True) | ||
remote_app_config = current_app.config["OAUTHCLIENT_REST_REMOTE_APPS"][ | ||
remote.name | ||
] | ||
return response_handler( | ||
remote, | ||
remote_app_config["error_redirect_url"], | ||
payload=dict(message="CERN account not allowed.", code=400), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.