Skip to content

Commit

Permalink
Merge pull request #5529 from bcgov/test-marshal-merge-main-12.0
Browse files Browse the repository at this point in the history
Test marshal merge main 12.0
  • Loading branch information
jocelyncabildo-aot authored Jan 16, 2025
2 parents 9c95fea + 31655b0 commit eff442c
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ def getapplicantcorrespondencesrawrequests(cls, requestid):
created_at, createdby, sentcorrespondencemessage, parentapplicantcorrespondenceid, sentby, sent_at,
isdraft, isdeleted, isresponse, response_at, israwrequest
from "FOIApplicantCorrespondencesRawRequests" rawcorr
where foirawrequest_id = (
SELECT foirawrequestid FROM public."FOIRequests"
WHERE foirequestid = :requestid
ORDER BY foirequestid ASC, version DESC limit 1)
OR
where
foirawrequest_id = :requestid
order by applicantcorrespondenceid desc, version desc"""
rs = db.session.execute(text(sql), {'requestid': requestid})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ class FOIFlowApplicantCorrespondence(Resource):
@auth.hasusertype('iao')
def get(requestid, ministryrequestid):
try:
rawrequestid = requestservice().getrawrequestidbyfoirequestid(requestid)
if ministryrequestid == 'None':
rawrequestid = requestid
else:
rawrequestid = requestservice().getrawrequestidbyfoirequestid(requestid)
correspondencelogs = applicantcorrespondenceservice().getapplicantcorrespondencelogs(ministryrequestid, rawrequestid)
return json.dumps(correspondencelogs) , 200
except BusinessException:
Expand All @@ -90,13 +93,15 @@ def get(requestid, ministryrequestid):
def post(requestid, ministryrequestid):
try:
requestjson = request.get_json()
applicantcorrespondencelog = FOIApplicantCorrespondenceSchema().load(data=requestjson)
rawrequestid = requestservice().getrawrequestidbyfoirequestid(requestid)
result = communicationwrapperservice().send_email(rawrequestid, ministryrequestid, applicantcorrespondencelog)
return {'status': result.success, 'message':result.message,'id':result.identifier} , 200
applicantcorrespondencelog = FOIApplicantCorrespondenceSchema().load(data=requestjson)
if ministryrequestid == 'None':
rawrequestid = requestid
else:
rawrequestid = requestservice().getrawrequestidbyfoirequestid(requestid)
result = communicationwrapperservice().send_email(requestid, rawrequestid, ministryrequestid, applicantcorrespondencelog)
return {'status': result['success'], 'message': result['message'], 'id': result['identifier']}, 200
except BusinessException:
return "Error happened while saving applicant correspondence log" , 500

return "Error happened while saving applicant correspondence log", 500


@cors_preflight('POST,OPTIONS')
Expand All @@ -111,7 +116,10 @@ def post(requestid, ministryrequestid):
try:
requestjson = request.get_json()
correspondenceschemaobj = FOIApplicantCorrespondenceSchema().load(data=requestjson)
rawrequestid = requestservice().getrawrequestidbyfoirequestid(requestid)
if ministryrequestid == 'None':
rawrequestid = requestid
else:
rawrequestid = requestservice().getrawrequestidbyfoirequestid(requestid)
if ministryrequestid != 'None' or "israwrequest" in correspondenceschemaobj and correspondenceschemaobj["israwrequest"] == False:
result = applicantcorrespondenceservice().saveapplicantcorrespondencelog(rawrequestid, ministryrequestid, correspondenceschemaobj, AuthHelper.getuserid(), True)
elif ministryrequestid == 'None' or "israwrequest" in correspondenceschemaobj and correspondenceschemaobj["israwrequest"] == True:
Expand All @@ -132,7 +140,10 @@ class FOIFlowApplicantCorrespondenceDraft(Resource):
def post(requestid, ministryrequestid):
try:
requestjson = request.get_json()
rawrequestid = requestservice().getrawrequestidbyfoirequestid(requestid)
if ministryrequestid == 'None':
rawrequestid = requestid
else:
rawrequestid = requestservice().getrawrequestidbyfoirequestid(requestid)
applicantcorrespondencelog = FOIApplicantCorrespondenceSchema().load(data=requestjson)
if ministryrequestid == 'None' or "israwrequest" in applicantcorrespondencelog and applicantcorrespondencelog["israwrequest"] == True:
result = applicantcorrespondenceservice().saveapplicantcorrespondencelogforrawrequest(rawrequestid, applicantcorrespondencelog, AuthHelper.getuserid(), True)
Expand All @@ -154,12 +165,15 @@ class FOIFlowApplicantCorrespondenceDraft(Resource):
def post(ministryrequestid, rawrequestid, correspondenceid):
try:
requestjson = request.get_json()
rawrequestidfromfoirequest = requestservice().getrawrequestidbyfoirequestid(rawrequestid)
if ministryrequestid == 'None':
rawrequestidforrequest = rawrequestid
else:
rawrequestidforrequest = requestservice().getrawrequestidbyfoirequestid(rawrequestid)
if ministryrequestid == 'None' or "israwrequest" in requestjson and requestjson["israwrequest"] == True:
rawresult = applicantcorrespondenceservice().deleteapplicantcorrespondencelograwrequest(rawrequestidfromfoirequest, correspondenceid, AuthHelper.getuserid())
rawresult = applicantcorrespondenceservice().deleteapplicantcorrespondencelograwrequest(rawrequestidforrequest, correspondenceid, AuthHelper.getuserid())
return {'status': rawresult.success, 'message':rawresult.message,'id':rawresult.identifier} , 200
else:
rawresult = applicantcorrespondenceservice().deleteapplicantcorrespondencelograwrequest(rawrequestidfromfoirequest, correspondenceid, AuthHelper.getuserid())
rawresult = applicantcorrespondenceservice().deleteapplicantcorrespondencelograwrequest(rawrequestidforrequest, correspondenceid, AuthHelper.getuserid())
ministryresult = applicantcorrespondenceservice().deleteapplicantcorrespondencelogministry(ministryrequestid, correspondenceid, AuthHelper.getuserid())
if rawresult.success == True and ministryresult.success == True:
return {'status': ministryresult.success, 'message':ministryresult.message,'id':ministryresult.identifier} , 200
Expand All @@ -178,9 +192,12 @@ class FOIFlowApplicantCorrespondenceEmail(Resource):
def post(ministryrequestid, rawrequestid):
try:
requestjson = request.get_json()
rawrequestidfromfoirequest = requestservice().getrawrequestidbyfoirequestid(rawrequestid)
if ministryrequestid == 'None':
rawrequestidforrequest = rawrequestid
else:
rawrequestidforrequest = requestservice().getrawrequestidbyfoirequestid(rawrequestid)
correspondenceemail = FOIApplicantCorrespondenceEmailSchema().load(data=requestjson)
result = correspondenceemailservice().savecorrespondenceemail(ministryrequestid, rawrequestidfromfoirequest, correspondenceemail, AuthHelper.getuserid())
result = correspondenceemailservice().savecorrespondenceemail(ministryrequestid, rawrequestidforrequest, correspondenceemail, AuthHelper.getuserid())

return {'status': result.success, 'message':result.message,'id':result.identifier} , 200
except BusinessException:
Expand All @@ -192,8 +209,11 @@ def post(ministryrequestid, rawrequestid):
@auth.require
def get(ministryrequestid, rawrequestid):
try:
rawrequestidfromfoirequest = requestservice().getrawrequestidbyfoirequestid(rawrequestid)
correspondenceemails = correspondenceemailservice().getcorrespondenceemails(ministryrequestid, rawrequestidfromfoirequest)
if ministryrequestid == 'None':
rawrequestidforrequest = rawrequestid
else:
rawrequestidforrequest = requestservice().getrawrequestidbyfoirequestid(rawrequestid)
correspondenceemails = correspondenceemailservice().getcorrespondenceemails(ministryrequestid, rawrequestidforrequest)
return json.dumps(correspondenceemails) , 200
except BusinessException:
return "Unable to retrieve correspondence emails" , 500
Expand All @@ -209,12 +229,15 @@ class FOIFlowApplicantCorrespondenceResponse(Resource):
def post(ministryrequestid, rawrequestid):
try:
requestjson = request.get_json()
rawrequestidfromfoirequest = requestservice().getrawrequestidbyfoirequestid(rawrequestid)
if ministryrequestid == 'None':
rawrequestidforrequest = rawrequestid
else:
rawrequestidforrequest = requestservice().getrawrequestidbyfoirequestid(rawrequestid)
correspondenceemail = FOIApplicantCorrespondenceResponseSchema().load(data=requestjson)
if ministryrequestid == 'None' or 'israwrequest' in requestjson and requestjson['israwrequest'] == True:
result = applicantcorrespondenceservice().saveapplicantcorrespondencelogforrawrequest(rawrequestidfromfoirequest, correspondenceemail, AuthHelper.getuserid())
result = applicantcorrespondenceservice().saveapplicantcorrespondencelogforrawrequest(rawrequestidforrequest, correspondenceemail, AuthHelper.getuserid())
else:
result = applicantcorrespondenceservice().saveapplicantcorrespondencelog(rawrequestidfromfoirequest, ministryrequestid, correspondenceemail, AuthHelper.getuserid())
result = applicantcorrespondenceservice().saveapplicantcorrespondencelog(rawrequestidforrequest, ministryrequestid, correspondenceemail, AuthHelper.getuserid())

return {'status': result.success, 'message':result.message,'id':result.identifier} , 200
except BusinessException:
Expand All @@ -231,11 +254,14 @@ class FOIFlowApplicantCorrespondenceEditResponse(Resource):
@auth.require
def post(ministryrequestid, rawrequestid):
try:
rawrequestidfromfoirequest = requestservice().getrawrequestidbyfoirequestid(rawrequestid)
if ministryrequestid == 'None':
rawrequestidforrequest = rawrequestid
else:
rawrequestidforrequest = requestservice().getrawrequestidbyfoirequestid(rawrequestid)
requestjson = request.get_json()
correspondenceemail = FOIApplicantCorrespondenceEditResponseSchema().load(data=requestjson)
if ministryrequestid == 'None' or 'israwrequest' in requestjson and requestjson['israwrequest'] == True:
result = applicantcorrespondenceservice().editapplicantcorrespondencelogforrawrequest(rawrequestidfromfoirequest, correspondenceemail, AuthHelper.getuserid())
result = applicantcorrespondenceservice().editapplicantcorrespondencelogforrawrequest(rawrequestidforrequest, correspondenceemail, AuthHelper.getuserid())
elif ministryrequestid != 'None' or 'israwrequest' in requestjson and requestjson['israwrequest'] == False:
result = applicantcorrespondenceservice().editapplicantcorrespondencelogforministry(ministryrequestid, correspondenceemail, AuthHelper.getuserid())

Expand All @@ -254,12 +280,15 @@ class FOIFlowApplicantCorrespondenceResponse(Resource):
def post(ministryrequestid, rawrequestid, correspondenceid):
try:
requestjson = request.get_json()
rawrequestidfromfoirequest = requestservice().getrawrequestidbyfoirequestid(rawrequestid)
if ministryrequestid == 'None':
rawrequestidforrequest = rawrequestid
else:
rawrequestidforrequest = requestservice().getrawrequestidbyfoirequestid(rawrequestid)
if ministryrequestid == 'None' or 'israwrequest' in requestjson and requestjson['israwrequest'] == True:
rawresult = applicantcorrespondenceservice().deleteapplicantcorrespondencelograwrequest(rawrequestidfromfoirequest, correspondenceid, AuthHelper.getuserid())
rawresult = applicantcorrespondenceservice().deleteapplicantcorrespondencelograwrequest(rawrequestidforrequest, correspondenceid, AuthHelper.getuserid())
return {'status': rawresult.success, 'message':rawresult.message,'id':rawresult.identifier} , 200
else:
rawresult = applicantcorrespondenceservice().deleteapplicantcorrespondencelograwrequest(rawrequestidfromfoirequest, correspondenceid, AuthHelper.getuserid())
rawresult = applicantcorrespondenceservice().deleteapplicantcorrespondencelograwrequest(rawrequestidforrequest, correspondenceid, AuthHelper.getuserid())
ministryresult = applicantcorrespondenceservice().deleteapplicantcorrespondencelogministry(ministryrequestid, correspondenceid, AuthHelper.getuserid())
if rawresult.success == True and ministryresult.success == True:
return {'status': ministryresult.success, 'message':ministryresult.message,'id':ministryresult.identifier} , 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def gettemplatebyid(self, templateid):
""" Returns the active applicant correspondence templates
"""
return ApplicationCorrespondenceTemplate.get_template_by_id(templateid)



def getapplicantcorrespondencelogs(self,ministryrequestid, rawrequestid):
""" Returns the active applicant correspondence logs
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,44 @@

class communicationwrapperservice:
""" FOI communication wrapper service
"""

def send_email(self,requestid, ministryrequestid, applicantcorrespondencelog):

def send_email(self, requestid, rawrequestid, ministryrequestid, applicantcorrespondencelog):
# Save correspondence log based on request type
if ministryrequestid == 'None' or ministryrequestid is None or ("israwrequest" in applicantcorrespondencelog and applicantcorrespondencelog["israwrequest"]) is True:
result = applicantcorrespondenceservice().saveapplicantcorrespondencelogforrawrequest(requestid, applicantcorrespondencelog, AuthHelper.getuserid())
result = applicantcorrespondenceservice().saveapplicantcorrespondencelogforrawrequest(rawrequestid, applicantcorrespondencelog, AuthHelper.getuserid())
else:
result = applicantcorrespondenceservice().saveapplicantcorrespondencelog(requestid, ministryrequestid, applicantcorrespondencelog, AuthHelper.getuserid())

if result.success == True:
# raw requests should never be fee emails so they would only get handled by else statement
if self.__is_fee_processing(applicantcorrespondencelog["templateid"]) == True:
return self.__handle_fee_email(requestid, ministryrequestid, applicantcorrespondencelog)
# Handle fee processing templates
if self.__is_fee_processing(applicantcorrespondencelog["templateid"]):
return self.__handle_fee_email(requestid, ministryrequestid, result, applicantcorrespondencelog)
# Handle non-fee templates - Send email for non-fee templates with email recipients
else:
if "emails" in applicantcorrespondencelog and len(applicantcorrespondencelog["emails"]) > 0:
template = applicantcorrespondenceservice().gettemplatebyid(applicantcorrespondencelog["templateid"])
return communicationemailservice().send(template, applicantcorrespondencelog)
return result





def __handle_fee_email(self,requestid, ministryrequestid, applicantcorrespondencelog):
if cfrfeeservice().getactivepayment(requestid, ministryrequestid) != None:
def __handle_fee_email(self, requestid, ministryrequestid, result, applicantcorrespondencelog):
if cfrfeeservice().getactivepayment(requestid, ministryrequestid) is not None:
requestservice().postfeeeventtoworkflow(requestid, ministryrequestid, "CANCELLED")
_attributes = applicantcorrespondencelog["attributes"][0] if "attributes" in applicantcorrespondencelog else None
_paymentexpirydate = _attributes["paymentExpiryDate"] if _attributes is not None and "paymentExpiryDate" in _attributes else None
if _paymentexpirydate not in (None, ""):
paymentservice().createpayment(requestid, ministryrequestid, _attributes, AuthHelper.getuserid())
return requestservice().postcorrespondenceeventtoworkflow(requestid, ministryrequestid, result.identifier, applicantcorrespondencelog['attributes'], applicantcorrespondencelog['templateid'])
_attributes = applicantcorrespondencelog["attributes"][0] if "attributes" in applicantcorrespondencelog else None
_paymentexpirydate = _attributes["paymentExpiryDate"] if _attributes is not None and "paymentExpiryDate" in _attributes else None
if _paymentexpirydate not in (None, ""):
paymentservice().createpayment(requestid, ministryrequestid, _attributes, AuthHelper.getuserid())
requestservice().postcorrespondenceeventtoworkflow(requestid, ministryrequestid, result.identifier, applicantcorrespondencelog['attributes'], applicantcorrespondencelog['templateid'])
return {"success" : True, "message": "Sent successfully", "identifier": -1}


def __is_fee_processing(self, templateid):
if applicantcorrespondenceservice().gettemplatebyid(templateid) in ['PAYONLINE','PAYOUTSTANDING']:
if applicantcorrespondenceservice().gettemplatebyid(templateid).name in ['PAYONLINE','PAYOUTSTANDING']:
return True
return False

class CommuniationType(Enum):
"""Communication types."""
FEE_PROCESSING = 'FEE_PROCESSING'
GENERAL = 'GENERAL'
GENERAL = 'GENERAL'
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ def send(self, subject, content, _messageattachmentlist, emails, from_email = No
from_email = MAIL_FROM_ADDRESS

msg['From'] = from_email
msg['To'] = ",".join(emails)
if isinstance(emails, list):
msg['To'] = ",".join(emails)
else:
msg['To'] = emails
msg['Subject'] = subject
formattedContent, embeddedImages = embeddedimagehandler().formatembeddedimage(content)
part = MIMEText(formattedContent, "html")
Expand Down Expand Up @@ -79,10 +82,10 @@ def send(self, subject, content, _messageattachmentlist, emails, from_email = No
smtpobj.sendmail(msg['From'], msg['To'], msg.as_string())
smtpobj.quit()
logging.debug("End: Send email for request")
return DefaultMethodResult(True,'Sent successfully', -1)
return {"success" : True, "message": "Sent successfully", "identifier": -1}
except Exception as e:
logging.exception(e)
return DefaultMethodResult(False,'Unable to send', -1)
return {"success" : False, "message": "Unable to send", "identifier": -1}


def read_outbox_as_bytes(self, servicekey, requestjson):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def send(self, servicename, requestid, ministryrequestid, emailschema):
_messageattachmentlist = self.__get_attachments(ministryrequestid, emailschema, servicename)
self.__pre_send_correspondence_audit(requestid, ministryrequestid,emailschema, content, templateconfig().isnotreceipt(servicename), _messageattachmentlist)
subject = templateconfig().getsubject(servicename, requestjson)
return senderservice().send(subject, _messagepart, _messageattachmentlist, requestjson)
return senderservice().send(subject, _messagepart, _messageattachmentlist, requestjson.get("email"))
except Exception as ex:
logging.exception(ex)

Expand Down
Loading

0 comments on commit eff442c

Please sign in to comment.