handle is_system_auditor case with unsaved users

This commit is contained in:
AlanCoding
2016-12-05 12:05:00 -05:00
parent 14746eebe3
commit 8c64fa2fe1
2 changed files with 22 additions and 42 deletions

View File

@@ -76,8 +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 = user.roles.filter(
singleton_name='system_auditor', role_field='system_auditor').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
user._is_system_auditor = False
return user._is_system_auditor