Merge pull request #308 from AlanCoding/calm_your_signals2

avoid every-request user signals
This commit is contained in:
Alan Rominger
2017-08-26 11:56:41 -04:00
committed by GitHub

View File

@@ -140,6 +140,9 @@ def rebuild_role_ancestor_list(reverse, model, instance, pk_set, action, **kwarg
def sync_superuser_status_to_rbac(instance, **kwargs): def sync_superuser_status_to_rbac(instance, **kwargs):
'When the is_superuser flag is changed on a user, reflect that in the membership of the System Admnistrator role' 'When the is_superuser flag is changed on a user, reflect that in the membership of the System Admnistrator role'
update_fields = kwargs.get('update_fields', None)
if update_fields and 'is_superuser' not in update_fields:
return
if instance.is_superuser: if instance.is_superuser:
Role.singleton(ROLE_SINGLETON_SYSTEM_ADMINISTRATOR).members.add(instance) Role.singleton(ROLE_SINGLETON_SYSTEM_ADMINISTRATOR).members.add(instance)
else: else:
@@ -147,6 +150,8 @@ def sync_superuser_status_to_rbac(instance, **kwargs):
def create_user_role(instance, **kwargs): def create_user_role(instance, **kwargs):
if not kwargs.get('created', True):
return
try: try:
Role.objects.get( Role.objects.get(
content_type=ContentType.objects.get_for_model(instance), content_type=ContentType.objects.get_for_model(instance),