Skip to content

Commit

Permalink
controlling of lock records for IAO user completed. WIP ministry user
Browse files Browse the repository at this point in the history
  • Loading branch information
Aman-Hundal committed Jul 11, 2024
1 parent 25ef0c8 commit 793f77c
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 9 deletions.
26 changes: 25 additions & 1 deletion forms-flow-web/src/apiManager/services/FOI/foiRecordServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,4 +620,28 @@ export const fetchPDFStitchedRecordForOIPCRedlineReview = (
done(error);
});
};
}
}

export const updateUserLockedRecords = (data, requestId, ministryId, ...rest) => {
const done = fnDone(rest);
let apiUrl= replaceUrl(replaceUrl(
API.FOI_REQUEST_SECTION_API,
"<ministryid>",
ministryId),"<requestid>",requestId
);
return (dispatch) => {
httpPOSTRequest(`${apiUrl}/userlockedrecords`, data)
.then((res) => {
if (res.data) {
done(null, res.data);
} else {
dispatch(serviceActionError(res));
throw new Error(`Error while updating records lock status for the (request# ${requestId}, ministry# ${ministryId})`);
}
})
.catch((error) => {
dispatch(serviceActionError(error));
done(error);
});
};
}
7 changes: 1 addition & 6 deletions forms-flow-web/src/components/FOI/FOIRequest/FOIRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1057,11 +1057,6 @@ const FOIRequest = React.memo(({ userDetail, openApplicantProfileModal }) => {
requestDetails?.requestType === FOI_COMPONENT_CONSTANTS.REQUEST_TYPE_GENERAL)
}

const handleLockRecords = () => {
setLockRecordsTab(!lockRecordsTab);
console.log("API CALL TO LOCK RECORDS ENDPOINT") // OR JUST REUQEST UPDATE END POINT AND NO NEED FOR NEW ONE?
}

return (!isLoading &&
requestDetails &&
Object.keys(requestDetails).length !== 0) ||
Expand Down Expand Up @@ -1671,7 +1666,7 @@ const FOIRequest = React.memo(({ userDetail, openApplicantProfileModal }) => {
recordsTabSelect={tabLinksStatuses.Records.active}
requestType={requestDetails?.requestType}
lockRecords={lockRecordsTab}
handleLockRecords={handleLockRecords}
setLockRecordsTab={setLockRecordsTab}
/>
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
fetchPDFStitchedRecordForOIPCRedline,
fetchPDFStitchedRecordForOIPCRedlineReview,
checkForRecordsChange,
updateUserLockedRecords,
} from "../../../../apiManager/services/FOI/foiRecordServices";
import {
StateTransitionCategories,
Expand Down Expand Up @@ -220,6 +221,7 @@ export const RecordsLog = ({
recordsTabSelect,
requestType,
lockRecords,
setLockRecordsTab,
}) => {
const user = useSelector((state) => state.user.userDetail);
const userGroups = user?.groups?.map((group) => group.slice(1));
Expand Down Expand Up @@ -577,6 +579,7 @@ export const RecordsLog = ({
saveDocument(value, fileInfoList, files);
}
};
console.log("LOCK", lockRecords)

const saveDocument = (value, fileInfoList, files) => {
if (value) {
Expand Down Expand Up @@ -1742,6 +1745,47 @@ export const RecordsLog = ({
);
};

const handleLockRecords = () => {
setLockRecordsTab(!lockRecords);
const toastID = toast.loading("Updating records lock status for request...");
const data = {userlockedrecords: !lockRecords};
dispatch(
updateUserLockedRecords(
data,
requestId,
ministryId,
(err, _res) => {
if(!err) {
toast.update(toastID, {
type: "success",
render: "Request details have been saved successfully.",
position: "top-right",
isLoading: false,
autoClose: 3000,
hideProgressBar: true,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
});
} else {
toast.error(
"Temporarily unable to update records lock status for request. Please try again in a few minutes.",
{
position: "top-right",
autoClose: 3000,
hideProgressBar: true,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
}
);
}
})
)
}

return (
<div className={classes.container}>
{isAttachmentLoading ? (
Expand All @@ -1766,6 +1810,7 @@ export const RecordsLog = ({
<Grid>
<button
style={{marginTop: "4px"}}
onClick={handleLockRecords}
className={clsx(
"btn",
"addAttachment",
Expand Down
11 changes: 9 additions & 2 deletions request-management-api/request_api/resources/foirequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ class FOIRequestsById(Resource):
def post(foirequestid,foiministryrequestid):
""" POST Method for capturing FOI requests before processing"""
try:
request_json = request.get_json()
request_json = request.get_json()
print("SNAKKE", request_json)
foirequestschema = FOIRequestWrapperSchema().load(request_json)
result = requestservice().saverequestversion(foirequestschema, foirequestid, foiministryrequestid,AuthHelper.getuserid())
if result.success == True:
Expand Down Expand Up @@ -308,9 +309,15 @@ def post(foirequestid,foiministryrequestid,section):
foirequest = requestservice().getrequest(foirequestid, foiministryrequestid)
foirequest['isoipcreview'] = request_json['isoipcreview']
foirequest['oipcdetails'] = request_json['oipcdetails']
foirequestschema = FOIRequestWrapperSchema().load(foirequest)
if (section == "userlockedrecords"):
foirequest = requestservice().getrequest(foirequestid, foiministryrequestid)
foirequest['userlockedrecords'] = request_json['userlockedrecords']

print("LIQUID", request_json)
foirequestschema = FOIRequestWrapperSchema().load(foirequest)
result = requestservice().saverequestversion(foirequestschema, foirequestid, foiministryrequestid,AuthHelper.getuserid())
if result.success == True:
#MAY NEED TO ADJ THIS?
asyncio.ensure_future(eventservice().postevent(foiministryrequestid,"ministryrequest",AuthHelper.getuserid(),AuthHelper.getusername(),AuthHelper.isministrymember()))
metadata = json.dumps({"id": result.identifier, "ministries": result.args[0]})
requestservice().posteventtoworkflow(foiministryrequestid, foirequestschema, json.loads(metadata),"iao")
Expand Down

0 comments on commit 793f77c

Please sign in to comment.