Skip to content

Commit

Permalink
fix: use the userobj from g for CKAN 2.9 + 2.10 support
Browse files Browse the repository at this point in the history
In CKAN 2.9, the user is not defined before login, so the userobj is not
instantiated (hence the attributeerror)

test: g has userobj, is it 2.9 and 2.10 compatible?

test: is userobj not defined before login?
  • Loading branch information
nickumia-reisys committed Sep 29, 2023
1 parent f841f8b commit fc68df2
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions ckanext/saml2auth/plugin.py
Expand Up @@ -25,7 +25,7 @@

import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit
from ckan.common import g, current_user
from ckan.common import g
import ckan.lib.base as base

from ckanext.saml2auth.views.saml2auth import saml2auth
Expand Down Expand Up @@ -96,15 +96,14 @@ def update_config(self, config_):
# IAuthenticator

def identify(self):
if (
current_user.is_authenticated and
current_user.is_active and
not session.get('last_active')
):
log.info('User {0}<{1}> logged in successfully{2}.'.format(
current_user.name, current_user.email,
' via saml' if session.get('_saml_session_info') else ''
))
try:
if g.userobj and not session.get('last_active'):
log.info('User {0}<{1}> logged in successfully{2}.'.format(
g.userobj.name, g.userobj.email,
' via saml' if session.get('_saml_session_info') else ''
))
except AttributeError:
log.info(u'No user defined!')

def logout(self):

Expand Down

0 comments on commit fc68df2

Please sign in to comment.