#101 Team mails
* adds mail templates for shared data actions * fixes bug where deleted compensations would be used for checking
This commit is contained in:
@@ -15,7 +15,10 @@ from django.db.models import QuerySet
|
||||
from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP, LANIS_ZOOM_LUT, LANIS_LINK_TEMPLATE
|
||||
from konova.tasks import celery_send_mail_shared_access_removed, celery_send_mail_shared_access_given, \
|
||||
celery_send_mail_shared_data_recorded, celery_send_mail_shared_data_unrecorded, \
|
||||
celery_send_mail_shared_data_deleted, celery_send_mail_shared_data_checked
|
||||
celery_send_mail_shared_data_deleted, celery_send_mail_shared_data_checked, \
|
||||
celery_send_mail_shared_access_given_team, celery_send_mail_shared_access_removed_team, \
|
||||
celery_send_mail_shared_data_checked_team, celery_send_mail_shared_data_deleted_team, \
|
||||
celery_send_mail_shared_data_unrecorded_team, celery_send_mail_shared_data_recorded_team
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.http import HttpRequest
|
||||
from django.utils.timezone import now
|
||||
@@ -130,6 +133,11 @@ class BaseObject(BaseResource):
|
||||
for user_id in shared_users:
|
||||
celery_send_mail_shared_data_deleted.delay(self.identifier, self.title, user_id)
|
||||
|
||||
# Send mail
|
||||
shared_teams = self.shared_teams.values_list("id", flat=True)
|
||||
for team_id in shared_teams:
|
||||
celery_send_mail_shared_data_deleted_team.delay(self.identifier, self.title, team_id)
|
||||
|
||||
self.save()
|
||||
|
||||
def mark_as_edited(self, performing_user, request: HttpRequest = None, edit_comment: str = None):
|
||||
@@ -258,10 +266,15 @@ class RecordableObjectMixin(models.Model):
|
||||
self.save()
|
||||
self.log.add(action)
|
||||
|
||||
shared_users = self.users.all().values_list("id", flat=True)
|
||||
shared_users = self.shared_users.values_list("id", flat=True)
|
||||
shared_teams = self.shared_teams.values_list("id", flat=True)
|
||||
|
||||
for user_id in shared_users:
|
||||
celery_send_mail_shared_data_unrecorded.delay(self.identifier, self.title, user_id)
|
||||
|
||||
for team_id in shared_teams:
|
||||
celery_send_mail_shared_data_unrecorded_team.delay(self.identifier, self.title, team_id)
|
||||
|
||||
return action
|
||||
|
||||
def set_recorded(self, user):
|
||||
@@ -281,10 +294,15 @@ class RecordableObjectMixin(models.Model):
|
||||
self.save()
|
||||
self.log.add(action)
|
||||
|
||||
shared_users = self.users.all().values_list("id", flat=True)
|
||||
shared_users = self.shared_users.values_list("id", flat=True)
|
||||
shared_teams = self.shared_teams.values_list("id", flat=True)
|
||||
|
||||
for user_id in shared_users:
|
||||
celery_send_mail_shared_data_recorded.delay(self.identifier, self.title, user_id)
|
||||
|
||||
for team_id in shared_teams:
|
||||
celery_send_mail_shared_data_recorded_team.delay(self.identifier, self.title, team_id)
|
||||
|
||||
return action
|
||||
|
||||
def unrecord(self, performing_user, request: HttpRequest = None):
|
||||
@@ -367,10 +385,15 @@ class CheckableObjectMixin(models.Model):
|
||||
self.save()
|
||||
|
||||
# Send mail
|
||||
shared_users = self.users.all().values_list("id", flat=True)
|
||||
shared_users = self.shared_users.values_list("id", flat=True)
|
||||
for user_id in shared_users:
|
||||
celery_send_mail_shared_data_checked.delay(self.identifier, self.title, user_id)
|
||||
|
||||
# Send mail
|
||||
shared_teams = self.shared_teams.values_list("id", flat=True)
|
||||
for team_id in shared_teams:
|
||||
celery_send_mail_shared_data_checked_team.delay(self.identifier, self.title, team_id)
|
||||
|
||||
self.log.add(action)
|
||||
return action
|
||||
|
||||
@@ -488,8 +511,8 @@ class ShareableObjectMixin(models.Model):
|
||||
"""
|
||||
self.users.set(user_list)
|
||||
|
||||
def update_sharing_user(self, form):
|
||||
""" Adds a new user with shared access to the object
|
||||
def _update_shared_teams(self, form):
|
||||
""" Updates shared access on the object for teams
|
||||
|
||||
Args:
|
||||
form (ShareModalForm): The form holding the data
|
||||
@@ -497,33 +520,46 @@ class ShareableObjectMixin(models.Model):
|
||||
Returns:
|
||||
|
||||
"""
|
||||
from user.models import User
|
||||
form_data = form.cleaned_data
|
||||
shared_teams = self.shared_teams
|
||||
|
||||
# Fetch selected teams and find out which user IDs are in removed teams -> mails need to be sent
|
||||
accessing_teams = form_data["teams"]
|
||||
removed_team_users = self.teams.all().exclude(
|
||||
removed_teams = shared_teams.exclude(
|
||||
id__in=accessing_teams
|
||||
).values_list("users__id", flat=True)
|
||||
accessing_team_users = User.objects.filter(
|
||||
id__in=accessing_teams.values_list("users", flat=True)
|
||||
)
|
||||
new_team_users = accessing_team_users.exclude(
|
||||
id__in=self.shared_users
|
||||
).values_list("id", flat=True)
|
||||
new_teams = accessing_teams.exclude(
|
||||
id__in=shared_teams
|
||||
).values_list("id", flat=True)
|
||||
|
||||
for team_id in new_teams:
|
||||
celery_send_mail_shared_access_given_team.delay(self.identifier, self.title, team_id)
|
||||
for team_id in removed_teams:
|
||||
celery_send_mail_shared_access_removed_team.delay(self.identifier, self.title, team_id)
|
||||
|
||||
self.share_with_team_list(accessing_teams)
|
||||
|
||||
def _update_shared_users(self, form):
|
||||
""" Updates shared access on the object for single users
|
||||
|
||||
Args:
|
||||
form (ShareModalForm): The form holding the data
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
form_data = form.cleaned_data
|
||||
shared_users = self.shared_users
|
||||
|
||||
# Fetch selected users
|
||||
accessing_users = form_data["users"]
|
||||
removed_users = self.users.all().exclude(
|
||||
removed_users = shared_users.exclude(
|
||||
id__in=accessing_users
|
||||
).values_list("id", flat=True)
|
||||
new_users = accessing_users.exclude(
|
||||
id__in=self.shared_users
|
||||
id__in=shared_users
|
||||
).values_list("id", flat=True)
|
||||
|
||||
new_users = new_users.union(new_team_users)
|
||||
removed_users = removed_users.union(removed_team_users)
|
||||
|
||||
# Send mails
|
||||
for user_id in removed_users:
|
||||
celery_send_mail_shared_access_removed.delay(self.identifier, self.title, user_id)
|
||||
@@ -532,7 +568,18 @@ class ShareableObjectMixin(models.Model):
|
||||
|
||||
# Set new shared users
|
||||
self.share_with_user_list(accessing_users)
|
||||
self.share_with_team_list(accessing_teams)
|
||||
|
||||
def update_shared_access(self, form):
|
||||
""" Updates shared access on the object
|
||||
|
||||
Args:
|
||||
form (ShareModalForm): The form holding the data
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
self._update_shared_teams(form)
|
||||
self._update_shared_users(form)
|
||||
|
||||
@property
|
||||
def shared_users(self) -> QuerySet:
|
||||
|
||||
Reference in New Issue
Block a user