From d829d11aec86a015d3898738ae9d73b5067bb865 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Fri, 9 May 2025 10:42:44 +0200 Subject: ✨ GIS API: get data sources list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/models_imports.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'ishtar_common/models_imports.py') diff --git a/ishtar_common/models_imports.py b/ishtar_common/models_imports.py index 63a5b92fc..33d793333 100644 --- a/ishtar_common/models_imports.py +++ b/ishtar_common/models_imports.py @@ -144,6 +144,7 @@ class ImporterModel(models.Model): IMPORT_TYPES = ( ("tab", _("Table")), ("gis", _("GIS")), + ("qgs", _("QGIS")), ) IMPORT_TYPES_DICT = dict(IMPORT_TYPES) @@ -222,6 +223,14 @@ class ImporterType(models.Model): verbose_name = _("Importer - Type") verbose_name_plural = _("Importer - Types") ordering = ("name",) + # own is defined by users + # change permission need view permission + permissions = ( + ("view_gis_importer", "Can export to QGIS"), + ("view_own_gis_importer", "Can export own to QGIS"), + ("change_gis_importer", "Can import from QGIS"), + ("change_own_gis_importer", "Can import own to QGIS"), + ) ADMIN_SECTION = _("Imports") def natural_key(self): @@ -230,10 +239,29 @@ class ImporterType(models.Model): def __str__(self): return self.name + def clean(self): + if self.type == "qgs" and not self.is_template: + raise ValidationError( + "QGIS importers should at least can be exported. Check the \"Can be " + "exported\" case.") + @classmethod def is_own(cls, ishtar_user): return bool(cls.objects.filter(users__pk=ishtar_user.pk).count()) + @classmethod + def q_qgis_importers(cls, ishtaruser): + """ + Return QGIS importer query + """ + # filter available according to permissions + q = cls.objects.filter(type="qgs", is_template=True, available=True) + if not ishtaruser.is_superuser and not ishtaruser.has_permission("change_gis_importer"): + if not ishtaruser.has_permission("change_own_gis_importer"): + return q.filter(pk__isnull=True) + q = q.filter(users__pk=ishtaruser.pk) + return q + @property def type_label(self): if self.type in IMPORT_TYPES_DICT: -- cgit v1.2.3