Merge branch 'Aufinal/bds_perms' into 'master'

Le groupe BDS a des permissions normales

Closes #263

See merge request klub-dev-ens/gestioCOF!444
This commit is contained in:
Martin Pepin 2020-08-29 12:24:35 +02:00
commit 0011cfe8f7
4 changed files with 27 additions and 14 deletions

View file

@ -27,6 +27,7 @@ adhérents ni des cotisations.
- Ajout d'un bouton pour supprimer un compte
- Le nombre d'adhérent⋅es est affiché sur la page d'accueil
- le groupe BDS a les bonnes permissions
### Site du COF

View file

@ -0,0 +1 @@
default_app_config = "bds.apps.BdsConfig"

View file

@ -1,5 +1,29 @@
from django import apps as global_apps
from django.apps import AppConfig
from django.db.models import Q
from django.db.models.signals import post_migrate
def bds_group_perms(app_config, apps=global_apps, **kwargs):
try:
Permission = apps.get_model("auth", "Permission")
Group = apps.get_model("auth", "Group")
group = Group.objects.get(name="Burô du BDS")
perms = Permission.objects.filter(
Q(content_type__app_label="bds")
| Q(content_type__app_label="auth") & Q(content_type__model="user")
)
group.permissions.set(perms)
group.save()
except (LookupError, Group.DoesNotExist):
return
class BdsConfig(AppConfig):
name = "bds"
verbose_name = "Gestion des adhérent·e·s du BDS"
def ready(self):
post_migrate.connect(bds_group_perms, sender=self)

View file

@ -1,24 +1,11 @@
# Generated by Django 2.2 on 2019-07-17 14:56
from django.contrib.auth.management import create_permissions
from django.db import migrations
from django.db.models import Q
def create_bds_buro_group(apps, schema_editor):
for app_config in apps.get_app_configs():
create_permissions(app_config, apps=apps, verbosity=0)
Group = apps.get_model("auth", "Group")
Permission = apps.get_model("auth", "Permission")
group, created = Group.objects.get_or_create(name="Burô du BDS")
if created:
perms = Permission.objects.filter(
Q(content_type__app_label="bds")
| Q(content_type__app_label="auth") & Q(content_type__model="user")
)
group.permissions.set(perms)
group.save()
Group.objects.get_or_create(name="Burô du BDS")
class Migration(migrations.Migration):