Skip to content

Commit

Permalink
Merge pull request #5379 from bcgov/dev-marshal-MD-2981
Browse files Browse the repository at this point in the history
2981 - add israwrequest to differentiate raw and ministry correspondence
  • Loading branch information
milosdes authored Aug 24, 2024
2 parents 287521a + b7f1832 commit 4a3515e
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export const editDraftCorrespondence = (

export const deleteDraftCorrespondence = (
correspondenceid,
israwrequest,
ministryId,
requestId,
dispatch,
Expand All @@ -177,7 +178,7 @@ export const deleteDraftCorrespondence = (

);
apiUrl = replaceUrl(apiUrl,"<rawrequestid>",requestId);
httpPOSTRequest(apiUrl,{})
httpPOSTRequest(apiUrl,{israwrequest: israwrequest})
.then((res) => {
if (res.data) {
if (callback) {
Expand All @@ -199,6 +200,7 @@ export const deleteDraftCorrespondence = (

export const deleteResponseCorrespondence = (
correspondenceid,
israwrequest,
ministryId,
requestId,
dispatch,
Expand All @@ -216,7 +218,7 @@ export const deleteResponseCorrespondence = (

);
apiUrl = replaceUrl(apiUrl,"<rawrequestid>",requestId);
httpPOSTRequest(apiUrl,{})
httpPOSTRequest(apiUrl,{israwrequest: israwrequest})
.then((res) => {
if (res.data) {
if (callback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ const CommunicationStructure = ({correspondence, currentIndex,
const { requestDetails, requestExtensions, responsePackagePdfStitchStatus, cfrFeeData } = templateVariableInfo
let variables = getTemplateVariables(requestDetails,requestExtensions, responsePackagePdfStitchStatus, cfrFeeData, template)
variables = variables.filter(variable => {
const includedVariables = ["{{firstName}}", "{{lastName}}"]
const includedVariables = ["{{firstName}}", "{{lastName}}", "{{address}}"]
return includedVariables.includes(variable.name)
})
for (let variable of variables) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export const ContactApplicant = ({
const [confirmationFor, setConfirmationFor] = useState("");
const [confirmationTitle, setConfirmationTitle] = useState("");
const [confirmationMessage, setConfirmationMessage] = useState("");
const [draftCorrespondence, setDraftCorrespondence] = useState <any> ({});
const [selectedCorrespondence, setSelectedCorrespondence] = useState <any> ({});
const [currentResponseDate, setCurrentResponseDate] = useState <any> ("");
const [extension, setExtension] = useState("");
Expand All @@ -114,7 +113,7 @@ export const ContactApplicant = ({
setEditMode(false);
setFiles([]);
setEditorValue("");
setDraftCorrespondence({});
setSelectedCorrespondence({});
setSelectedEmails([]);
setCurrentTemplate(0);

Expand All @@ -137,7 +136,7 @@ export const ContactApplicant = ({
setEditMode(false);
setFiles([]);
setEditorValue("");
setDraftCorrespondence({});
setSelectedCorrespondence({});
setCorrespondenceId(null);
setSelectedEmails([]);
setCurrentTemplate(0);
Expand All @@ -146,7 +145,7 @@ export const ContactApplicant = ({
const handleConfirmationClose = () => {
setConfirmationFor("");
setConfirmationMessage("");
setDraftCorrespondence({});
setSelectedCorrespondence({});
setOpenConfirmationModal(false);
}

Expand Down Expand Up @@ -409,6 +408,7 @@ export const ContactApplicant = ({
}
const templateId = currentTemplate ? templates[currentTemplate as keyof typeof templates].templateid : null;
const type = (templateId && [1, 2].includes(templateId)) ? "CFRFee" : "";
let israwrequest = selectedCorrespondence.israwrequest || false;
let data = {
templateid: currentTemplate ? templates[currentTemplate as keyof typeof templates].templateid : null,
correspondenceid:correspondenceId,
Expand All @@ -424,7 +424,8 @@ export const ContactApplicant = ({
"paymentExpiryDate": dueDateCalculation(new Date(), PAYMENT_EXPIRY_DAYS),
"axisRequestId": requestNumber
}],
assignedGroupEmail: requestDetails.assignedGroupEmail
assignedGroupEmail: requestDetails.assignedGroupEmail,
israwrequest: israwrequest
};
saveEmailCorrespondence(
data,
Expand Down Expand Up @@ -464,6 +465,7 @@ export const ContactApplicant = ({
}
const templateId = currentTemplate ? templates[currentTemplate as keyof typeof templates].templateid : null;
const type = (templateId && [1, 2].includes(templateId)) ? "CFRFee" : "";
let israwrequest = selectedCorrespondence.israwrequest || false;
let data = {
templateid: currentTemplate ? templates[currentTemplate as keyof typeof templates].templateid : null,
correspondencemessagejson: JSON.stringify({
Expand All @@ -473,7 +475,8 @@ export const ContactApplicant = ({
}),
foiministryrequest_id: ministryId,
attachments: attachments,
emails: selectedEmails
emails: selectedEmails,
israwrequest: israwrequest
};
saveDraftCorrespondence(
data,
Expand Down Expand Up @@ -503,6 +506,7 @@ export const ContactApplicant = ({
}
const templateId = currentTemplate ? templates[currentTemplate as keyof typeof templates].templateid : null;
const type = (templateId && [1, 2].includes(templateId)) ? "CFRFee" : "";
let israwrequest = selectedCorrespondence.israwrequest || false;
let data = {
templateid: currentTemplate ? templates[currentTemplate as keyof typeof templates].templateid : null,
correspondenceid:correspondenceId,
Expand All @@ -517,7 +521,8 @@ export const ContactApplicant = ({
attributes: [{
"paymentExpiryDate": dueDateCalculation(new Date(), PAYMENT_EXPIRY_DAYS),
"axisRequestId": requestNumber
}]
}],
israwrequest: israwrequest
};
saveEmailCorrespondence(
data,
Expand Down Expand Up @@ -561,8 +566,10 @@ export const ContactApplicant = ({
changeCorrespondenceFilter("log");
dispatch(fetchApplicantCorrespondence(requestId, ministryId));
}
let israwrequest = ministryId ? false : true;
let data = {
attachments: responseattachments
attachments: responseattachments,
israwrequest: israwrequest
};
saveCorrespondenceResponse(
data,
Expand Down Expand Up @@ -601,6 +608,7 @@ export const ContactApplicant = ({
const [correspondenceId, setCorrespondenceId] = useState(null);

const editDraft = async (i : any) => {
setSelectedCorrespondence(i);
setEditMode(true);
setShowEditor(true);
setEditorValue(i.text);
Expand All @@ -616,7 +624,7 @@ export const ContactApplicant = ({
};

const deleteDraft = (i : any) => {
setDraftCorrespondence(i);
setSelectedCorrespondence(i);
setOpenConfirmationModal(true);
setConfirmationFor("delete-draft")
setConfirmationTitle("Delete Draft")
Expand All @@ -625,8 +633,8 @@ export const ContactApplicant = ({


const deleteDraftAction = async () => {
if (draftCorrespondence) {
setCorrespondenceId(draftCorrespondence.applicantcorrespondenceid);
if (selectedCorrespondence) {
setCorrespondenceId(selectedCorrespondence.applicantcorrespondenceid);
setDisablePreview(true);
setPreviewModal(false);
let callback = (_res: string) => {
Expand All @@ -643,7 +651,7 @@ export const ContactApplicant = ({
});
dispatch(fetchApplicantCorrespondence(requestId, ministryId));
}
deleteDraftCorrespondence(draftCorrespondence.applicantcorrespondenceid,ministryId,requestId,
deleteDraftCorrespondence(selectedCorrespondence.applicantcorrespondenceid, selectedCorrespondence.israwrequest, ministryId,requestId,
dispatch,
callback,
(errorMessage: string) => {
Expand Down Expand Up @@ -693,7 +701,7 @@ export const ContactApplicant = ({
});
dispatch(fetchApplicantCorrespondence(requestId, ministryId));
}
deleteResponseCorrespondence(selectedCorrespondence.applicantcorrespondenceid,ministryId,requestId,
deleteResponseCorrespondence(selectedCorrespondence.applicantcorrespondenceid,selectedCorrespondence.israwrequest, ministryId,requestId,
dispatch,
callback,
(errorMessage: string) => {
Expand Down Expand Up @@ -735,6 +743,7 @@ export const ContactApplicant = ({
}
const templateId = currentTemplate ? templates[currentTemplate as keyof typeof templates].templateid : null;
const type = (templateId && [1, 2].includes(templateId)) ? "CFRFee" : "";
let israwrequest = selectedCorrespondence.israwrequest || false;
let data = {
correspondenceid:correspondenceId,
templateid: currentTemplate ? templates[currentTemplate as keyof typeof templates].templateid : null,
Expand All @@ -745,7 +754,8 @@ export const ContactApplicant = ({
}),
foiministryrequest_id: ministryId,
attachments: attachments,
emails: selectedEmails
emails: selectedEmails,
israwrequest: israwrequest
};
editDraftCorrespondence(
data,
Expand Down Expand Up @@ -773,7 +783,7 @@ export const ContactApplicant = ({

if (updateAttachment.filename !== newFilename) {
editCorrespondenceResponse(
{ filename: newFilename, correspondenceattachmentid: correspondenceAttachmentId, correspondenceid: correspondenceId },
{ filename: newFilename, correspondenceattachmentid: correspondenceAttachmentId, correspondenceid: correspondenceId, israwrequest: selectedCorrespondence.israwrequest },
ministryId,
requestId,
dispatch,
Expand All @@ -789,7 +799,7 @@ export const ContactApplicant = ({
const handleChangeResponseDate = (newDate: string) => {
setModal(false);
editCorrespondenceResponse(
{responsedate: newDate, correspondenceid: selectedCorrespondence.applicantcorrespondenceid},
{responsedate: newDate, correspondenceid: selectedCorrespondence.applicantcorrespondenceid, israwrequest: selectedCorrespondence.israwrequest},
ministryId,
requestId,
dispatch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def upgrade():
sa.Column('isdraft', sa.Boolean(), nullable=True),
sa.Column('isdeleted', sa.Boolean(), nullable=True),
sa.Column('isresponse', sa.Boolean(), nullable=True),
sa.Column('israwrequest', sa.Boolean(), nullable=True, server_default=sa.true()),

sa.ForeignKeyConstraint(['foirawrequest_id', 'foirawrequestversion_id'], ['FOIRawRequests.requestid', 'FOIRawRequests.version']),
sa.PrimaryKeyConstraint('applicantcorrespondenceid', 'version'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def getapplicantcorrespondencesrawrequests(cls, requestid):
try:
sql = """select distinct on (applicantcorrespondenceid) applicantcorrespondenceid, templateid , correspondencemessagejson , version,
created_at, createdby, sentcorrespondencemessage, parentapplicantcorrespondenceid, sentby, sent_at,
isdraft, isdeleted, isresponse, response_at
isdraft, isdeleted, isresponse, response_at, israwrequest
from "FOIApplicantCorrespondencesRawRequests" rawcorr
where foirawrequest_id = (
SELECT foirawrequestid FROM public."FOIRequests"
Expand All @@ -64,7 +64,7 @@ def getapplicantcorrespondencesrawrequests(cls, requestid):
"created_at": row["created_at"], "createdby": row["createdby"],
"sentcorrespondencemessage": row["sentcorrespondencemessage"], "parentapplicantcorrespondenceid": row["parentapplicantcorrespondenceid"],
"sent_at": row["sent_at"], "sentby": row["sentby"],
"isdraft": row["isdraft"], "isresponse": row["isresponse"], "response_at": row["response_at"]})
"isdraft": row["isdraft"], "isresponse": row["isresponse"], "response_at": row["response_at"], "israwrequest": row["israwrequest"]})
except Exception as ex:
logging.error(ex)
raise ex
Expand Down Expand Up @@ -144,5 +144,5 @@ def deleteapplicantcorrespondence(cls, rawrequestid, correspondenceid,userid)->D

class FOIApplicantCorrespondenceRawRequestSchema(ma.Schema):
class Meta:
fields = ('applicantcorrespondenceid', 'version', 'parentapplicantcorrespondenceid', 'templateid','correspondencemessagejson','foirawrequest_id','foirawrequestversion_id','created_at','createdby','attachments','sentcorrespondencemessage','sent_at','sentby', 'isdraft', 'isdeleted', 'isresponse', 'response_at')
fields = ('applicantcorrespondenceid', 'version', 'parentapplicantcorrespondenceid', 'templateid','correspondencemessagejson','foirawrequest_id','foirawrequestversion_id','created_at','createdby','attachments','sentcorrespondencemessage','sent_at','sentby', 'isdraft', 'isdeleted', 'isresponse', 'response_at', 'israwrequest')

Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,11 @@ class FOIFlowApplicantCorrespondenceDraft(Resource):
def post(requestid, ministryrequestid):
try:
requestjson = request.get_json()
correspondenceschemaobj = FOIApplicantCorrespondenceSchema().load(data=requestjson)
rawrequestid = requestservice().getrawrequestidbyfoirequestid(requestid)
if ministryrequestid != 'None':
correspondenceschemaobj = FOIApplicantCorrespondenceSchema().load(data=requestjson)
if ministryrequestid != 'None' or "israwrequest" in correspondenceschemaobj and correspondenceschemaobj["israwrequest"] == False:
result = applicantcorrespondenceservice().saveapplicantcorrespondencelog(rawrequestid, ministryrequestid, correspondenceschemaobj, AuthHelper.getuserid(), True)
elif ministryrequestid == 'None':
correspondenceschemaobj = FOIApplicantCorrespondenceSchema().load(data=requestjson)
elif ministryrequestid == 'None' or "israwrequest" in correspondenceschemaobj and correspondenceschemaobj["israwrequest"] == True:
result = applicantcorrespondenceservice().saveapplicantcorrespondencelogforrawrequest(rawrequestid, correspondenceschemaobj, AuthHelper.getuserid(), True)
if result.success == True:
return {'status': result.success, 'message':result.message,'id':result.identifier} , 200
Expand All @@ -135,7 +134,7 @@ def post(requestid, ministryrequestid):
requestjson = request.get_json()
rawrequestid = requestservice().getrawrequestidbyfoirequestid(requestid)
applicantcorrespondencelog = FOIApplicantCorrespondenceSchema().load(data=requestjson)
if ministryrequestid == 'None':
if ministryrequestid == 'None' or "israwrequest" in applicantcorrespondencelog and applicantcorrespondencelog["israwrequest"] == True:
result = applicantcorrespondenceservice().saveapplicantcorrespondencelogforrawrequest(rawrequestid, applicantcorrespondencelog, AuthHelper.getuserid(), True)
else:
result = applicantcorrespondenceservice().saveapplicantcorrespondencelog(rawrequestid, ministryrequestid, applicantcorrespondencelog, AuthHelper.getuserid(), True)
Expand All @@ -154,8 +153,9 @@ class FOIFlowApplicantCorrespondenceDraft(Resource):
@auth.require
def post(ministryrequestid, rawrequestid, correspondenceid):
try:
requestjson = request.get_json()
rawrequestidfromfoirequest = requestservice().getrawrequestidbyfoirequestid(rawrequestid)
if ministryrequestid == 'None':
if ministryrequestid == 'None' or "israwrequest" in requestjson and requestjson["israwrequest"] == True:
rawresult = applicantcorrespondenceservice().deleteapplicantcorrespondencelograwrequest(rawrequestidfromfoirequest, correspondenceid, AuthHelper.getuserid())
return {'status': rawresult.success, 'message':rawresult.message,'id':rawresult.identifier} , 200
else:
Expand Down Expand Up @@ -211,7 +211,7 @@ def post(ministryrequestid, rawrequestid):
requestjson = request.get_json()
rawrequestidfromfoirequest = requestservice().getrawrequestidbyfoirequestid(rawrequestid)
correspondenceemail = FOIApplicantCorrespondenceResponseSchema().load(data=requestjson)
if ministryrequestid == 'None':
if ministryrequestid == 'None' or 'israwrequest' in requestjson and requestjson['israwrequest'] == True:
result = applicantcorrespondenceservice().saveapplicantcorrespondencelogforrawrequest(rawrequestidfromfoirequest, correspondenceemail, AuthHelper.getuserid())
else:
result = applicantcorrespondenceservice().saveapplicantcorrespondencelog(rawrequestidfromfoirequest, ministryrequestid, correspondenceemail, AuthHelper.getuserid())
Expand All @@ -234,9 +234,9 @@ def post(ministryrequestid, rawrequestid):
rawrequestidfromfoirequest = requestservice().getrawrequestidbyfoirequestid(rawrequestid)
requestjson = request.get_json()
correspondenceemail = FOIApplicantCorrespondenceEditResponseSchema().load(data=requestjson)
if ministryrequestid == 'None':
if ministryrequestid == 'None' or 'israwrequest' in requestjson and requestjson['israwrequest'] == True:
result = applicantcorrespondenceservice().editapplicantcorrespondencelogforrawrequest(rawrequestidfromfoirequest, correspondenceemail, AuthHelper.getuserid())
elif ministryrequestid != 'None':
elif ministryrequestid != 'None' or 'israwrequest' in requestjson and requestjson['israwrequest'] == False:
result = applicantcorrespondenceservice().editapplicantcorrespondencelogforministry(ministryrequestid, correspondenceemail, AuthHelper.getuserid())

return {'status': result.success, 'message':result.message,'id':result.identifier} , 200
Expand All @@ -253,8 +253,9 @@ class FOIFlowApplicantCorrespondenceResponse(Resource):
@auth.require
def post(ministryrequestid, rawrequestid, correspondenceid):
try:
requestjson = request.get_json()
rawrequestidfromfoirequest = requestservice().getrawrequestidbyfoirequestid(rawrequestid)
if ministryrequestid == 'None':
if ministryrequestid == 'None' or 'israwrequest' in requestjson and requestjson['israwrequest'] == True:
rawresult = applicantcorrespondenceservice().deleteapplicantcorrespondencelograwrequest(rawrequestidfromfoirequest, correspondenceid, AuthHelper.getuserid())
return {'status': rawresult.success, 'message':rawresult.message,'id':rawresult.identifier} , 200
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Meta: # pylint: disable=too-few-public-methods
data_key="attributes",
required=False,
)
israwrequest = fields.Bool(data_key="israwrequest",required=False,allow_none=True)


class FOIApplicantCorrespondenceEmailSchema(Schema):
Expand Down
Loading

0 comments on commit 4a3515e

Please sign in to comment.