Skip to content

Commit

Permalink
TMP
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm committed Nov 14, 2023
1 parent 95c923a commit 520d00c
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 83 deletions.
2 changes: 1 addition & 1 deletion src/openforms/appointments/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def get_confirmation_mail_suffix(submission: Submission) -> str:
return ""

# if the previous appointment was not cancelled, it cannot be an update
# TODO: what to do when we did succesfully create a new appointment, but the old
# TODO: what to do when we did successfully create a new appointment, but the old
# one deletion failed? there are now two appointments open.
# submission.appointment_info.status == AppointmentDetailsStatus.success and
# submission.previous_submission.appointment_info.status == AppointmentDetailsStatus.success
Expand Down
3 changes: 0 additions & 3 deletions src/openforms/emails/confirmation_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@


def get_confirmation_email_templates(submission: "Submission") -> tuple[str, str]:
if not submission.form.send_confirmation_email:
raise SkipConfirmationEmail("Confirmation e-mail sending is disabled.")

with translation.override(submission.language_code):
config = GlobalConfiguration.get_solo()
assert isinstance(config, GlobalConfiguration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% if cosign_complete or waiting_on_cosign %}<h2 style="margin: 1em 0; font-size: 1.5em;">{% trans "Co-sign information" %}</h2>{% endif %}
{% if cosign_complete %}
<p>
{% blocktranslate trimmed %}This email is a confirmation that this form has been co-signed by {{ cosigner_email }} and can now be processed.{% endblocktranslate %}
{% blocktranslate trimmed %}This submission has been co-signed by {{ cosigner_email }}.{% endblocktranslate %}
</p>
{% elif waiting_on_cosign %}
<p>
Expand Down
3 changes: 0 additions & 3 deletions src/openforms/payments/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,3 @@ def update_submission_payment_status(submission_id: int):
if is_retrying:
raise
return

# if this properly executed, we can schedule "instant" confirmation e-mail delivery
send_confirmation_email.delay(submission_id)
40 changes: 40 additions & 0 deletions src/openforms/submissions/migrations/0003_auto_20231114_1000.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Django 3.2.23 on 2023-11-14 09:00

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("submissions", "0002_change_json_encoder"),
]

operations = [
migrations.AddField(
model_name="submission",
name="cosign_confirmation_email_sent",
field=models.BooleanField(
default=False,
help_text="Has the confirmation email been sent after the submission has successfully been cosigned?",
verbose_name="cosign confirmation email sent",
),
),
migrations.AddField(
model_name="submission",
name="cosign_request_email_sent",
field=models.BooleanField(
default=False,
help_text="Has the email to request a co-sign been sent?",
verbose_name="cosign request email sent",
),
),
migrations.AddField(
model_name="submission",
name="payment_complete_confirmation_email_sent",
field=models.BooleanField(
default=False,
help_text="Has the confirmation emails been sent after successful payment?",
verbose_name="payment complete confirmation email sent",
),
),
]
18 changes: 18 additions & 0 deletions src/openforms/submissions/models/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,31 @@ class Submission(models.Model):
default=False,
help_text=_("Indicates whether the submission has been cosigned."),
)
cosign_request_email_sent = models.BooleanField(
_("cosign request email sent"),
default=False,
help_text=_("Has the email to request a co-sign been sent?"),
)
cosign_confirmation_email_sent = models.BooleanField(
_("cosign confirmation email sent"),
default=False,
help_text=_(
"Has the confirmation email been sent after the submission has successfully been cosigned?"
),
)

confirmation_email_sent = models.BooleanField(
_("confirmation email sent"),
default=False,
help_text=_("Indicates whether the confirmation email has been sent."),
)

payment_complete_confirmation_email_sent = models.BooleanField(
_("payment complete confirmation email sent"),
default=False,
help_text=_("Has the confirmation emails been sent after successful payment?"),
)

privacy_policy_accepted = models.BooleanField(
_("privacy policy accepted"),
default=False,
Expand Down
58 changes: 58 additions & 0 deletions src/openforms/submissions/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,61 @@ def retry_processing_submissions():
logger.debug("Resend submission for registration '%s'", submission)
retry_chain = on_completion_retry(submission.id)
retry_chain.delay()


def on_post_submission_event(submission_id: int) -> None:
# this can run any time because they have been claimed earlier
cleanup_temporary_files_for.delay(submission_id)

# If the form involves appointments and no appointment has been scheduled yet, schedule it.
# Todo: deprecated => Not needed with the new appointment flow
register_appointment_task = maybe_register_appointment.si(submission_id)

# Perform any pre-registration task specified by the registration plugin. If no registration plugin is configured,
# just set a submission reference (if it hasn't already been set)
pre_registration_task = pre_registration.si(submission_id)

# Generate the submission report. Contains information about the payment and co-sign status.
generate_report_task = generate_submission_report.si(submission_id)

# Attempt registering submission
register_submission_task = register_submission.si(submission_id)

# Payment status update
# Todo: deprecated => Not needed with the new payment flow
payment_status_update_task = update_submission_payment_status.si(
submission_id
) # Todo: Add field to skip rerunning

# Send emails
schedule_emails_task = schedule_emails.si(submission_id)

# Hash attributes
hash_identifying_attributes_task = maybe_hash_identifying_attributes.si(
submission_id
)

actions_chain = chain(
register_appointment_task,
pre_registration_task,
generate_report_task,
register_submission_task,
payment_status_update_task,
schedule_emails_task,
hash_identifying_attributes_task,
)

async_result: AsyncResult = actions_chain.delay()

# TODO: Figure out what to do with this
# # obtain all the task IDs so we can check the state later
# task_ids = []
#
# node = async_result
# while node is not None:
# task_ids.append(node.id)
# node = node.parent
#
# # NOTE - this is "risky" since we're running outside of the transaction (this code
# # should run in transaction.on_commit)!
# Submission.objects.filter(id=submission_id).update(on_completion_task_ids=task_ids)
54 changes: 1 addition & 53 deletions src/openforms/submissions/tasks/co_sign.py
Original file line number Diff line number Diff line change
@@ -1,66 +1,14 @@
import logging

from django.conf import settings
from django.template.loader import get_template
from django.utils import translation
from django.utils.translation import gettext_lazy as _

from celery import chain

from openforms.celery import app
from openforms.config.models import GlobalConfiguration
from openforms.emails.utils import send_mail_html
from openforms.logging import logevent
from openforms.submissions.models import Submission

from .cleanup import * # noqa
from .emails import * # noqa
from .registration import * # noqa

logger = logging.getLogger(__name__)

__all__ = ["send_email_cosigner", "on_cosign"]


@app.task()
def send_email_cosigner(submission_id: int) -> None:
submission = Submission.objects.get(id=submission_id)

with translation.override(submission.language_code):
config = GlobalConfiguration.get_solo()

if not (recipient := submission.cosigner_email):
logger.warning(
"No co-signer email found in the form. Skipping co-sign email for submission %d.",
submission.id,
)
return

template = get_template("emails/cosign.html")
content = template.render(
{
"code": submission.public_registration_reference,
"form_name": submission.form.name,
"form_url": submission.cleaned_form_url,
"show_form_link": config.show_form_link_in_cosign_email,
}
)

try:
send_mail_html(
subject=_("Co-sign request for {form_name}").format(
form_name=submission.form.name
),
html_body=content,
from_email=settings.DEFAULT_FROM_EMAIL,
recipient_list=[recipient],
text_message=content,
)
except Exception:
logevent.cosigner_email_queuing_failure(submission)
raise

logevent.cosigner_email_queuing_success(submission)
__all__ = ["on_cosign"]


def on_cosign(submission_id: int) -> None:
Expand Down
Loading

0 comments on commit 520d00c

Please sign in to comment.