From 3b2ca10e292ca86ae5bf98ed39883d659d24be58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Wed, 27 Jun 2018 12:21:20 +0000 Subject: [PATCH] Fix #109: Remove misnamed rights --- .../0083_remove_duplicate_rights.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 machines/migrations/0083_remove_duplicate_rights.py diff --git a/machines/migrations/0083_remove_duplicate_rights.py b/machines/migrations/0083_remove_duplicate_rights.py new file mode 100644 index 00000000..05ad2938 --- /dev/null +++ b/machines/migrations/0083_remove_duplicate_rights.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations + +def remove_permission_alias(apps, schema_editor): + Permission = apps.get_model('auth', 'Permission') + for codename in ['add_alias', 'change_alias', 'delete_alias']: + # Retrieve the wrong permission + try: + to_remove = Permission.objects.get( + codename=codename, + content_type__model='domain' + ) + except Permission.DoesNotExist: + # The permission is missing so no problem + pass + else: + to_remove.delete() + + +def remove_permission_text(apps, schema_editor): + Permission = apps.get_model('auth', 'Permission') + for codename in ['add_text', 'change_text', 'delete_text']: + # Retrieve the wrong permission + try: + to_remove = Permission.objects.get( + codename=codename, + content_type__model='txt' + ) + except Permission.DoesNotExist: + # The permission is missing so no problem + pass + else: + to_remove.delete() + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0082_auto_20180525_2209'), + ] + + operations = [ + migrations.RunPython(remove_permission_text), + migrations.RunPython(remove_permission_alias), + ]