set orga = True on login for superusers

This commit is contained in:
Élie Bouttier 2016-07-22 18:25:06 +02:00
parent c3a96ececf
commit ebc96aaad7
2 changed files with 10 additions and 5 deletions

View File

@ -20,7 +20,10 @@ def create_default_options(sender, **kwargs):
@receiver(user_logged_in)
def on_user_logged_in(sender, request, user, **kwargs):
proposition, created = Participation.objects.get_or_create(user=user, site=get_current_site(request))
participation, created = Participation.objects.get_or_create(user=user, site=get_current_site(request))
if user.is_superuser:
participation.orga = True
participation.save()
if created:
messages.info(request, "Please check your profile!\n", fail_silently=True) # FIXME
messages.success(request, 'Welcome!', fail_silently=True) # FIXME

View File

@ -53,11 +53,13 @@ class AccountTests(TestCase):
b = User.objects.get(username='b')
b.is_superuser = True
b.save()
p = Participation.objects.get(user=b)
self.assertFalse(p.orga)
self.assertEqual(self.client.get(reverse('list-participant')).status_code, 200)
b = Participation.objects.get(user=b)
b.is_superuser = False
b.orga = True
b.save()
# login signal should set orga to True due to superuser status
self.client.login(username='b', password='b')
p = Participation.objects.get(user=b)
self.assertTrue(p.orga)
self.assertEqual(self.client.post(reverse('edit-participant', kwargs={'username': 'a'}),
{'biography': 'foo', 'nootes': 'bar'}).status_code, 200)
self.assertEqual(User.objects.get(username='a').profile.biography, '')