def test_disable_member(self, transaction): # Inert signals action transaction.on_commit.side_effect = lambda fn: fn() # Add permission perm = Permission.objects.create(codename='test_perm', name='test perm', content_type_id=1) # Add public group pub_group = Group.objects.create(name="A Public group") pub_group.authgroup.internal = False pub_group.authgroup.public = True pub_group.save() # Setup member self.member.user_permissions.add(perm) self.member.groups.add(pub_group) # Pre assertion self.assertIn(pub_group, self.member.groups.all()) self.assertGreater(len(self.member.groups.all()), 1) # Act disable_member(self.member) # Assert self.assertIn(pub_group, self.member.groups.all()) # Everything but the single public group wiped self.assertEqual(len(self.member.groups.all()), 1) # All permissions wiped self.assertEqual(len(self.member.user_permissions.all()), 0)
def pre_save_auth_state(sender, instance, *args, **kwargs): if instance.pk: old_instance = AuthServicesInfo.objects.get(pk=instance.pk) if old_instance.state != instance.state: logger.debug('Detected state change for %s' % instance.user) if instance.state == MEMBER_STATE: make_member(instance) elif instance.state == BLUE_STATE: make_blue(instance) else: disable_member(instance.user) validate_services.apply(args=(instance.user,))
def pre_save_auth_state(sender, instance, *args, **kwargs): if instance.pk: old_instance = AuthServicesInfo.objects.get(pk=instance.pk) if old_instance.state != instance.state: logger.debug('Detected state change for %s' % instance.user) if instance.state == MEMBER_STATE: make_member(instance) elif instance.state == BLUE_STATE: make_blue(instance) else: disable_member(instance.user) validate_services.apply(args=(instance.user, ))
def pre_save_user(sender, instance, *args, **kwargs): logger.debug("Received pre_save from %s" % instance) # check if user is being marked active/inactive if not instance.pk: # new model being created return try: old_instance = User.objects.get(pk=instance.pk) if old_instance.is_active and not instance.is_active: logger.info("Disabling services for inactivation of user %s" % instance) disable_member(instance) elif instance.is_active and not old_instance.is_active: logger.info("Assessing state of reactivated user %s" % instance) set_state(instance) except User.DoesNotExist: pass
def pre_delete_user(sender, instance, *args, **kwargs): logger.debug("Received pre_delete from %s" % instance) disable_member(instance)