-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refonte de l'affichage du badge staff (#4240)
* Refonte de l'affichage du badge staff * Petite optimisation de la migration * Nom et dépendance du fichier de migration * Erreur lors du rebase * Migration revue * Corrige le problème lors de la migration initiale
- Loading branch information
Showing
4 changed files
with
88 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
from django.contrib.auth.models import User, Permission | ||
from zds.member.models import Profile | ||
from django.db.models import Q | ||
|
||
|
||
def forwards_func(apps, schema_editor): | ||
# Check for each user if the staff badge should be displayed | ||
try: | ||
staff_perm = Permission.objects.get(codename='change_post') | ||
staffs = User.objects.filter( | ||
Q(groups__permissions=staff_perm) | | ||
Q(user_permissions=staff_perm) | | ||
Q(is_superuser=True) | ||
).distinct() | ||
Profile.objects.filter(user__in=staffs).update(show_staff_badge=True) | ||
except Permission.DoesNotExist: | ||
pass | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('member', '0008_remove_profile_sdz_tutorial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='profile', | ||
name='show_staff_badge', | ||
field=models.BooleanField(default=False, verbose_name='Afficher le badge staff'), | ||
), | ||
migrations.RunPython(forwards_func), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from django.test import TestCase | ||
|
||
from zds.utils.templatetags.profile import state | ||
from zds.member.factories import ProfileFactory | ||
|
||
|
||
class ProfileTest(TestCase): | ||
def test_staff_badge(self): | ||
user = ProfileFactory() | ||
|
||
self.assertEqual(None, state(user.user)) | ||
|
||
result = self.client.get( | ||
user.get_absolute_url(), | ||
follow=False | ||
) | ||
self.assertEqual(200, result.status_code) | ||
self.assertNotContains(result, 'Staff') | ||
|
||
# Make the user superuser to give him the staff perms | ||
user.user.is_superuser = True | ||
user.user.save() | ||
|
||
self.assertEqual('STAFF', state(user.user)) | ||
|
||
result = self.client.get( | ||
user.get_absolute_url(), | ||
follow=False | ||
) | ||
self.assertEqual(200, result.status_code) | ||
self.assertContains(result, 'Staff') |