Skip to content

Commit

Permalink
Merge pull request #495 from awf-dbca/migration-management-script
Browse files Browse the repository at this point in the history
Migration management script and other changes
  • Loading branch information
xzzy authored Dec 10, 2024
2 parents 70c6025 + add4ed8 commit 8d3e665
Show file tree
Hide file tree
Showing 19 changed files with 385 additions and 40 deletions.
2 changes: 2 additions & 0 deletions mooringlicensing/components/approvals/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1815,6 +1815,7 @@ def create_mooring_licence_application(self, request, *args, **kwargs):
waiting_list_allocation = self.get_object()
proposal_type = ProposalType.objects.get(code=PROPOSAL_TYPE_NEW)
selected_mooring_id = request.data.get("selected_mooring_id")
no_email_notifications = request.data.get("no_emails")
allocated_mooring = Mooring.objects.get(id=selected_mooring_id)

current_date = datetime.now(pytz.timezone(TIME_ZONE)).date()
Expand All @@ -1839,6 +1840,7 @@ def create_mooring_licence_application(self, request, *args, **kwargs):
allocated_mooring=allocated_mooring,
waiting_list_allocation=waiting_list_allocation,
date_invited=current_date,
no_email_notifications=no_email_notifications,
)
waiting_list_allocation.proposal_applicant.copy_self_to_proposal(new_proposal)
logger.info(f'Offering new Mooring Site Licence application: [{new_proposal}], which has been created from the waiting list allocation: [{waiting_list_allocation}].')
Expand Down
24 changes: 15 additions & 9 deletions mooringlicensing/components/proposals/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ def create(self, request, *args, **kwargs):
if is_internal(request):

applicant_system_id = request.data.get("applicant_system_id")
no_email_notifications = request.data.get("no_emails", False)
if not applicant_system_id:
raise serializers.ValidationError("no system user id provided")

Expand All @@ -749,9 +750,10 @@ def create(self, request, *args, **kwargs):
raise serializers.ValidationError("proposal type does not exist")

obj = AnnualAdmissionApplication.objects.create(
submitter=request.user.id,
proposal_type=proposal_type
)
submitter=request.user.id,
no_email_notifications=no_email_notifications,
proposal_type=proposal_type
)

logger.info(f'Annual Admission Application: [{obj}] has been created by the user: [{request.user}].')

Expand Down Expand Up @@ -821,6 +823,7 @@ def create(self, request, *args, **kwargs):
if is_internal(request):

applicant_system_id = request.data.get("applicant_system_id")
no_email_notifications = request.data.get("no_emails", False)
if not applicant_system_id:
raise serializers.ValidationError("no system user id provided")

Expand All @@ -835,9 +838,10 @@ def create(self, request, *args, **kwargs):
raise serializers.ValidationError("proposal type does not exist")

obj = AuthorisedUserApplication.objects.create(
submitter=request.user.id,
proposal_type=proposal_type
)
submitter=request.user.id,
no_email_notifications=no_email_notifications,
proposal_type=proposal_type
)
logger.info(f'Authorised User Permit Application: [{obj}] has been created by the user: [{request.user}].')
obj.log_user_action(f'Authorised User Permit Application: {obj.lodgement_number} has been created.', request)

Expand Down Expand Up @@ -926,6 +930,7 @@ def create(self, request, *args, **kwargs):
if is_internal(request):

applicant_system_id = request.data.get("applicant_system_id")
no_email_notifications = request.data.get("no_emails", False)
if not applicant_system_id:
raise serializers.ValidationError("no system user id provided")

Expand All @@ -947,9 +952,10 @@ def create(self, request, *args, **kwargs):
raise serializers.ValidationError("user not permitted to create WLA at this time")

obj = WaitingListApplication.objects.create(
submitter=request.user.id,
proposal_type=proposal_type
)
submitter=request.user.id,
no_email_notifications=no_email_notifications,
proposal_type=proposal_type
)

logger.info(f'Waiting List Application: [{obj}] has been created by the user: [{request.user}].')
obj.log_user_action(f'Waiting List Application: {obj.lodgement_number} has been created.', request)
Expand Down
93 changes: 90 additions & 3 deletions mooringlicensing/components/proposals/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def _log_proposal_email(email_message, proposal, sender=None, file_bytes=None, f

def send_confirmation_email_upon_submit(request, proposal, payment_made, attachments=[]):
# 1 a and b
if proposal.no_email_notifications:
return

if payment_made:
subject='Submission received: Rottnest Island boating application {}'.format(proposal.lodgement_number)
else:
Expand Down Expand Up @@ -126,6 +129,9 @@ def send_confirmation_email_upon_submit(request, proposal, payment_made, attachm

def send_notification_email_upon_submit_to_assessor(request, proposal, attachments=[]):
# 2
if proposal.no_email_notifications:
return

email = TemplateEmailBase(
subject='Assessment required: a new application submission is awaiting assessment',
html_template='mooringlicensing/emails_2/email_2.html',
Expand Down Expand Up @@ -158,6 +164,9 @@ def send_notification_email_upon_submit_to_assessor(request, proposal, attachmen

def send_approver_approve_decline_email_notification(request, proposal):
# 3
if proposal.no_email_notifications:
return

email = TemplateEmailBase(
subject='Approval required: an assessed application is awaiting approval or decline',
html_template='mooringlicensing/emails_2/email_3.html',
Expand All @@ -182,6 +191,9 @@ def send_approver_approve_decline_email_notification(request, proposal):

def send_amendment_email_notification(amendment_request, request, proposal):
# 5
if proposal.no_email_notifications:
return

email = TemplateEmailBase(
subject='Amendment required: Rottnest Island boating application {}'.format(proposal.lodgement_number),
html_template='mooringlicensing/emails_2/email_5.html',
Expand Down Expand Up @@ -212,6 +224,9 @@ def send_amendment_email_notification(amendment_request, request, proposal):

def send_create_mooring_licence_application_email_notification(request, waiting_list_allocation, mooring_licence_application):
# 6
if mooring_licence_application.no_email_notifications:
return

allocated_mooring = mooring_licence_application.allocated_mooring
email = TemplateEmailBase(
subject='Offer for Mooring Site Licence {} - Rottnest Island Authority'.format(allocated_mooring.name),
Expand Down Expand Up @@ -263,6 +278,9 @@ def send_create_mooring_licence_application_email_notification(request, waiting_

def send_documents_upload_for_mooring_licence_application_email(request, proposal):
# 7
if proposal.no_email_notifications:
return

allocated_mooring = proposal.allocated_mooring
email = TemplateEmailBase(
subject='Additional documents required: Application for mooring site licence {} - Rottnest Island Authority'.format(allocated_mooring.name),
Expand Down Expand Up @@ -298,7 +316,7 @@ def send_documents_upload_for_mooring_licence_application_email(request, proposa
return msg


def send_comppliance_due_date_notification(approval, compliance,):
def send_compliance_due_date_notification(approval, compliance,):
# 8
email = TemplateEmailBase(
subject='Due: Compliance requirement for permit or licence - Deadline {} - Rottnest Island Authority'.format(compliance.due_date),
Expand Down Expand Up @@ -328,7 +346,7 @@ def send_comppliance_due_date_notification(approval, compliance,):
return msg


def send_comliance_overdue_notification(request, approval, compliance,):
def send_compliance_overdue_notification(request, approval, compliance,):
# 9
email = TemplateEmailBase(
subject='OVERDUE: Compliance requirement for permit or licence - Rottnest Island Authority',
Expand Down Expand Up @@ -363,6 +381,8 @@ def send_comliance_overdue_notification(request, approval, compliance,):
def send_invitee_reminder_email(approval, due_date, request=None):
# 11
proposal = approval.current_proposal
if proposal.no_email_notifications:
return
allocated_mooring = proposal.allocated_mooring
email = TemplateEmailBase(
subject='REMINDER : Your Offer for mooring site licence {} is about to lapse - Rottnest Island Authority'.format(allocated_mooring.name),
Expand Down Expand Up @@ -392,6 +412,8 @@ def send_invitee_reminder_email(approval, due_date, request=None):
_log_user_email(msg, approval.applicant_obj, proposal.applicant_obj, sender=sender_user)

def send_expire_application_email(proposal, due_date,):
if proposal.no_email_notifications:
return

html_template = 'mooringlicensing/emails_2/application_expire_notification.html'
txt_template = 'mooringlicensing/emails_2/application_expire_notification.txt'
Expand Down Expand Up @@ -423,6 +445,8 @@ def send_expire_application_email(proposal, due_date,):
return msg

def send_expire_notification_to_assessor(proposal, due_date):
if proposal.no_email_notifications:
return
email = TemplateEmailBase(
subject='Expired application - not paid on time',
html_template='mooringlicensing/emails_2/assessor_expiry_notification.html',
Expand All @@ -449,7 +473,8 @@ def send_expire_notification_to_assessor(proposal, due_date):
return msg

def send_payment_reminder_email(proposal, request=None):

if proposal.no_email_notifications:
return
email = TemplateEmailBase(
subject='Payment reminder: Application {} - Rottnest Island Authority'.format(proposal.lodgement_number),
html_template='mooringlicensing/emails_2/application_payment_reminder.html',
Expand Down Expand Up @@ -484,6 +509,10 @@ def send_payment_reminder_email(proposal, request=None):
def send_expire_mooring_licence_application_email(proposal, reason, due_date,):
# 12 email to mooring licence applicant when mooring licence application is not submitted within configurable
# number of days after being invited to apply for a mooring licence

if proposal.no_email_notifications:
return

allocated_mooring = proposal.allocated_mooring
html_template = 'mooringlicensing/emails_2/email_12.html'
txt_template = 'mooringlicensing/emails_2/email_12.txt'
Expand Down Expand Up @@ -519,6 +548,10 @@ def send_expire_mooring_licence_by_no_documents_email(proposal, reason, due_date
# 13
# Expire mooring licence application if additional documents are not submitted within a configurable number of days
# from the initial submit of the mooring licence application and email to inform the applicant

if proposal.no_email_notifications:
return

html_template = 'mooringlicensing/emails_2/email_13.html'
txt_template = 'mooringlicensing/emails_2/email_13.txt'
allocated_mooring = proposal.allocated_mooring
Expand Down Expand Up @@ -553,6 +586,10 @@ def send_expire_mla_notification_to_assessor(proposal, reason, due_date):
# 14
# email to assessor group when invite to apply for a mooring licence is expired, either because mooring licence is not submitted or additional documents are not submitted
# (internal)

if proposal.no_email_notifications:
return

email = TemplateEmailBase(
subject='Expired mooring site licence application - not submitted on time',
html_template='mooringlicensing/emails_2/email_14.html',
Expand Down Expand Up @@ -582,6 +619,10 @@ def send_expire_mla_notification_to_assessor(proposal, reason, due_date):


def send_endorser_reminder_email(proposal, request=None):

if proposal.no_email_notifications:
return

allocated_mooring = proposal.allocated_mooring
# 15
# email to authorised user application endorser if application is not endorsed or declined within configurable number of days
Expand Down Expand Up @@ -686,6 +727,10 @@ def send_approval_renewal_email_notification(approval):
def send_application_approved_or_declined_email(proposal, decision, request, stickers_to_be_returned=[]):
# 17 --- 25
# email to applicant when application is issued or declined (waiting list allocation application)

if proposal.no_email_notifications:
return

from mooringlicensing.components.proposals.models import WaitingListApplication, AnnualAdmissionApplication, AuthorisedUserApplication, MooringLicenceApplication

if proposal.application_type.code == WaitingListApplication.code:
Expand Down Expand Up @@ -733,6 +778,9 @@ def send_application_approved_or_declined_email(proposal, decision, request, sti
def send_wla_approved_or_declined_email(proposal, decision, request):
# 17 a and b
# email to applicant when application is issued or declined (waiting list allocation application)
if proposal.no_email_notifications:
return

all_ccs = []
all_bccs = []

Expand Down Expand Up @@ -796,6 +844,9 @@ def send_aaa_approved_or_declined_email(proposal, decision, request, stickers_to
# email to applicant when application is issued or declined (annual admission application, new and renewal)
# 19 a and b amendment, approval/decline
# email to applicant when application is issued or declined (annual admission application, amendment)
if proposal.no_email_notifications:
return

all_ccs = []
all_bccs = []
attach_invoice = False
Expand Down Expand Up @@ -862,6 +913,8 @@ def send_aaa_approved_or_declined_email(proposal, decision, request, stickers_to
def send_aua_approved_or_declined_email_new_renewal(proposal, decision, request, stickers_to_be_returned):
# 20 AUA new/renewal, approval/decline
# email to applicant when application is issued or declined (authorised user application, new and renewal)
if proposal.no_email_notifications:
return

all_ccs = []
all_bccs = []
Expand Down Expand Up @@ -942,6 +995,9 @@ def send_aua_approved_or_declined_email_new_renewal(proposal, decision, request,
def send_aua_approved_or_declined_email_amendment_payment_not_required(proposal, decision, request, stickers_to_be_returned):
#21 a and b
# email to applicant when application is issued or declined (authorised user application, amendment where no payment is required)
if proposal.no_email_notifications:
return

all_ccs = []
all_bccs = []

Expand Down Expand Up @@ -1000,6 +1056,9 @@ def send_aua_approved_or_declined_email_amendment_payment_not_required(proposal,
def send_aua_approved_or_declined_email_amendment_payment_required(proposal, decision, request, stickers_to_be_returned):
#22
# email to applicant when application is issued or declined (authorised user application, amendment where payment is required)
if proposal.no_email_notifications:
return

all_ccs = []
all_bccs = []
attach_invoice = False
Expand Down Expand Up @@ -1124,6 +1183,9 @@ def get_attachments(attach_invoice, attach_licence_doc, proposal, attach_au_summ


def send_au_summary_to_ml_holder(mooring_licence, request, au_proposal):
if au_proposal.no_email_notifications:
return

subject = 'Authorised User Summary for {} - Rottnest Island Authority'.format(mooring_licence.mooring.name)
attachments = []

Expand Down Expand Up @@ -1164,6 +1226,9 @@ def send_au_summary_to_ml_holder(mooring_licence, request, au_proposal):
def send_mla_approved_or_declined_email_new_renewal(proposal, decision, request, stickers_to_be_returned):
# 23 ML new/renewal, approval/decline
# email to applicant when application is issued or declined (mooring licence application, new and renewal)
if proposal.no_email_notifications:
return

all_ccs = []
all_bccs = []
allocated_mooring = proposal.allocated_mooring
Expand Down Expand Up @@ -1246,6 +1311,9 @@ def send_mla_approved_or_declined_email_new_renewal(proposal, decision, request,
def send_mla_approved_or_declined_email_amendment_payment_not_required(proposal, decision, request, stickers_to_be_returned):
# 24 a and b ML amendment(no payment), approval/decline
# email to applicant when application is issued or declined (mooring licence application, amendment where no payment is required)
if proposal.no_email_notifications:
return

all_ccs = []
all_bccs = []
allocated_mooring = proposal.allocated_mooring
Expand Down Expand Up @@ -1307,6 +1375,9 @@ def send_mla_approved_or_declined_email_amendment_payment_not_required(proposal,
def send_mla_approved_or_declined_email_amendment_payment_required(proposal, decision, request, stickers_to_be_returned):
# 25 ML amendment(payment), approval/decline
# email to applicant when application is issued or declined (mooring licence application, amendment where payment is required)
if proposal.no_email_notifications:
return

all_ccs = []
all_bccs = []
subject = ''
Expand Down Expand Up @@ -1387,6 +1458,9 @@ def send_mla_approved_or_declined_email_amendment_payment_required(proposal, dec

def send_aua_declined_by_endorser_email(proposal, request):
# email to applicant when application is issued or declined (mooring licence application, amendment where payment is required)
if proposal.no_email_notifications:
return

all_ccs = []
all_bccs = []

Expand Down Expand Up @@ -1422,6 +1496,9 @@ def send_aua_declined_by_endorser_email(proposal, request):
return msg

def send_other_documents_submitted_notification_email(request, proposal):
if proposal.no_email_notifications:
return

email = TemplateEmailBase(
subject='Application: {} is ready for assessment. Other documents have been submitted.'.format(proposal.description),
html_template='mooringlicensing/emails/send_documents_submitted_for_mla.html',
Expand Down Expand Up @@ -1507,6 +1584,10 @@ def send_sticker_printing_batch_email(batches):
return msg

def send_endorsement_of_authorised_user_application_email(request, proposal):

if proposal.no_email_notifications:
return

email = TemplateEmailBase(
subject='Endorsement of Authorised user application',
html_template='mooringlicensing/emails/send_endorsement_of_aua.html',
Expand Down Expand Up @@ -1555,6 +1636,9 @@ def send_endorsement_of_authorised_user_application_email(request, proposal):
return msgs

def send_application_discarded_email(proposal, request):
if proposal.no_email_notifications:
return

email = TemplateEmailBase(
subject='An Application has been discarded.',
html_template='mooringlicensing/emails_2/application_discarded.html',
Expand All @@ -1577,6 +1661,9 @@ def send_application_discarded_email(proposal, request):
return msg

def send_proposal_approver_sendback_email_notification(request, proposal):
if proposal.no_email_notifications:
return

email = TemplateEmailBase(
subject='An Application has been sent back by approver.',
html_template='mooringlicensing/emails/send_approver_sendback_notification.html',
Expand Down
Loading

0 comments on commit 8d3e665

Please sign in to comment.