summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2026-01-23 16:23:10 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2026-01-28 14:52:09 +0100
commit9bca2db98069a01bb2e991887993d578da6d6e62 (patch)
treeb4a1c9bd54ee397fcc4708e45d49f212967446c5
parentc9849f27ecf4073adfe319645e40c6e60ce385c5 (diff)
downloadIshtar-9bca2db98069a01bb2e991887993d578da6d6e62.tar.bz2
Ishtar-9bca2db98069a01bb2e991887993d578da6d6e62.zip
🐛 fix permission migration
-rw-r--r--ishtar_common/migrations/0274_import_gis_options.py25
-rw-r--r--ishtar_common/models_imports.py16
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"