Skip to content
Snippets Groups Projects
Commit 4b1a9fc1 authored by Albert Feghaly's avatar Albert Feghaly
Browse files

Merge branch '52-populate-user-info-at-login' into 'dev'

Resolve "Populate user info at login"

Closes #52

See merge request !49
parents 2cd7b1f1 8de4aa91
No related branches found
No related tags found
2 merge requests!55Merge dev into master,!49Resolve "Populate user info at login"
......@@ -144,6 +144,13 @@ class Client:
'username/password combination.'
)
self.query_my_profile()
sys.stdout.write(
'Your connexion to IRIC-Data has been established ' +
'[username=%s email=%s]\n' % (self.username, self.email)
)
if not lightmode:
self.labs
self.datasets
......@@ -157,11 +164,10 @@ class Client:
def _token_auth(self):
# Note that some requests might not function (e.g. get_available_labs)
# unless a query is sent to get authenticated with IRIC-Data. This query
# is currently set to `self.query_my_profile()`
self.session.headers.update({'Iric-Auth-Token': F'{self.token}'})
# Send a simple query to get authenticated with IRIC-Data
# Otherwise, some requests might not function (e.g. get_available_labs)
self.get_available_datasets(return_df=False)
sys.stdout.write('Your connexion to IRIC-Data has been established\n')
def _userpass_auth(self):
......@@ -178,11 +184,6 @@ class Client:
self.get_response(login_url, method='post',
cookies=cookies, data=payload, headers=headers)
sys.stdout.write(
'Your connexion to IRIC-Data has been ' +
'established [user=%s]\n' % self.username
)
# ==> A cleaner way would be to verify route accesses directly
# as done for PAT-based access
......@@ -501,7 +502,9 @@ class Client:
return df
def _query_profiles(self, profile_email_list, api_token=False):
def _query_profiles(self, profile_email_list, api_token=False, me=False):
assert not (api_token and me)
gql_in_name_list = ""
if type(profile_email_list) is str:
......@@ -512,9 +515,11 @@ class Client:
elif profile_email_list is not None:
warn("Wrong format for GraphQL 'keys' argument. Ignoring.")
field = 'profiles_token' if api_token else 'my_profile' if me else 'profiles'
query = """
{
profiles%s(
%s(
%s
) {
id
......@@ -526,7 +531,7 @@ class Client:
}
}
""" % (
('_token' if api_token else ''),
field,
gql_in_name_list,
('api_token' if api_token else '')
)
......@@ -544,7 +549,20 @@ class Client:
if self.verbose:
print(gql_res)
return gql_res['data']['profiles%s' % ('_token' if api_token else '')]
return gql_res['data'][field]
def query_my_profile(self):
"""Construct a DataFrame of user's information.
"""
r = self._query_profiles(None, me=True)
self.id = r['id']
self.email = r['user']['email']
if self.username is None:
self.username = r['user']['username']
else:
assert self.username == r['user']['username']
def query_profiles(self, profile_email_list=None):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment