Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FOIMOD-2479] Add OIPC email templates and migration #5300

Merged
merged 16 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { any } from "prop-types";

export const renderTemplate = (template: string, content: string, params: Array<any>) => {
let newTemplate = template.replace("{{content}}", content);
return applyVariables(newTemplate, params);
Expand All @@ -18,15 +20,20 @@ export const getExtensiondetails = (requestExtensions:any, type: string) => {
if (recentExtension["extensiontype"] === "Public Body" && recentExtension["extensionstatus"] == "Approved") {
return [recentExtension["extendedduedays"], recentExtension["extendedduedate"], recentExtension["extensionreson"]]
} else if (recentExtension["extensiontype"] === "OIPC" && recentExtension["extensionstatus"] == "Approved") {
return [recentExtension["approvednoofdays"], recentExtension["extendedduedate"], recentExtension["extensionreson"]]
return [recentExtension["approvednoofdays"], recentExtension["extendedduedate"], recentExtension["extensionreson"], recentExtension["created_at"], recentExtension["extensionreasonid"], recentExtension["decisiondate"]
]
}
}
return ["","",""]
return ["","","","","",""]
}

export const getTemplateVariables = (requestDetails: any, requestExtensions:any, templateInfo: any) => {
let oipcExtension = getExtensiondetails(requestExtensions, "OIPC");
let pbExtension = getExtensiondetails(requestExtensions, "Public Body");

// Find the record that matches the criteria for already taken a time extension under section 10(1), excluding the most recent record
const filteredOutLatestExtensions = findLatestMatchingTimeExtension(requestExtensions, reasonsToCheck);

return [
{name: "{{axisRequestId}}", value: requestDetails.axisRequestId},
{name: "{{title}}", value: templateInfo?.label || ""},
Expand All @@ -43,6 +50,18 @@ export const getTemplateVariables = (requestDetails: any, requestExtensions:any,
{name: "{{pbExtensionDueDate}}", value: pbExtension[1]},
{name: "{{pbExtensionReason}}", value: pbExtension[2]},
{name: "{{pbExtensionBody}}", value: "public body"},
{name: "{{oipcExtensionDueDays}}", value: oipcExtension[0]},
{name: "{{oipcExtensionDueDates}}", value: oipcExtension[1]},
{name: "{{oipcExtensionReason}}", value: oipcExtension[2]},
{name: "{{oipcExtensionNotiDate}}", value: oipcExtension[5]},
{name: "{{oipcOriginalReceivedDate}}", value: requestDetails.receivedDate},
{name: "{{oipcOriginalDueDate}}", value: requestDetails.originalDueDate},
{name: "{{sectionID}}", value: mapSectionWithExtensionReasonId(oipcExtension[4])},
{name: "{{takenExtensionStatus}}", value: isAlreadyTakenTimeExtension(filteredOutLatestExtensions)},
{name: "{{filteredExtensionDate}}", value: filteredOutLatestExtensions ? filteredOutLatestExtensions.extendedduedate : ""},
{name: "{{filteredExtensionDueDays}}", value: filteredOutLatestExtensions ? filteredOutLatestExtensions.extendedduedays : ""},
{name: "{{oipcComplaintStatus}}", value: oipcComplaintCheck(requestDetails.oipcdetails)},

];

}
Expand All @@ -55,3 +74,44 @@ export const isTemplateDisabled = (currentCFRForm: any, template: any) => {
}
return false
}

// Function to map extension reason id to its textual representation
const mapSectionWithExtensionReasonId = (extensionReasonId: number) => {
switch (extensionReasonId) {
case 6:
return "10(1)(d)"; // 10(1)(d) = Applicant Consent
case 7:
return "10(1)(c)"; // 10(1)(c) = Consultation
case 8:
return "10(1)(a)"; // 10(1)(a) = Further detail from applicant required
case 9:
return "10(1)(b)"; // 10(1)(b) = Large Volume and/or Volume of Search
default:
return "";
}
};

// List of reasons to check already taken a time extension under section 10(1)
const reasonsToCheck = [
"OIPC - Applicant Consent",
"OIPC - Consultation",
"OIPC - Further Detail from Applicant Required",
"OIPC - Large Volume and/or Volume of Search"
];

// Find the record that matches the criteria for already taken a time extension under section 10(1), excluding the most recent record.
const findLatestMatchingTimeExtension = (requestExtensions: any[], reasonsToCheck: string[]): any | null => {
const foundObject = requestExtensions
.filter(extension => extension.extensiontype === "OIPC" && reasonsToCheck.includes(extension.extensionreson) && extension !== requestExtensions[0])
.find(extension => reasonsToCheck.includes(extension.extensionreson)) || null;

return foundObject;
};

// Function to check and return "Yes" or "No"
const isAlreadyTakenTimeExtension = (result: any | null): string => {
return result === null ? "No" : "Yes";
};

// Check if there are any OIPC details.
const oipcComplaintCheck = (oipcdetails: any): string => oipcdetails && oipcdetails.length > 0 ? "Yes" : "No";
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""empty message

Revision ID: 8487688c2e35
Revises: c3e447d3d94d
Create Date: 2024-06-20 17:16:09.447577

"""
from alembic import op
from datetime import datetime
import sqlalchemy as sa
from sqlalchemy.sql import column, table
from sqlalchemy.sql.sqltypes import Boolean, String,Text,Integer,DateTime


# revision identifiers, used by Alembic.
revision = '8487688c2e35'
down_revision = 'c3e447d3d94d'
branch_labels = None
depends_on = None


def upgrade():
applicant_correspondence_templates = table('ApplicantCorrespondenceTemplates',
column('name',String),
column('documenturipath',Text),
column('description',String),
column('active',Boolean),
column('display',Boolean),
column('version',Integer),
column('created_at',DateTime),
column('createdby',String),
)
op.bulk_insert(
applicant_correspondence_templates,
[{'name': 'OIPCAPPLICANTCONSENTEXTENSION',
'description': 'OIPC Applicant Consent Time Extension',
'active': True,
'display': True,
'version': 1,
'documenturipath': '/TEMPLATES/EMAILS/oipc_applicant_consent_time_extension.html',
'created_at': datetime.now(),
'createdby': 'system'},
{'name': 'OIPCFIRSTTIMEEXTENSION',
'description': 'OIPC Applicant First Time Extension',
'active': True,
'display': True,
'version': 1,
'documenturipath': '/TEMPLATES/EMAILS/oipc_first_time_extension.html',
'created_at': datetime.now(),
'createdby': 'system'},
{'name': 'OIPCSUBSEQUENTTIMEEXTENSION',
'description': 'OIPC Subsequent Time Extension',
'active': True,
'display': True,
'version': 1,
'documenturipath': '/TEMPLATES/EMAILS/oipc_subsequent_time_extension.html',
'created_at': datetime.now(),
'createdby': 'system'}]
)


def downgrade():
op.execute(
"""
DELETE FROM "ApplicantCorrespondenceTemplates"
WHERE name IN ('OIPCAPPLICANTCONSENTEXTENSION', 'OIPCFIRSTTIMEEXTENSION', 'OIPCSUBSEQUENTTIMEEXTENSION')
"""
)
Loading
Loading