@@ -93,8 +93,9 @@ def authenticate(self, **kwargs):
93
93
94
94
if getattr (settings , 'OPENID_PHYSICAL_MULTIFACTOR_REQUIRED' , False ):
95
95
pape_response = pape .Response .fromSuccessResponse (openid_response )
96
- if pape_response is None or \
97
- pape .AUTH_MULTI_FACTOR_PHYSICAL not in pape_response .auth_policies :
96
+ key = pape .AUTH_MULTI_FACTOR_PHYSICAL
97
+ if (pape_response is None or
98
+ key not in pape_response .auth_policies ):
98
99
raise MissingPhysicalMultiFactor ()
99
100
100
101
teams_response = teams .TeamsResponse .fromSuccessResponse (
@@ -194,12 +195,12 @@ def _get_available_username(self, nickname, identity_url):
194
195
if nickname is None or nickname == '' :
195
196
raise MissingUsernameViolation ()
196
197
197
- # If we don't have a nickname, and we're not being strict, use a default
198
+ # If we don't have a nickname, and we're not being strict, use default
198
199
nickname = nickname or 'openiduser'
199
200
200
201
# See if we already have this nickname assigned to a username
201
202
try :
202
- user = User .objects .get (username__exact = nickname )
203
+ User .objects .get (username__exact = nickname )
203
204
except User .DoesNotExist :
204
205
# No conflict, we can use this nickname
205
206
return nickname
@@ -231,7 +232,6 @@ def _get_available_username(self, nickname, identity_url):
231
232
# No user associated with this identity_url
232
233
pass
233
234
234
-
235
235
if getattr (settings , 'OPENID_STRICT_USERNAMES' , False ):
236
236
if User .objects .filter (username__exact = nickname ).count () > 0 :
237
237
raise DuplicateUsernameViolation (
@@ -248,7 +248,7 @@ def _get_available_username(self, nickname, identity_url):
248
248
if i > 1 :
249
249
username += str (i )
250
250
try :
251
- user = User .objects .get (username__exact = username )
251
+ User .objects .get (username__exact = username )
252
252
except User .DoesNotExist :
253
253
break
254
254
i += 1
@@ -266,12 +266,12 @@ def create_user_from_openid(self, openid_response):
266
266
"An attribute required for logging in was not "
267
267
"returned ({0})." .format (required_attr ))
268
268
269
- nickname = self ._get_preferred_username (details [ 'nickname' ],
270
- details ['email' ])
269
+ nickname = self ._get_preferred_username (
270
+ details ['nickname' ], details [ ' email' ])
271
271
email = details ['email' ] or ''
272
272
273
- username = self ._get_available_username (nickname ,
274
- openid_response .identity_url )
273
+ username = self ._get_available_username (
274
+ nickname , openid_response .identity_url )
275
275
276
276
user = User .objects .create_user (username , email , password = None )
277
277
self .associate_openid (user , openid_response )
@@ -328,13 +328,16 @@ def update_user_details(self, user, details, openid_response):
328
328
user .save ()
329
329
330
330
def get_teams_mapping (self ):
331
- teams_mapping_auto = getattr (settings , 'OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO' , False )
332
- teams_mapping_auto_blacklist = getattr (settings , 'OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO_BLACKLIST' , [])
331
+ teams_mapping_auto = getattr (
332
+ settings , 'OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO' , False )
333
+ teams_mapping_auto_blacklist = getattr (
334
+ settings , 'OPENID_LAUNCHPAD_TEAMS_MAPPING_AUTO_BLACKLIST' , [])
333
335
teams_mapping = getattr (settings , 'OPENID_LAUNCHPAD_TEAMS_MAPPING' , {})
334
336
if teams_mapping_auto :
335
- #ignore teams_mapping. use all django-groups
337
+ # ignore teams_mapping. use all django-groups
336
338
teams_mapping = dict ()
337
- all_groups = Group .objects .exclude (name__in = teams_mapping_auto_blacklist )
339
+ all_groups = Group .objects .exclude (
340
+ name__in = teams_mapping_auto_blacklist )
338
341
for group in all_groups :
339
342
teams_mapping [group .name ] = group .name
340
343
return teams_mapping
@@ -344,12 +347,12 @@ def update_groups_from_teams(self, user, teams_response):
344
347
if len (teams_mapping ) == 0 :
345
348
return
346
349
347
- current_groups = set ( user . groups . filter (
348
- name__in = teams_mapping . values ()))
349
- desired_groups = set ( Group . objects . filter (
350
- name__in = [ teams_mapping [ lp_team ]
351
- for lp_team in teams_response . is_member
352
- if lp_team in teams_mapping ] ))
350
+ mapping = [
351
+ teams_mapping [ lp_team ] for lp_team in teams_response . is_member
352
+ if lp_team in teams_mapping ]
353
+ current_groups = set (
354
+ user . groups . filter ( name__in = teams_mapping . values ()))
355
+ desired_groups = set ( Group . objects . filter ( name__in = mapping ))
353
356
for group in current_groups - desired_groups :
354
357
user .groups .remove (group )
355
358
for group in desired_groups - current_groups :
0 commit comments