From 9bca2db98069a01bb2e991887993d578da6d6e62 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 23 Jan 2026 16:23:10 +0100 Subject: 🐛 fix permission migration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0274_import_gis_options.py | 25 +++++++++++++++------- ishtar_common/models_imports.py | 16 +++++++------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/ishtar_common/migrations/0274_import_gis_options.py b/ishtar_common/migrations/0274_import_gis_options.py index b7e93030b..553f2fb83 100644 --- a/ishtar_common/migrations/0274_import_gis_options.py +++ b/ishtar_common/migrations/0274_import_gis_options.py @@ -1,25 +1,34 @@ # Generated by Django 4.2.19 on 2026-01-21 14:08 -from django.db import migrations, models -import django.db.models.deletion +from django.db import migrations +from django.utils.translation import gettext_lazy as _ def update_groups(apps, __): Permission = apps.get_model("auth", "Permission") Group = apps.get_model("auth", "Group") + ContentType = apps.get_model("contenttypes", "ContentType") + ct = ContentType.objects.get(app_label='ishtar_common', model='import') update = ( - ("Imports : lecture", "view_gis_import"), - ("Imports rattachés : lecture", "view_own_gis_import"), - ("Imports : ajout", "change_gis_import"), + ("Imports : lecture", "view_gis_import", _("Can export to QGIS")), + ("Imports rattachés : lecture", "view_own_gis_import", _("Can export own to QGIS")), + ("Imports : ajout", "change_gis_import", _("Can create import from QGIS")), ) - for gp_name, codename in update: + for gp_name, codename, p_name in update: gp = Group.objects.filter(name=gp_name) if gp.exists(): perm = Permission.objects.filter(codename=codename) if perm.exists(): - gp = gp.all()[0] perm = perm.all()[0] - gp.permissions.add(perm) + else: + perm = Permission.objects.create( + codename=codename, + name=p_name, + content_type=ct + ) + + gp = gp.all()[0] + gp.permissions.add(perm) class Migration(migrations.Migration): diff --git a/ishtar_common/models_imports.py b/ishtar_common/models_imports.py index 1c0bd4fa4..b456bfd59 100644 --- a/ishtar_common/models_imports.py +++ b/ishtar_common/models_imports.py @@ -2250,14 +2250,14 @@ class Import(BaseImport): verbose_name = _("Import - Import") verbose_name_plural = _("Import - Imports") permissions = ( - ("view_own_import", "Can view own Import"), - ("add_own_import", "Can add own Import"), - ("change_own_import", "Can change own Import"), - ("delete_own_import", "Can delete own Import"), - ("view_gis_import", "Can export to QGIS"), - ("view_own_gis_import", "Can export own to QGIS"), - ("change_gis_import", "Can import from QGIS"), - ("change_own_gis_import", "Can import own to QGIS"), + ("view_own_import", _("Can view own Import")), + ("add_own_import", _("Can add own Import")), + ("change_own_import", _("Can change own Import")), + ("delete_own_import", _("Can delete own Import")), + ("view_gis_import", _("Can export to QGIS")), + ("view_own_gis_import", _("Can export own to QGIS")), + ("change_gis_import", _("Can import from QGIS")), + ("change_own_gis_import", _("Can import own from QGIS")), ) ADMIN_SECTION = _("Imports") SLUG = "import" -- cgit v1.2.3