From 31ef78cec0cd2ba3ccc91c4bafd89831e73abe20 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 20 Jan 2022 17:10:43 +0100 Subject: External sources - limit access in admin, limit by profile --- ishtar_common/models_rest.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'ishtar_common/models_rest.py') diff --git a/ishtar_common/models_rest.py b/ishtar_common/models_rest.py index 18f6c4c3f..b0ed5cbd4 100644 --- a/ishtar_common/models_rest.py +++ b/ishtar_common/models_rest.py @@ -93,6 +93,7 @@ class ApiExternalSource(models.Model): url = models.URLField(verbose_name=_("URL")) name = models.CharField(verbose_name=_("Name"), max_length=200) key = models.CharField(_("Key"), max_length=40) + users = models.ManyToManyField("IshtarUser", blank=True) match_document = models.FileField( _("Match document"), blank=True, @@ -108,10 +109,22 @@ class ApiExternalSource(models.Model): class Meta: verbose_name = _("API - Search - External source") verbose_name_plural = _("API - Search - External sources") + ordering = ("name",) def __str__(self): return self.name + def save(self, force_insert=False, force_update=False, using=None, + update_fields=None): + super().save(force_insert, force_update, using, update_fields) + # remove external sources from profiles if not in user anymore + UserProfile = apps.get_model("ishtar_common", "UserProfile") + q = UserProfile.objects.filter(external_sources=self).exclude( + person__ishtaruser__in=list(self.users.all()) + ) + for profile in q.all(): + profile.external_sources.remove(self) + def update_matches(self, content): result = { "created": 0, -- cgit v1.2.3