Skip to content

Commit

Permalink
Merge pull request #5373 from bcgov/dev-marshal-MD-2981
Browse files Browse the repository at this point in the history
2981 - Use rawrequestid when entry in FOIRequest exists
  • Loading branch information
milosdes authored Aug 20, 2024
2 parents 2b54f1d + afaf39b commit 320c051
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export const ContactApplicant = ({
setFiles([]);
setEditorValue("");
setDraftCorrespondence({});
setCorrespondenceId(null);
setSelectedEmails([]);
setCurrentTemplate(0);
}
Expand Down Expand Up @@ -585,7 +586,7 @@ export const ContactApplicant = ({



const [correspondenceId, setCorrespondenceId] = useState(0);
const [correspondenceId, setCorrespondenceId] = useState(null);

const editDraft = async (i : any) => {
setEditMode(true);
Expand Down
15 changes: 15 additions & 0 deletions request-management-api/request_api/models/FOIRequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ def getworkflowinstance(cls,requestid)->DefaultMethodResult:
finally:
db.session.close()
return request_schema
@classmethod
def getrawrequestidbyfoirequestid(cls,requestid)->DefaultMethodResult:
try:
sql = """select fr.foirawrequestid, fr.foirequestid from "FOIRequests" fr
where fr.foirequestid=:requestid
order by fr."version" desc limit 1"""
rs = db.session.execute(text(sql), {'requestid': requestid})
rawrequestid = None
for row in rs:
rawrequestid = row["foirawrequestid"]
except Exception as ex:
logging.error(ex)
finally:
db.session.close()
return rawrequestid

class FOIRequestsSchema(ma.Schema):
class Meta:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class FOIFlowApplicantCorrespondence(Resource):
@auth.hasusertype('iao')
def get(requestid, ministryrequestid):
try:
correspondencelogs = applicantcorrespondenceservice().getapplicantcorrespondencelogs(ministryrequestid, requestid)
rawrequestid = requestservice().getrawrequestidbyfoirequestid(requestid)
correspondencelogs = applicantcorrespondenceservice().getapplicantcorrespondencelogs(ministryrequestid, rawrequestid)
return json.dumps(correspondencelogs) , 200
except BusinessException:
return "Error happened while fetching applicant correspondence logs" , 500
Expand All @@ -90,7 +91,8 @@ def post(requestid, ministryrequestid):
try:
requestjson = request.get_json()
applicantcorrespondencelog = FOIApplicantCorrespondenceSchema().load(data=requestjson)
result = communicationwrapperservice().send_email(requestid, ministryrequestid, applicantcorrespondencelog)
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
Expand All @@ -108,12 +110,13 @@ class FOIFlowApplicantCorrespondenceDraft(Resource):
def post(requestid, ministryrequestid):
try:
requestjson = request.get_json()
rawrequestid = requestservice().getrawrequestidbyfoirequestid(requestid)
if ministryrequestid != 'None':
correspondenceschemaobj = FOIApplicantCorrespondenceSchema().load(data=requestjson)
result = applicantcorrespondenceservice().saveapplicantcorrespondencelog(requestid, ministryrequestid, correspondenceschemaobj, AuthHelper.getuserid(), True)
result = applicantcorrespondenceservice().saveapplicantcorrespondencelog(rawrequestid, ministryrequestid, correspondenceschemaobj, AuthHelper.getuserid(), True)
elif ministryrequestid == 'None':
correspondenceschemaobj = FOIApplicantCorrespondenceSchema().load(data=requestjson)
result = applicantcorrespondenceservice().saveapplicantcorrespondencelogforrawrequest(requestid, correspondenceschemaobj, AuthHelper.getuserid(), True)
result = applicantcorrespondenceservice().saveapplicantcorrespondencelogforrawrequest(rawrequestid, correspondenceschemaobj, AuthHelper.getuserid(), True)
if result.success == True:
return {'status': result.success, 'message':result.message,'id':result.identifier} , 200
except BusinessException:
Expand All @@ -130,11 +133,12 @@ class FOIFlowApplicantCorrespondenceDraft(Resource):
def post(requestid, ministryrequestid):
try:
requestjson = request.get_json()
rawrequestid = requestservice().getrawrequestidbyfoirequestid(requestid)
applicantcorrespondencelog = FOIApplicantCorrespondenceSchema().load(data=requestjson)
if ministryrequestid == 'None':
result = applicantcorrespondenceservice().saveapplicantcorrespondencelogforrawrequest(requestid, applicantcorrespondencelog, AuthHelper.getuserid(), True)
result = applicantcorrespondenceservice().saveapplicantcorrespondencelogforrawrequest(rawrequestid, applicantcorrespondencelog, AuthHelper.getuserid(), True)
else:
result = applicantcorrespondenceservice().saveapplicantcorrespondencelog(requestid, ministryrequestid, applicantcorrespondencelog, AuthHelper.getuserid(), True)
result = applicantcorrespondenceservice().saveapplicantcorrespondencelog(rawrequestid, ministryrequestid, applicantcorrespondencelog, AuthHelper.getuserid(), True)
if result.success == True:
return {'status': result.success, 'message':result.message,'id':result.identifier} , 200
except BusinessException:
Expand All @@ -150,11 +154,12 @@ class FOIFlowApplicantCorrespondenceDraft(Resource):
@auth.require
def post(ministryrequestid, rawrequestid, correspondenceid):
try:
rawrequestidfromfoirequest = requestservice().getrawrequestidbyfoirequestid(rawrequestid)
if ministryrequestid == 'None':
rawresult = applicantcorrespondenceservice().deleteapplicantcorrespondencelograwrequest(rawrequestid, correspondenceid, AuthHelper.getuserid())
rawresult = applicantcorrespondenceservice().deleteapplicantcorrespondencelograwrequest(rawrequestidfromfoirequest, correspondenceid, AuthHelper.getuserid())
return {'status': rawresult.success, 'message':rawresult.message,'id':rawresult.identifier} , 200
else:
rawresult = applicantcorrespondenceservice().deleteapplicantcorrespondencelograwrequest(rawrequestid, correspondenceid, AuthHelper.getuserid())
rawresult = applicantcorrespondenceservice().deleteapplicantcorrespondencelograwrequest(rawrequestidfromfoirequest, 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 @@ -173,8 +178,9 @@ class FOIFlowApplicantCorrespondenceEmail(Resource):
def post(ministryrequestid, rawrequestid):
try:
requestjson = request.get_json()
rawrequestidfromfoirequest = requestservice().getrawrequestidbyfoirequestid(rawrequestid)
correspondenceemail = FOIApplicantCorrespondenceEmailSchema().load(data=requestjson)
result = correspondenceemailservice().savecorrespondenceemail(ministryrequestid, rawrequestid, correspondenceemail, AuthHelper.getuserid())
result = correspondenceemailservice().savecorrespondenceemail(ministryrequestid, rawrequestidfromfoirequest, correspondenceemail, AuthHelper.getuserid())

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

return {'status': result.success, 'message':result.message,'id':result.identifier} , 200
except BusinessException:
Expand All @@ -223,10 +231,11 @@ class FOIFlowApplicantCorrespondenceEditResponse(Resource):
@auth.require
def post(ministryrequestid, rawrequestid):
try:
rawrequestidfromfoirequest = requestservice().getrawrequestidbyfoirequestid(rawrequestid)
requestjson = request.get_json()
correspondenceemail = FOIApplicantCorrespondenceEditResponseSchema().load(data=requestjson)
if ministryrequestid == 'None':
result = applicantcorrespondenceservice().editapplicantcorrespondencelogforrawrequest(rawrequestid, correspondenceemail, AuthHelper.getuserid())
result = applicantcorrespondenceservice().editapplicantcorrespondencelogforrawrequest(rawrequestidfromfoirequest, correspondenceemail, AuthHelper.getuserid())
elif ministryrequestid != 'None':
result = applicantcorrespondenceservice().editapplicantcorrespondencelogforministry(ministryrequestid, correspondenceemail, AuthHelper.getuserid())

Expand All @@ -244,11 +253,12 @@ class FOIFlowApplicantCorrespondenceResponse(Resource):
@auth.require
def post(ministryrequestid, rawrequestid, correspondenceid):
try:
rawrequestidfromfoirequest = requestservice().getrawrequestidbyfoirequestid(rawrequestid)
if ministryrequestid == 'None':
rawresult = applicantcorrespondenceservice().deleteapplicantcorrespondencelograwrequest(rawrequestid, correspondenceid, AuthHelper.getuserid())
rawresult = applicantcorrespondenceservice().deleteapplicantcorrespondencelograwrequest(rawrequestidfromfoirequest, correspondenceid, AuthHelper.getuserid())
return {'status': rawresult.success, 'message':rawresult.message,'id':rawresult.identifier} , 200
else:
rawresult = applicantcorrespondenceservice().deleteapplicantcorrespondencelograwrequest(rawrequestid, correspondenceid, AuthHelper.getuserid())
rawresult = applicantcorrespondenceservice().deleteapplicantcorrespondencelograwrequest(rawrequestidfromfoirequest, 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 @@ -29,12 +29,12 @@ def gettemplatebyid(self, templateid):
"""
return ApplicationCorrespondenceTemplate.get_template_by_id(templateid)

def getapplicantcorrespondencelogs(self,ministryrequestid, requestid):
def getapplicantcorrespondencelogs(self,ministryrequestid, rawrequestid):
""" Returns the active applicant correspondence logs
"""
_correspondencelogs = FOIApplicantCorrespondenceRawRequest.getapplicantcorrespondencesrawrequests(requestid)
_correspondenceattachments = FOIApplicantCorrespondenceAttachmentRawRequest.getcorrespondenceattachmentsbyrawrequestid(requestid)
_correspondenceemails = FOIApplicantCorrespondenceEmailRawRequest.getapplicantcorrespondenceemails(requestid)
_correspondencelogs = FOIApplicantCorrespondenceRawRequest.getapplicantcorrespondencesrawrequests(rawrequestid)
_correspondenceattachments = FOIApplicantCorrespondenceAttachmentRawRequest.getcorrespondenceattachmentsbyrawrequestid(rawrequestid)
_correspondenceemails = FOIApplicantCorrespondenceEmailRawRequest.getapplicantcorrespondenceemails(rawrequestid)
if ministryrequestid != 'None':
_correspondencelogs.extend(FOIApplicantCorrespondence.getapplicantcorrespondences(ministryrequestid))
_correspondenceattachments.extend(FOIApplicantCorrespondenceAttachment.getcorrespondenceattachmentsbyministryid(ministryrequestid))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ def getrequestdetails(self,foirequestid, foiministryrequestid):
requestdetails['cfrfee']['feedata']['paymentdate'] = payment['created_at'][:10]
return requestdetails

def getrawrequestidbyfoirequestid(self, foirequestid):
return FOIRequest.getrawrequestidbyfoirequestid(foirequestid)

def __preparebaseinfo(self,request,foiministryrequestid,requestministry,requestministrydivisions):
_receiveddate = parse(request['receiveddate'])
axissyncdatenoneorempty = self.__noneorempty(requestministry["axissyncdate"])
Expand Down
8 changes: 8 additions & 0 deletions request-management-api/request_api/services/requestservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ def updateduedate(
def getrequest(self, foirequestid, foiministryrequestid):
return requestservicegetter().getrequest(foirequestid, foiministryrequestid)

def getrawrequestidbyfoirequestid(self, foirequestid):
if foirequestid == 'undefined':
return None
rawrequestid = requestservicegetter().getrawrequestidbyfoirequestid(foirequestid)
if rawrequestid is None:
rawrequestid = foirequestid
return rawrequestid

def getrequestdetailsforministry(
self, foirequestid, foiministryrequestid, authmembershipgroups
):
Expand Down

0 comments on commit 320c051

Please sign in to comment.