Skip to content

Commit

Permalink
contrib: removal of dependency on Invenio-Groups
Browse files Browse the repository at this point in the history
* Removes the dependency on Invenio-Groups reducing the number of fields
  parsed inside CERN or ORCID modules and sending the response to a
  subscribable signal. (closes #18)

Signed-off-by: Javier Delgado <javier.delgado.fernandez@cern.ch>
  • Loading branch information
JavierDelgadoFernandez committed Dec 1, 2015
1 parent 0f54e05 commit 8904cba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
18 changes: 8 additions & 10 deletions invenio_oauthclient/contrib/cern.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import re

import requests
from blinker import signal
from flask import current_app
from flask_login import current_user

Expand Down Expand Up @@ -159,6 +160,9 @@
REMOTE_APP_RESOURCE_SCHEMA = "http://schemas.xmlsoap.org/claims/"


oauth_cern_response_received = signal('oauth-cern-response-received')


def fetch_groups(groups):
"""Prepare list of allowed group names."""
hidden_groups = current_app.config.get(
Expand Down Expand Up @@ -197,6 +201,8 @@ def account_info(remote, resp):
email = res['EmailAddress'][0]
common_name = res['CommonName'][0]

oauth_cern_response_received(resp)

# FIXME get user informations accordly with invenio-userprofiles
return dict(email=email.lower(), nickname=common_name)

Expand All @@ -210,13 +216,5 @@ def account_setup(remote, token):

if response.status == requests.codes.ok:
res = get_dict_from_response(response)
current_user.info['group'] = fetch_groups(res['Group'])
current_user.modified = True
current_user.save()

if user and not any([user.family_name, user.given_names]):
user.family_name = res['Lastname'][0]
user.given_names = res['Firstname'][0]

db.session.add(user)
current_user.reload()
res['groups'] = fetch_groups(res['Group'])
oauth_cern_response_received.send(res)
7 changes: 7 additions & 0 deletions invenio_oauthclient/contrib/orcid.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@

import copy

from blinker import signal
from flask import current_app, redirect, url_for
from flask_login import current_user
from invenio_db import db
Expand Down Expand Up @@ -119,9 +120,13 @@
))


oauth_orcid_response_received = signal('oauth-orcid-response-received')


def account_info(remote, resp):
"""Retrieve remote account information used to find local user."""
orcid = resp.get("orcid")
oauth_orcid_response_received.send(resp)
return dict(
external_id=orcid,
external_method="orcid",
Expand Down Expand Up @@ -166,6 +171,8 @@ def account_setup(remote, token, resp):
# Create user <-> external id link.
oauth_link_external_id(user, dict(id=orcid, method="orcid"))

oauth_orcid_response_received.send(resp)

# FIXME put these data in user profile!
# Fill user full name if not already set
# if user and not any([user.given_names, user.family_name]):
Expand Down

0 comments on commit 8904cba

Please sign in to comment.