|
6 | 6 | from django.conf import settings |
7 | 7 | from django.contrib.auth import get_user_model |
8 | 8 | from django.template.loader import render_to_string |
| 9 | +from django.urls import reverse |
9 | 10 | from django.utils.translation import gettext as _ |
10 | 11 |
|
11 | 12 | from hypha.apply.activity import tasks |
@@ -41,6 +42,7 @@ class EmailAdapter(AdapterBase): |
41 | 42 | messages = { |
42 | 43 | MESSAGES.NEW_SUBMISSION: "messages/email/submission_confirmation.html", |
43 | 44 | MESSAGES.DRAFT_SUBMISSION: "messages/email/submission_confirmation.html", |
| 45 | + MESSAGES.INVITE_COAPPLICANT: "handle_co_applicant_invite", |
44 | 46 | MESSAGES.COMMENT: "notify_comment", |
45 | 47 | MESSAGES.EDIT_SUBMISSION: "messages/email/submission_edit.html", |
46 | 48 | MESSAGES.TRANSITION: "handle_transition", |
@@ -87,6 +89,8 @@ def get_subject(self, message_type, source): |
87 | 89 | subject = _( |
88 | 90 | "Reminder: Application ready to review: {source.title_text_display}" |
89 | 91 | ).format(source=source) |
| 92 | + elif message_type == MESSAGES.INVITE_COAPPLICANT: |
| 93 | + subject = _("You are invited as a co-applicant") |
90 | 94 | elif message_type in [ |
91 | 95 | MESSAGES.SENT_TO_COMPLIANCE, |
92 | 96 | MESSAGES.APPROVE_PAF, |
@@ -164,6 +168,27 @@ def handle_transition(self, old_phase, source, **kwargs): |
164 | 168 | **kwargs, |
165 | 169 | ) |
166 | 170 |
|
| 171 | + def handle_co_applicant_invite(self, source, related, **kwargs): |
| 172 | + invited_user = User.objects.filter(email=related.invited_user_email).first() |
| 173 | + can_accept = True |
| 174 | + if invited_user and ( |
| 175 | + invited_user.is_apply_staff or invited_user.is_apply_staff_admin |
| 176 | + ): |
| 177 | + can_accept = False |
| 178 | + |
| 179 | + accept_link = reverse( |
| 180 | + "apply:submissions:accept_coapplicant_invite", |
| 181 | + kwargs={"pk": source.id, "token": related.token}, |
| 182 | + ) |
| 183 | + return self.render_message( |
| 184 | + "messages/email/invite_co_applicant.html", |
| 185 | + source=source, |
| 186 | + can_accept=can_accept, |
| 187 | + accept_link=accept_link, |
| 188 | + related=related, |
| 189 | + **kwargs, |
| 190 | + ) |
| 191 | + |
167 | 192 | def handle_batch_transition(self, transitions, sources, **kwargs): |
168 | 193 | submissions = sources |
169 | 194 | kwargs.pop("source") |
@@ -274,6 +299,10 @@ def recipients(self, message_type, source, user, **kwargs): |
274 | 299 | if not source.phase.permissions.can_view(source.user): |
275 | 300 | return [] |
276 | 301 |
|
| 302 | + if message_type == MESSAGES.INVITE_COAPPLICANT: |
| 303 | + related = kwargs.get("related", None) |
| 304 | + return [related.invited_user_email] |
| 305 | + |
277 | 306 | if message_type == MESSAGES.PARTNERS_UPDATED_PARTNER: |
278 | 307 | partners = kwargs["added"] |
279 | 308 | return [partner.email for partner in partners] |
|
0 commit comments