From d36d69238d4296b9efe6d3f068ed2693ea434aa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Wed, 22 Feb 2017 18:19:49 +0100 Subject: [PATCH 1/2] Add groups and permissions for BDS staff & members --- bds/migrations/0002_add_BDS_groups.py | 52 +++++++++++++++++++++++++++ bds/models.py | 8 +++++ 2 files changed, 60 insertions(+) create mode 100644 bds/migrations/0002_add_BDS_groups.py diff --git a/bds/migrations/0002_add_BDS_groups.py b/bds/migrations/0002_add_BDS_groups.py new file mode 100644 index 00000000..f0b4a75c --- /dev/null +++ b/bds/migrations/0002_add_BDS_groups.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib.auth.models import Group, Permission +from django.db import migrations + + +def create_groups(apps, schema_editor): + from django.contrib.auth.management import create_permissions + + apps.models_module = True + create_permissions(apps, verbosity=0) + apps.models_module = None + + memberp = Permission.objects.get( + codename="member", + content_type__app_label="bds" + ) + burop = Permission.objects.get( + codename="buro", + content_type__app_label="bds" + ) + + # Creates the groups for BDS members and staff + member = Group.objects.create(name="bds_members") + buro = Group.objects.create(name="bds_buro") + + # Associates the permissions to the respective groups + member.permissions = [memberp] + buro.permissions = [memberp, burop] + + +class Migration(migrations.Migration): + + dependencies = [ + ('bds', '0001_initial'), + ] + + operations = [ + migrations.AlterModelOptions( + name='bdsprofile', + options={ + 'permissions': [ + ('member', 'Is a BDS member'), + ('buro', 'Is part of the BDS staff') + ], + 'verbose_name': 'Profil BDS', + 'verbose_name_plural': 'Profils BDS' + }, + ), + migrations.RunPython(create_groups, migrations.RunPython.noop), + ] diff --git a/bds/models.py b/bds/models.py index ecfbb3db..da80dd77 100644 --- a/bds/models.py +++ b/bds/models.py @@ -55,3 +55,11 @@ class BdsProfile(models.Model): default='CASH', choices=PAYMENT_METHOD_CHOICES, max_length=6) + + class Meta: + verbose_name = "Profil BDS" + verbose_name_plural = "Profils BDS" + permissions = [ + ("member", "Is a BDS member"), + ("buro", "Is part of the BDS staff") + ] From c81b84978566c3b06135cc4719ab9d81304333e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Wed, 22 Feb 2017 18:21:23 +0100 Subject: [PATCH 2/2] Prevent conflicts in COF perm migration There may be a conflict during the migration cof 0009 if the permissions are referenced only by their codename. --- cof/migrations/0009_generic_profiles.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cof/migrations/0009_generic_profiles.py b/cof/migrations/0009_generic_profiles.py index 673202b8..a544ce74 100644 --- a/cof/migrations/0009_generic_profiles.py +++ b/cof/migrations/0009_generic_profiles.py @@ -30,8 +30,14 @@ def preserve_perms(apps, schema_editor): apps.models_module = None CofProfile = apps.get_model("cof", "CofProfile") - memberp = Permission.objects.get(codename='member') - burop = Permission.objects.get(codename='buro') + memberp = Permission.objects.get( + codename='member', + content_type__app_label="cof" + ) + burop = Permission.objects.get( + codename='buro', + content_type__app_label="cof" + ) # creates the groups for COF members and member = Group.objects.create(name='cof_members')