def test_remove_permission_can_see_user_from_registered(self): self.assertTrue(self.user.has_perm('users.can_see')) # Remove perm from registered group can_see_perm = Permission.objects.get( content_type=ContentType.objects.get(app_label='users', model='user'), codename='can_see') get_registered_group().permissions.remove(can_see_perm) # Reload user self.user = User.objects.get(pk=1) self.assertTrue(self.user.has_perm('users.can_see'))
def post_save(self, form): super(UserCreateView, self).post_save(form) # TODO: find a better solution that makes the following lines obsolete # Background: motion.models.use_post_save adds already the registerd group # to new user but super(..).post_save(form) removes it and sets only the # groups selected in the form (without 'registered') # workaround: add registered group again manually from openslides.users.api import get_registered_group # TODO: Test, if global import is possible registered = get_registered_group() self.object.groups.add(registered)
def user_post_save(sender, instance, *args, **kwargs): """ Receiver function to add a new user to the registered group. It is connected to the signal django.db.models.signals.post_save during app loading. """ if not kwargs['created']: return from openslides.users.api import get_registered_group # TODO: Test, if global import is possible registered = get_registered_group() instance.groups.add(registered) instance.save()
def test_normal(self, mock_group): mock_group.objects.get.return_value = 'test_group' self.assertEqual(get_registered_group(), 'test_group') mock_group.objects.getassert_called_once_with(pk=2)