Removed database calls and made scope filter a callable

This commit is contained in:
0mar
2021-02-25 07:30:41 +01:00
parent de2e8ff355
commit 1c789fcbb5
5 changed files with 128 additions and 80 deletions

View File

@@ -81,8 +81,6 @@ class BaseHandler(RequestHandler):
The current user (None if not logged in) may be accessed
via the `self.current_user` property during the handling of any request.
"""
self.raw_scopes = set()
self.parsed_scopes = set()
try:
await self.get_current_user()
except Exception:
@@ -431,16 +429,8 @@ class BaseHandler(RequestHandler):
# don't let errors here raise more than once
self._jupyterhub_user = None
self.log.exception("Error getting current user")
self._parse_scopes()
return self._jupyterhub_user
def _parse_scopes(self):
if self._jupyterhub_user is not None or self.get_current_user_oauth_token():
self.raw_scopes = roles.get_subscopes(*self._jupyterhub_user.roles)
if 'all' in self.raw_scopes:
self.raw_scopes |= scopes.get_user_scopes(self.current_user.name)
self.parsed_scopes = scopes.parse_scopes(self.raw_scopes)
@property
def current_user(self):
"""Override .current_user accessor from tornado