diff --git a/apps/account/models.py b/apps/account/models.py index 33a44569..76513e5e 100644 --- a/apps/account/models.py +++ b/apps/account/models.py @@ -431,6 +431,16 @@ class User(PhoneModelMixin, AbstractUser): template_name=settings.EXISTING_USER_FOR_ESTABLISHMENT_TEAM_TEMPLATE, context=context), get_template(settings.EXISTING_USER_FOR_ESTABLISHMENT_TEAM_TEMPLATE).render(context) + def establishment_team_role_revoked(self, country_code, username, subject, restaurant_name): + """Template to notify user that his/her establishment role is revoked""" + context = {'token': self.reset_password_token, + 'country_code': country_code, + 'restaurant_name': restaurant_name} + context.update(self.base_template(country_code, username, subject)) + return render_to_string( + template_name=settings.ESTABLISHMENT_TEAM_ROLE_REVOKED_TEMPLATE, + context=context), get_template(settings.ESTABLISHMENT_TEAM_ROLE_REVOKED_TEMPLATE).render(context) + def notify_password_changed_template(self, country_code, username, subject): """Get notification email template""" context = {'country_code': country_code} diff --git a/apps/account/tasks.py b/apps/account/tasks.py index a9e5ea0f..fbaae1ce 100644 --- a/apps/account/tasks.py +++ b/apps/account/tasks.py @@ -57,6 +57,17 @@ def send_team_invite_to_existing_user(user_id, country_code, user_role_id, resta emails=None) +@shared_task +def team_role_revoked(user_id, country_code, restaurant_name): + """Send email to establishment team member with role acceptance link""" + user = User.objects.get(id=user_id) + subject = _(f'Your GAULT&MILLAU privileges to manage {restaurant_name} have been revoked.') + message = user.establishment_team_role_revoked(country_code, user.username, subject, restaurant_name) + user.send_email(subject=subject, + message=message, + emails=None) + + @shared_task def confirm_new_email_address(user_id, country_code): """Send email to user new email.""" diff --git a/apps/establishment/views/back.py b/apps/establishment/views/back.py index 822d6f7b..ce032658 100644 --- a/apps/establishment/views/back.py +++ b/apps/establishment/views/back.py @@ -1,4 +1,5 @@ """Establishment app views.""" +from django.conf import settings from django.db import transaction from django.db.models.query_utils import Q from django.http import Http404 @@ -938,3 +939,12 @@ class TeamMemberDeleteView(generics.DestroyAPIView): def get_object(self): return UserRole.objects.get(role__role=Role.ESTABLISHMENT_ADMINISTRATOR, user_id=self.kwargs['user_id'], establishment_id=self.kwargs['establishment_id']) + + def perform_destroy(self, instance): + instance.delete() + from account.tasks import team_role_revoked + establishment = models.Establishment.objects.get(ok=self.kwargs['establishment_id']) + if settings.USE_CELERY: + team_role_revoked.delay(self.kwargs['user_id'], self.request.country_code, establishment.name) + else: + team_role_revoked(self.kwargs['user_id'], self.request.country_code, establishment.name) diff --git a/project/settings/base.py b/project/settings/base.py index 350de177..91e5ab20 100644 --- a/project/settings/base.py +++ b/project/settings/base.py @@ -455,6 +455,7 @@ PASSWORD_RESET_TIMEOUT_DAYS = 1 RESETTING_TOKEN_TEMPLATE = 'account/password_reset_email.html' NEW_USER_FOR_ESTABLISHMENT_TEAM_TEMPLATE = 'account/invite_est_team_new_user.html' EXISTING_USER_FOR_ESTABLISHMENT_TEAM_TEMPLATE = 'account/invite_est_team_existing_user.html' +ESTABLISHMENT_TEAM_ROLE_REVOKED_TEMPLATE = 'account/est_team_role_revoked.html' CHANGE_EMAIL_TEMPLATE = 'account/change_email.html' CONFIRM_EMAIL_TEMPLATE = 'authorization/confirm_email.html' NEWS_EMAIL_TEMPLATE = 'news/news_email.html' diff --git a/project/templates/account/est_team_role_revoked.html b/project/templates/account/est_team_role_revoked.html new file mode 100644 index 00000000..0a72d53f --- /dev/null +++ b/project/templates/account/est_team_role_revoked.html @@ -0,0 +1,76 @@ +{% load i18n %}{% autoescape off %} + + + + + + + + + + +
+ +
+ +
+
+
+
+
+ + +
+
+
+ {{ title }} +
+
+
+ {% blocktrans %}Hello, you are receiving this email because your admin privileges on {{ restaurant_name }} have been revoked by another administrator. +If you think this is a mistake, you should contact {{ contact_email }}.{% endblocktrans %} +
+
+ {% blocktrans %}The {{ site_name }} team{% endblocktrans %} +
+ +
+ Please contact {{ contact_email }} if you have any questions. +
+ +
+
+
+ + +{% endautoescape %} \ No newline at end of file