Merge pull request #4288 from AlanCoding/user_aud_31_fixes

Fix system auditor getter logic
This commit is contained in:
Alan Rominger
2016-12-05 17:07:19 -05:00
committed by GitHub
4 changed files with 35 additions and 43 deletions

View File

@@ -76,7 +76,12 @@ User.add_to_class('auditor_of_organizations', user_get_auditor_of_organizations)
@property
def user_is_system_auditor(user):
if not hasattr(user, '_is_system_auditor'):
user._is_system_auditor = Role.objects.filter(role_field='system_auditor', id=user.id).exists()
if user.pk:
user._is_system_auditor = user.roles.filter(
singleton_name='system_auditor', role_field='system_auditor').exists()
else:
# Odd case where user is unsaved, this should never be relied on
return False
return user._is_system_auditor