From 8165540c00c1cf975d6aa0749269576693c6c83f Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Thu, 14 Apr 2022 08:37:43 +0200 Subject: [PATCH] #146 Record-unshare with default * adds automatic unsharing with default-only users if entry is recorded --- konova/models/object.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/konova/models/object.py b/konova/models/object.py index f224b68c..59c68860 100644 --- a/konova/models/object.py +++ b/konova/models/object.py @@ -289,6 +289,8 @@ class RecordableObjectMixin(models.Model): from user.models import UserActionLogEntry if self.recorded: return None + + self.unshare_with_default_users() action = UserActionLogEntry.get_recorded_action(user) self.recorded = action self.save() @@ -608,6 +610,26 @@ class ShareableObjectMixin(models.Model): """ raise NotImplementedError("Must be implemented in subclasses!") + def unshare_with_default_users(self): + """ Removes all shared users from direct shared access which are only default group users + + Returns: + + """ + from konova.utils.user_checks import is_default_group_only + users = self.shared_users + cleaned_users = [] + default_users = [] + for user in users: + if not is_default_group_only(user): + cleaned_users.append(user) + else: + default_users.append(user) + self.share_with_user_list(cleaned_users) + + for user in default_users: + celery_send_mail_shared_access_removed.delay(self.identifier, self.title, user.id) + class GeoReferencedMixin(models.Model): geometry = models.ForeignKey("konova.Geometry", null=True, blank=True, on_delete=models.SET_NULL)