Skip to content

Commit

Permalink
Merge pull request #4396 from ryanpetrello/ldap-audit
Browse files Browse the repository at this point in the history
properly set `is_system_auditor` on initial LDAP login

Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
  • Loading branch information
softwarefactory-project-zuul[bot] authored Jul 30, 2019
2 parents 5d6916f + a47a2d8 commit 8c4aac3
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions awx/main/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,22 @@ def user_is_system_auditor(user):

@user_is_system_auditor.setter
def user_is_system_auditor(user, tf):
if user.id:
if tf:
role = Role.singleton('system_auditor')
# must check if member to not duplicate activity stream
if user not in role.members.all():
role.members.add(user)
user._is_system_auditor = True
else:
role = Role.singleton('system_auditor')
if user in role.members.all():
role.members.remove(user)
user._is_system_auditor = False
if not user.id:
# If the user doesn't have a primary key yet (i.e., this is the *first*
# time they've logged in, and we've just created the new User in this
# request), we need one to set up the system auditor role
user.save()
if tf:
role = Role.singleton('system_auditor')
# must check if member to not duplicate activity stream
if user not in role.members.all():
role.members.add(user)
user._is_system_auditor = True
else:
role = Role.singleton('system_auditor')
if user in role.members.all():
role.members.remove(user)
user._is_system_auditor = False


User.add_to_class('is_system_auditor', user_is_system_auditor)
Expand Down

0 comments on commit 8c4aac3

Please sign in to comment.