def request_for_invitation(self, requestor: dict): """ A new user can ask for an invitation to join a prescriber organization. The list of members is sorted by: - admin - date joined and the first member of the list will be contacted. This feature is only available for prescribers but it should be common to every organization. """ to_user = self.user to = [to_user.email] invitation_url = "%s?%s" % ( reverse("invitations_views:invite_prescriber_with_org"), urlencode(requestor)) # requestor is not a User, get_full_name can't be used in template full_name = f"""{requestor.get("first_name")} {requestor.get("last_name")}""" context = { "to": to_user, "organization": self.organization, "requestor": requestor, "full_name": full_name, "email": requestor.get("email"), "invitation_url": get_absolute_url(invitation_url), } subject = "common/emails/request_for_invitation_subject.txt" body = "common/emails/request_for_invitation_body.txt" return get_email_message(to, context, subject, body)
def member_deactivation_email(self, user): """ Tell a user he is no longer a member of this organization. """ to = [user.email] context = {"structure": self} subject = "common/emails/member_deactivation_email_subject.txt" body = "common/emails/member_deactivation_email_body.txt" return get_email_message(to, context, subject, body)
def remove_admin_email(self, user): """ Tell a member he is no longer an administrator. """ to = [user.email] context = {"structure": self} subject = "common/emails/remove_admin_email_subject.txt" body = "common/emails/remove_admin_email_body.txt" return get_email_message(to, context, subject, body)
def email_manually_refuse_approval(self): if not self.accepted_by: raise RuntimeError( "Unable to determine the recipient email address.") to = [self.accepted_by.email] context = {"job_application": self} subject = "approvals/email/refuse_manually_subject.txt" body = "approvals/email/refuse_manually_body.txt" return get_email_message(to, context, subject, body)
def email_cancel(self, cancelled_by): to = [cancelled_by.email] bcc = [] if self.is_sent_by_proxy: bcc.append(self.sender.email) context = {"job_application": self} subject = "apply/email/cancel_subject.txt" body = "apply/email/cancel_body.txt" return get_email_message(to, context, subject, body, bcc=bcc)
def email_refuse(self): to = [self.job_seeker.email] bcc = [] if self.is_sent_by_proxy: bcc.append(self.sender.email) context = {"job_application": self} subject = "apply/email/refuse_subject.txt" body = "apply/email/refuse_body.txt" return get_email_message(to, context, subject, body, bcc=bcc)
def refused_prescriber_organization_email(self): """ Send an email to the user who asked for the validation of a new prescriber organization when refused """ to = [u.email for u in self.active_members] context = {"organization": self} subject = "prescribers/email/refused_prescriber_organization_email_subject.txt" body = "prescribers/email/refused_prescriber_organization_email_body.txt" return get_email_message(to, context, subject, body)
def new_signup_warning_email_to_existing_members(self, user): """ Send a warning fyi-only email to all existing users of the siae about a new user signup. """ to = [u.email for u in self.active_members] context = {"new_user": user, "siae": self} subject = "siaes/email/new_signup_warning_email_to_existing_members_subject.txt" body = "siaes/email/new_signup_warning_email_to_existing_members_body.txt" return get_email_message(to, context, subject, body)
def email_accepted_notif_sender(self): to = [self.sender.email] context = { "first_name": self.first_name, "last_name": self.last_name, "email": self.email, "establishment_name": self.institution.display_name, } subject = "invitations_views/email/accepted_notif_sender_subject.txt" body = "invitations_views/email/accepted_notif_establishment_sender_body.txt" return get_email_message(to, context, subject, body)
def must_validate_prescriber_organization_email(self): """ Send an email to the support: signup of a **newly created** prescriber organization, with unregistered/unchecked org => prescriber organization authorization must be validated """ to = [settings.ITOU_EMAIL_CONTACT] context = {"organization": self} subject = "prescribers/email/must_validate_prescriber_organization_email_subject.txt" body = "prescribers/email/must_validate_prescriber_organization_email_body.txt" return get_email_message(to, context, subject, body)
def organization_with_no_member_email(self, user): """ Send an email to the support: signup of an **exisiting** prescriber organization, without any member (hence not validated) => prescriber organization authorization must be validated """ to = [settings.ITOU_EMAIL_CONTACT] context = {"organization": self, "new_user": user} subject = "prescribers/email/organization_with_no_member_email_subject.txt" body = "prescribers/email/organization_with_no_member_email_body.txt" return get_email_message(to, context, subject, body)
def email_accept(self): to = [self.job_seeker.email] bcc = [] if self.is_sent_by_proxy: bcc.append(self.sender.email) context = { "job_application": self, "survey_link": settings.ITOU_EMAIL_PRESCRIBER_NEW_HIRING_LINK } subject = "apply/email/accept_subject.txt" body = "apply/email/accept_body.txt" return get_email_message(to, context, subject, body, bcc=bcc)
def email_accept_for_proxy(self): if not self.is_sent_by_proxy: raise RuntimeError("The job application was not sent by a proxy.") to = [self.sender.email] context = {"job_application": self} if self.sender_prescriber_organization: # Include the survey link for all prescribers's organizations. context[ "prescriber_survey_link"] = self.sender_prescriber_organization.accept_survey_url subject = "apply/email/accept_for_proxy_subject.txt" body = "apply/email/accept_for_proxy_body.txt" return get_email_message(to, context, subject, body)
def email_accepted_notif_siae_members(self): members = self.siae.members.exclude( email__in=[self.sender.email, self.email]) to = [member.email for member in members] context = { "first_name": self.first_name, "last_name": self.last_name, "email": self.email, "siae_name": self.siae.display_name, "sender": self.sender, } subject = "invitations_views/email/accepted_notif_establishment_members_subject.txt" body = "invitations_views/email/accepted_notif_establishment_members_body.txt" return get_email_message(to, context, subject, body)
def email_deliver_approval(self, accepted_by): if not accepted_by: raise RuntimeError( "Unable to determine the recipient email address.") if not self.approval: raise RuntimeError("No approval found for this job application.") to = [accepted_by.email] context = { "job_application": self, "siae_survey_link": self.to_siae.accept_survey_url } subject = "approvals/email/deliver_subject.txt" body = "approvals/email/deliver_body.txt" return get_email_message(to, context, subject, body)
def email_invitation(self): to = [self.email] context = { "acceptance_link": self.acceptance_link, "expiration_date": self.expiration_date, "email": self.email, "first_name": self.first_name, "last_name": self.last_name, "sender": self.sender, "establishment": self.institution, } subject = "invitations_views/email/invitation_establishment_subject.txt" body = "invitations_views/email/invitation_establishment_body.txt" return get_email_message(to, context, subject, body)
def email_accept_trigger_manual_approval(self, accepted_by): to = [settings.ITOU_EMAIL_CONTACT] context = { "job_application": self, "admin_manually_add_approval_url": reverse("admin:approvals_approval_manually_add_approval", args=[self.pk]), } if accepted_by: context["accepted_by"] = accepted_by subject = "apply/email/accept_trigger_approval_subject.txt" body = "apply/email/accept_trigger_approval_body.txt" return get_email_message(to, context, subject, body)
def new_signup_activation_email_to_official_contact(self, request): """ Send email to siae.auth_email with a magic link to continue signup. Request object is needed to build absolute URL for magic link in email body. See https://stackoverflow.com/questions/2345708/how-can-i-get-the-full-absolute-url-with-domain-in-django """ if not self.auth_email: raise RuntimeError("Siae cannot be signed up for, this should never happen.") to = [self.auth_email] signup_magic_link = request.build_absolute_uri(self.signup_magic_link) context = {"siae": self, "signup_magic_link": signup_magic_link} subject = "siaes/email/new_signup_activation_email_to_official_contact_subject.txt" body = "siaes/email/new_signup_activation_email_to_official_contact_body.txt" return get_email_message(to, context, subject, body)
def email_approval_number(self, accepted_by): if not accepted_by: raise RuntimeError( _("Unable to determine the recipient email address.")) if not self.approval: raise RuntimeError( _("No approval found for this job application.")) to = [accepted_by.email] context = { "job_application": self, "survey_link": settings.ITOU_EMAIL_APPROVAL_SURVEY_LINK } subject = "apply/email/approval_number_subject.txt" body = "apply/email/approval_number_body.txt" return get_email_message(to, context, subject, body)
def email_new_for_siae(self): to = self.get_siae_recipents_email_list() context = {"job_application": self} subject = "apply/email/new_for_siae_subject.txt" body = "apply/email/new_for_siae_body.txt" return get_email_message(to, context, subject, body)
def email_new_for_prescriber(self): to = [self.sender.email] context = {"job_application": self} subject = "apply/email/new_for_prescriber_subject.txt" body = "apply/email/new_for_prescriber_body.txt" return get_email_message(to, context, subject, body)
def email(self): to = self.recipients_emails context = {"job_application": self.job_application} subject = "apply/email/new_for_siae_subject.txt" body = "apply/email/new_for_siae_body.txt" return get_email_message(to, context, subject, body)
def email_new_for_job_seeker(self, base_url): to = [self.job_seeker.email] context = {"job_application": self, "base_url": base_url} subject = "apply/email/new_for_job_seeker_subject.txt" body = "apply/email/new_for_job_seeker_body.txt" return get_email_message(to, context, subject, body)
def email(self): to = [self.prolongation.validated_by.email] context = {"prolongation": self.prolongation} subject = "approvals/email/new_prolongation_for_prescriber_subject.txt" body = "approvals/email/new_prolongation_for_prescriber_body.txt" return get_email_message(to, context, subject, body)
def email_refuse_for_job_seeker(self): to = [self.job_seeker.email] context = {"job_application": self} subject = "apply/email/refuse_subject.txt" body = "apply/email/refuse_body_for_job_seeker.txt" return get_email_message(to, context, subject, body)