#146 Record-unshare with default

* adds automatic unsharing with default-only users if entry is recorded
This commit is contained in:
mpeltriaux 2022-04-14 08:37:43 +02:00
parent e029f8c61e
commit dd0b3c0680

View File

@ -289,6 +289,8 @@ class RecordableObjectMixin(models.Model):
from user.models import UserActionLogEntry from user.models import UserActionLogEntry
if self.recorded: if self.recorded:
return None return None
self.unshare_with_default_users()
action = UserActionLogEntry.get_recorded_action(user) action = UserActionLogEntry.get_recorded_action(user)
self.recorded = action self.recorded = action
self.save() self.save()
@ -608,6 +610,26 @@ class ShareableObjectMixin(models.Model):
""" """
raise NotImplementedError("Must be implemented in subclasses!") 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): class GeoReferencedMixin(models.Model):
geometry = models.ForeignKey("konova.Geometry", null=True, blank=True, on_delete=models.SET_NULL) geometry = models.ForeignKey("konova.Geometry", null=True, blank=True, on_delete=models.SET_NULL)