Skip to content

Commit

Permalink
Sending Email
Browse files Browse the repository at this point in the history
  • Loading branch information
Jocelyn Cabildo authored and Jocelyn Cabildo committed Jan 11, 2025
1 parent 29c38b9 commit a81a08a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,6 @@ def get(requestid, ministryrequestid):
except BusinessException:
return "Error happened while fetching applicant correspondence logs" , 500

# @staticmethod
# @TRACER.trace()
# @cross_origin(origins=allowedorigins())
# @auth.require
# @auth.hasusertype('iao')
# 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
# except BusinessException:
# return "Error happened while saving applicant correspondence log" , 500
@staticmethod
@TRACER.trace()
@cross_origin(origins=allowedorigins())
Expand All @@ -105,23 +91,12 @@ def post(requestid, ministryrequestid):
try:
requestjson = request.get_json()
applicantcorrespondencelog = FOIApplicantCorrespondenceSchema().load(data=requestjson)
result = applicantcorrespondenceservice().saveapplicantcorrespondencelog(requestid, ministryrequestid, applicantcorrespondencelog, AuthHelper.getuserid())
if cfrfeeservice().getactivepayment(requestid, ministryrequestid) != None:
requestservice().postfeeeventtoworkflow(requestid, ministryrequestid, "CANCELLED")
if result.success == True:
_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 {'status': result.success, 'message':result.message,'id':result.identifier} , 200
rawrequestid = requestservice().getrawrequestidbyfoirequestid(requestid)
result = communicationwrapperservice().send_email(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





@cors_preflight('POST,OPTIONS')
@API.route('/foiflow/applicantcorrespondence/draft/<requestid>/<ministryrequestid>')
class FOIFlowApplicantCorrespondenceDraft(Resource):
Expand Down
2 changes: 0 additions & 2 deletions request-management-api/request_api/resources/fee.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ class Payment(Resource):
def post(request_id: int):
try:
request_json = request.get_json()
print("request_id", request_id)
print("request_json", request_json)
fee_service: FeeService = FeeService(request_id=request_id, code=request_json['fee_code'])
pay_response = fee_service.init_payment(request_json)
return pay_response, 201
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,44 @@ def send_email(self,requestid, ministryrequestid, applicantcorrespondencelog):
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
isFee = self.__is_fee_processing(applicantcorrespondencelog["templateid"])
print("isFee", isFee)
if self.__is_fee_processing(applicantcorrespondencelog["templateid"]) == True:
return self.__handle_fee_email(requestid, ministryrequestid, applicantcorrespondencelog)
print("isFee2", isFee)
return self.__handle_fee_email(requestid, ministryrequestid, applicantcorrespondencelog, result)
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):
def __handle_fee_email(self,requestid, ministryrequestid, applicantcorrespondencelog, result):
if cfrfeeservice().getactivepayment(requestid, ministryrequestid) != 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())
print("isFee3")
return requestservice().postcorrespondenceeventtoworkflow(requestid, ministryrequestid, result.identifier, applicantcorrespondencelog['attributes'], applicantcorrespondencelog['templateid'])

# def __is_fee_processing(self, templateid):
# template = applicantcorrespondenceservice().gettemplatebyid(templateid)
# print("template10", template)
# return template and template.name in ['PAYONLINE', 'PAYOUTSTANDING']

# def __is_fee_processing(self, templateid):
# template = applicantcorrespondenceservice().getactivetemplatebyid(templateid)
# template2 = applicantcorrespondenceservice().gettemplatebyid(templateid).name
# print("template10", template)
# print("template12", template2)
# if template and hasattr(template, 'name') and template.name.upper() in ['PAYONLINE', 'PAYOUTSTANDING']:
# return True
# return False

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def _getserviceaccounttoken_(self):
def _getHeaders_(self, token):
"""Generate headers."""
if token is None:
token = self._getserviceaccounttoken_()
token = self._getserviceaccounttoken_();
return {
"Authorization": "Bearer " + token,
"Content-Type": "application/json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ async def generateunopenedreport(self):
alerts.append({"request": request, "rank": 2, "potentialmatches": alert.potentialmatches})
UnopenedReport.bulkinsert(alertdbrows)
alerts.sort(key=lambda a : a.get('potentialmatches', {'highscore': -1})['highscore'])
requestjson={"email": self.reportemail, "topic": "Unopened Report"}
senderservice().send(
subject="Intake Unopened Request Report: " + str(date.today()),
content=self.generateemailhtml(alerts),
_messageattachmentlist=[],
requestjson={"email": self.reportemail, "topic": "Unopened Report"}
emails=requestjson.get("email")
)
return alerts

Expand Down

0 comments on commit a81a08a

Please sign in to comment.