Skip to content

Commit b2166e6

Browse files
committed
experiment matching
1 parent 95c0e78 commit b2166e6

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

recastcontrolcenter/server.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import recastconfig
33
import json
44
import os
5+
import logging
56
import importlib
67
import pkg_resources
78
import yaml
@@ -16,6 +17,8 @@
1617
from recastdb.database import db
1718

1819

20+
log = logging.getLogger(__name__)
21+
1922
def get_blueprint(name):
2023
module, attr = name.split(':')
2124
blueprintmodule = importlib.import_module(module)
@@ -70,6 +73,29 @@ def user_data(access_token):
7073
return r.json()
7174

7275

76+
def extract_user_info(userdata):
77+
userjson = {'experiment': 'unaffiliated'}
78+
79+
egroup_to_expt = {
80+
'cms-members': 'CMS',
81+
'alice-member': 'ALICE',
82+
'atlas-active-members-all': 'ATLAS',
83+
'lhcb-general': 'LHCb'
84+
}
85+
86+
for x in userdata:
87+
if x['Type'] == 'http://schemas.xmlsoap.org/claims/Firstname':
88+
userjson['firstname'] = x['Value']
89+
if x['Type'] == 'http://schemas.xmlsoap.org/claims/Lastname"':
90+
userjson['lastname'] = x['Value']
91+
if x['Type'] == 'http://schemas.xmlsoap.org/claims/CommonName':
92+
userjson['username'] = x['Value']
93+
if x['Type'] == 'http://schemas.xmlsoap.org/claims/Group':
94+
if x['Value'] in egroup_to_expt:
95+
userjson['experiment'] = egroup_to_expt[x['Value']]
96+
return userjson
97+
98+
7399
@flask_app.route(recastconfig.config['RECAST_OAUTH_REDIRECT_ROUTE'])
74100
@oauth_app.authorized_handler
75101
def oauth_redirect(resp):
@@ -78,23 +104,14 @@ def oauth_redirect(resp):
78104
return redirect(next_url)
79105

80106
data = user_data(resp['access_token'])
81-
session['user'] = {}
82-
83-
for x in data:
84-
if x['Type'] == 'http://schemas.xmlsoap.org/claims/Firstname':
85-
session['user']['firstname'] = x['Value']
86-
if x['Type'] == 'http://schemas.xmlsoap.org/claims/Lastname"':
87-
session['user']['lastname'] = x['Value']
88-
if x['Type'] == 'http://schemas.xmlsoap.org/claims/CommonName':
89-
session['user']['username'] = x['Value']
107+
session['user'] = extract_user_info(data)
90108

91109
return redirect(next_url)
92110

93111

94112
@flask_app.route('/login')
95113
def login():
96-
redirect_uri = recastconfig.config[
97-
'RECAST_BASEURL'] + url_for('oauth_redirect')
114+
redirect_uri = recastconfig.config['RECAST_BASEURL'] + url_for('oauth_redirect')
98115
return oauth_app.authorize(callback=redirect_uri)
99116

100117

recastcontrolcenter/templates/nav.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<li id="nav-allreq"><a href="{{url_for('recast.recast_workflow_catalogue_view')}}">Implemented Analyses</a></li>
2020
<li id="nav-allreq"><a href="{{url_for('recast.recast_requests_view')}}">All Requests</a></li>
2121
{% if session.has_key('user') %}
22-
<li id="nav-allreq"><a href="/"><span class="glyphicon glyphicon-user"></span> {{session['user']['username']}}</a></li>
22+
<li id="nav-allreq"><a href="/"><span class="glyphicon glyphicon-user"></span> {{session['user']['username']}} ({{session['user']['experiment']}})</a></li>
2323
<li id="nav-allreq"><a href="/logout"><i class="glyphicon glyphicon-log-out"></i>&nbsp;Logout</a></li>
2424
{% else %}
2525
<li id="nav-allreq"><a href="/login">Login</a></li>

0 commit comments

Comments
 (0)