368_Mail_linking #370

Merged
mpeltriaux merged 3 commits from 368_Mail_linking into master 2023-12-11 13:42:51 +01:00
2 changed files with 49 additions and 33 deletions
Showing only changes of commit 11bbf7d9ec - Show all commits

View File

@ -116,14 +116,13 @@ class DeletableObjectMixin(models.Model):
if send_mail: if send_mail:
# Send mail # Send mail
shared_users = self.shared_users.values_list("id", flat=True) shared_users = self.shared_users.values_list("id", flat=True)
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
for user_id in shared_users: for user_id in shared_users:
celery_send_mail_shared_data_deleted.delay(self.identifier, self.title, user_id, municipals_names) celery_send_mail_shared_data_deleted.delay(self.identifier, self.title, user_id)
# Send mail # Send mail
shared_teams = self.shared_teams.values_list("id", flat=True) shared_teams = self.shared_teams.values_list("id", flat=True)
for team_id in shared_teams: for team_id in shared_teams:
celery_send_mail_shared_data_deleted_team.delay(self.id, self.__class__, team_id, municipals_names) celery_send_mail_shared_data_deleted_team.delay(self.id, self.__class__, team_id)
self.save() self.save()
@ -253,13 +252,12 @@ class RecordableObjectMixin(models.Model):
shared_users = self.shared_users.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) shared_teams = self.shared_teams.values_list("id", flat=True)
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
for user_id in shared_users: for user_id in shared_users:
celery_send_mail_shared_data_unrecorded.delay(self.id, self.__class__, user_id, municipals_names) celery_send_mail_shared_data_unrecorded.delay(self.id, self.__class__, user_id)
for team_id in shared_teams: for team_id in shared_teams:
celery_send_mail_shared_data_unrecorded_team.delay(self.id, self.__class__, team_id, municipals_names) celery_send_mail_shared_data_unrecorded_team.delay(self.id, self.__class__, team_id)
return action return action
@ -284,13 +282,12 @@ class RecordableObjectMixin(models.Model):
shared_users = self.shared_users.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) shared_teams = self.shared_teams.values_list("id", flat=True)
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
for user_id in shared_users: for user_id in shared_users:
celery_send_mail_shared_data_recorded.delay(self.id, self.__class__, user_id, municipals_names) celery_send_mail_shared_data_recorded.delay(self.id, self.__class__, user_id)
for team_id in shared_teams: for team_id in shared_teams:
celery_send_mail_shared_data_recorded_team.delay(self.id, self.__class__, team_id, municipals_names) celery_send_mail_shared_data_recorded_team.delay(self.id, self.__class__, team_id)
return action return action
@ -361,17 +358,15 @@ class CheckableObjectMixin(models.Model):
self.checked = action self.checked = action
self.save() self.save()
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
# Send mail # Send mail
shared_users = self.shared_users.values_list("id", flat=True) shared_users = self.shared_users.values_list("id", flat=True)
for user_id in shared_users: for user_id in shared_users:
celery_send_mail_shared_data_checked.delay(self.id, self.__class__, user_id, municipals_names) celery_send_mail_shared_data_checked.delay(self.id, self.__class__, user_id)
# Send mail # Send mail
shared_teams = self.shared_teams.values_list("id", flat=True) shared_teams = self.shared_teams.values_list("id", flat=True)
for team_id in shared_teams: for team_id in shared_teams:
celery_send_mail_shared_data_checked_team.delay(self.id, self.__class__, team_id, municipals_names) celery_send_mail_shared_data_checked_team.delay(self.id, self.__class__, team_id)
self.log.add(action) self.log.add(action)
return action return action
@ -554,11 +549,10 @@ class ShareableObjectMixin(models.Model):
id__in=shared_teams id__in=shared_teams
).values_list("id", flat=True) ).values_list("id", flat=True)
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
for team_id in new_teams: for team_id in new_teams:
celery_send_mail_shared_access_given_team.delay(self.id, self.__class__, team_id, municipals_names) celery_send_mail_shared_access_given_team.delay(self.id, self.__class__, team_id)
for team_id in removed_teams: for team_id in removed_teams:
celery_send_mail_shared_access_removed_team.delay(self.id, self.__class__, team_id, municipals_names) celery_send_mail_shared_access_removed_team.delay(self.id, self.__class__, team_id)
self.share_with_team_list(accessing_teams) self.share_with_team_list(accessing_teams)
@ -583,12 +577,11 @@ class ShareableObjectMixin(models.Model):
id__in=shared_users id__in=shared_users
).values_list("id", flat=True) ).values_list("id", flat=True)
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
# Send mails # Send mails
for user_id in removed_users: for user_id in removed_users:
celery_send_mail_shared_access_removed(self.id, self.__class__, user_id, municipals_names) celery_send_mail_shared_access_removed.delay(self.id, self.__class__, user_id)
for user_id in new_users: for user_id in new_users:
celery_send_mail_shared_access_given(self.id, self.__class__, user_id, municipals_names) celery_send_mail_shared_access_given.delay(self.id, self.__class__, user_id)
# Set new shared users # Set new shared users
self.share_with_user_list(accessing_users) self.share_with_user_list(accessing_users)
@ -650,9 +643,8 @@ class ShareableObjectMixin(models.Model):
default_users.append(user) default_users.append(user)
self.share_with_user_list(cleaned_users) self.share_with_user_list(cleaned_users)
municipals_names = list(self.geometry.get_underlying_municipals().values_list("name", flat=True))
for user in default_users: for user in default_users:
celery_send_mail_shared_access_removed.delay(self.identifier, self.title, user.id, municipals_names) celery_send_mail_shared_access_removed.delay(self.id, self.__class__, user.id)
class GeoReferencedMixin(models.Model): class GeoReferencedMixin(models.Model):

View File

@ -25,98 +25,122 @@ def celery_update_parcels(geometry_id: str, recheck: bool = True):
@shared_task @shared_task
def celery_send_mail_shared_access_removed(obj_id, obj_class, user_id=None, municipals_names=[]): def celery_send_mail_shared_access_removed(obj_id, obj_class, user_id=None):
from user.models import User from user.models import User
user = User.objects.get(id=user_id) user = User.objects.get(id=user_id)
obj = obj_class.objects.get(id=obj_id) obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
user.send_mail_shared_access_removed(obj, municipals_names) user.send_mail_shared_access_removed(obj, municipals_names)
@shared_task @shared_task
def celery_send_mail_shared_access_given(obj_id, obj_class, user_id=None, municipals_names=[]): def celery_send_mail_shared_access_given(obj_id, obj_class, user_id=None):
from user.models import User from user.models import User
user = User.objects.get(id=user_id) user = User.objects.get(id=user_id)
obj = obj_class.objects.get(id=obj_id) obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
user.send_mail_shared_access_given(obj, municipals_names) user.send_mail_shared_access_given(obj, municipals_names)
@shared_task @shared_task
def celery_send_mail_shared_access_removed_team(obj_id, obj_class, team_id=None, municipals_names=[]): def celery_send_mail_shared_access_removed_team(obj_id, obj_class, team_id=None):
from user.models import Team from user.models import Team
team = Team.objects.get(id=team_id) team = Team.objects.get(id=team_id)
obj = obj_class.objects.get(id=obj_id) obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
team.send_mail_shared_access_removed(obj, municipals_names) team.send_mail_shared_access_removed(obj, municipals_names)
@shared_task @shared_task
def celery_send_mail_shared_access_given_team(obj_id, obj_class, team_id=None, municipals_names=[]): def celery_send_mail_shared_access_given_team(obj_id, obj_class, team_id=None):
from user.models import Team from user.models import Team
team = Team.objects.get(id=team_id) team = Team.objects.get(id=team_id)
obj = obj_class.objects.get(id=obj_id) obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
team.send_mail_shared_access_given_team(obj, municipals_names) team.send_mail_shared_access_given_team(obj, municipals_names)
@shared_task @shared_task
def celery_send_mail_shared_data_recorded(obj_id, obj_class, user_id=None, municipals_names=[]): def celery_send_mail_shared_data_recorded(obj_id, obj_class, user_id=None):
from user.models import User from user.models import User
user = User.objects.get(id=user_id) user = User.objects.get(id=user_id)
obj = obj_class.objects.get(id=obj_id) obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
user.send_mail_shared_data_recorded(obj, municipals_names) user.send_mail_shared_data_recorded(obj, municipals_names)
@shared_task @shared_task
def celery_send_mail_shared_data_unrecorded(obj_id, obj_class, user_id=None, municipals_names=[]): def celery_send_mail_shared_data_unrecorded(obj_id, obj_class, user_id=None):
from user.models import User from user.models import User
user = User.objects.get(id=user_id) user = User.objects.get(id=user_id)
obj = obj_class.objects.get(id=obj_id) obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
user.send_mail_shared_data_unrecorded(obj, municipals_names) user.send_mail_shared_data_unrecorded(obj, municipals_names)
@shared_task @shared_task
def celery_send_mail_shared_data_recorded_team(obj_id, obj_class, team_id=None, municipals_names=[]): def celery_send_mail_shared_data_recorded_team(obj_id, obj_class, team_id=None):
from user.models import Team from user.models import Team
team = Team.objects.get(id=team_id) team = Team.objects.get(id=team_id)
obj = obj_class.objects.get(id=obj_id) obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
team.send_mail_shared_data_recorded(obj, municipals_names) team.send_mail_shared_data_recorded(obj, municipals_names)
@shared_task @shared_task
def celery_send_mail_shared_data_unrecorded_team(obj_id, obj_class, team_id=None, municipals_names=[]): def celery_send_mail_shared_data_unrecorded_team(obj_id, obj_class, team_id=None):
from user.models import Team from user.models import Team
team = Team.objects.get(id=team_id) team = Team.objects.get(id=team_id)
obj = obj_class.objects.get(id=obj_id) obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
team.send_mail_shared_data_unrecorded(obj, municipals_names) team.send_mail_shared_data_unrecorded(obj, municipals_names)
@shared_task @shared_task
def celery_send_mail_shared_data_deleted(obj_id, obj_class, user_id=None, municipals_names=[]): def celery_send_mail_shared_data_deleted(obj_id, obj_class, user_id=None):
from user.models import User from user.models import User
user = User.objects.get(id=user_id) user = User.objects.get(id=user_id)
obj = obj_class.objects.get(id=obj_id) obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
user.send_mail_shared_data_deleted(obj, municipals_names) user.send_mail_shared_data_deleted(obj, municipals_names)
@shared_task @shared_task
def celery_send_mail_shared_data_checked(obj_id, obj_class, user_id=None, municipals_names=[]): def celery_send_mail_shared_data_checked(obj_id, obj_class, user_id=None):
from user.models import User from user.models import User
user = User.objects.get(id=user_id) user = User.objects.get(id=user_id)
obj = obj_class.objects.get(id=obj_id) obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
user.send_mail_shared_data_checked(obj, municipals_names) user.send_mail_shared_data_checked(obj, municipals_names)
@shared_task @shared_task
def celery_send_mail_shared_data_deleted_team(obj_id, obj_class, team_id=None, municipals_names=[]): def celery_send_mail_shared_data_deleted_team(obj_id, obj_class, team_id=None):
from user.models import Team from user.models import Team
team = Team.objects.get(id=team_id) team = Team.objects.get(id=team_id)
obj = obj_class.objects.get(id=obj_id) obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
team.send_mail_shared_data_deleted(obj, municipals_names) team.send_mail_shared_data_deleted(obj, municipals_names)
@shared_task @shared_task
def celery_send_mail_shared_data_checked_team(obj_id, obj_class, team_id=None, municipals_names=[]): def celery_send_mail_shared_data_checked_team(obj_id, obj_class, team_id=None):
from user.models import Team from user.models import Team
team = Team.objects.get(id=team_id) team = Team.objects.get(id=team_id)
obj = obj_class.objects.get(id=obj_id) obj = obj_class.objects.get(id=obj_id)
municipals_names = list(obj.geometry.get_underlying_municipals().values_list("name", flat=True))
team.send_mail_shared_data_checked(obj, municipals_names) team.send_mail_shared_data_checked(obj, municipals_names)