Skip to content

Commit

Permalink
Remove CERN-specific code from search
Browse files Browse the repository at this point in the history
  • Loading branch information
ThiefMaster committed Aug 20, 2020
1 parent 89e0760 commit 8e4212f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 57 deletions.
5 changes: 2 additions & 3 deletions newdle/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
from sqlalchemy.orm import selectinload
from werkzeug.exceptions import Forbidden, ServiceUnavailable, UnprocessableEntity

from .cern_integration import search_cern_users
from .core.auth import user_info_from_app_token
from .core.auth import search_users, user_info_from_app_token
from .core.db import db
from .core.util import DATE_FORMAT, format_dt, range_union, sign_user
from .core.webargs import abort, use_args, use_kwargs
Expand Down Expand Up @@ -142,7 +141,7 @@ def users(name, email):
elif not current_app.config['MULTIPASS_IDENTITY_PROVIDER_SEARCH']:
raise ServiceUnavailable('Search is not available')
else:
total, data = search_cern_users(name, email, 10)
total, data = search_users(name, email, 10)
return {
'total': total,
'users': [
Expand Down
50 changes: 0 additions & 50 deletions newdle/cern_integration.py

This file was deleted.

7 changes: 6 additions & 1 deletion newdle/core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ def _configure_multipass(app):
if search_provider:
app.config['MULTIPASS_IDENTITY_PROVIDERS']['newdle-search'] = search_provider
app.config['MULTIPASS_PROVIDER_MAP'] = {'newdle-sso': 'newdle-sso'}
app.config['MULTIPASS_IDENTITY_INFO_KEYS'] = {'email', 'given_name', 'family_name'}
app.config['MULTIPASS_IDENTITY_INFO_KEYS'] = {
'email',
'given_name',
'family_name',
'name',
}
multipass.init_app(app)
with app.app_context():
if not multipass.auth_providers['newdle-sso'].is_external:
Expand Down
22 changes: 22 additions & 0 deletions newdle/core/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,25 @@ def user_info_from_app_token(app_token):
return secure_serializer.loads(
app_token, salt='app-token', max_age=current_app.config['TOKEN_LIFETIME']
)


def search_users(name, email, limit):
criteria = {}
if name:
criteria['name'] = name
if email:
criteria['email'] = email

identities, total = multipass.search_identities_ex(
{'newdle-search'}, limit=limit, criteria=criteria
)
users = [
{
'email': identity.data['email'],
'first_name': identity.data['given_name'],
'last_name': identity.data['family_name'],
'uid': identity.identifier,
}
for identity in sorted(identities, key=lambda x: x.data['name'])
]
return total, users
2 changes: 1 addition & 1 deletion newdle/newdle.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ MULTIPASS_AUTH_PROVIDER_LOGIN = {
}

# The Flask-Multipass identity provider settings. Currently only one provider is supported
# and it needs to provide the following data keys: email, given_name, family_name, sub
# and it needs to provide the following data keys: email, given_name, family_name, name
MULTIPASS_IDENTITY_PROVIDER_LOGIN = {'type': 'authlib'}

# The Flask-Multipass identity provider settings used to search for existing people.
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ faker==2.0.3
Flask-Caching==1.7.2
flask-marshmallow==0.10.1
flask-migrate==2.5.2
Flask-Multipass[authlib]==0.3
Flask-Multipass[authlib]==0.3.1
Flask-SQLAlchemy==2.4.4
flask-url-map-serializer==0.0.1
Flask==1.1.1
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ def get_requirements():
zip_safe=False,
python_requires='>=3.7',
install_requires=get_requirements(),
extras_require={'exchange': ['exchangelib'], 'cern': ['Flask-Multipass-CERN']},
extras_require={
'exchange': ['exchangelib'],
'cern': ['Flask-Multipass-CERN>=1.0.dev3'],
},
)

0 comments on commit 8e4212f

Please sign in to comment.