def getrawrequestforid(self, requestid): request = FOIRawRequest.get_request(requestid) request = self.__attachministriesinfo(request) if request != {} and request[ 'version'] == 1 and request['sourceofsubmission'] != "intake": requestrawdata = request['requestrawdata'] requesttype = requestrawdata['requestType']['requestType'] baserequestinfo = self.__preparebaserequestinfo( requestid, request, requesttype, requestrawdata) if self.__ispersonalrequest(requesttype): baserequestinfo[ 'additionalPersonalInfo'] = self.__prepareadditionalpersonalinfo( requestrawdata) return baserequestinfo elif request != {} and request['version'] != 1 and request[ 'sourceofsubmission'] != "intake": request['requestrawdata']['currentState'] = request['status'] requeststatus = FOIRequestStatus().getrequeststatusid( request['status']) request['requestrawdata']['requeststatusid'] = requeststatus[ 'requeststatusid'] request['requestrawdata'][ 'lastStatusUpdateDate'] = FOIRawRequest.getLastStatusUpdateDate( requestid, request['status']).strftime(self.__generaldateformat()) if request['status'] == 'Closed': request['requestrawdata'][ 'stateTransition'] = FOIRawRequest.getstatesummary( requestid) return request['requestrawdata'] elif request != {} and request['sourceofsubmission'] == "intake": requestrawdata = request['requestrawdata'] requesttype = requestrawdata['requestType'] additionalpersonalinfo = None if self.__ispersonalrequest(requesttype) and requestrawdata.get( 'additionalPersonalInfo') is not None: additionalpersonalinfo = self.__prepareadditionalpersonalinfoforintakesubmission( requestrawdata) request['requestrawdata'][ 'additionalPersonalInfo'] = additionalpersonalinfo request['requestrawdata']['wfinstanceid'] = request['wfinstanceid'] request['requestrawdata']['currentState'] = request['status'] requeststatus = FOIRequestStatus().getrequeststatusid( request['status']) request['requestrawdata']['requeststatusid'] = requeststatus[ 'requeststatusid'] request['requestrawdata'][ 'lastStatusUpdateDate'] = FOIRawRequest.getLastStatusUpdateDate( requestid, request['status']).strftime(self.__generaldateformat()) request['requestrawdata'][ 'stateTransition'] = FOIRawRequest.getstatesummary(requestid) return request['requestrawdata'] else: return None
def getrequestqueuepagination(self, groups=None, page=1, size=10, sortingitems=[], sortingorders=[], filterfields=[], keyword=None, additionalfilter='All', userid=None): requests = FOIRawRequest.getrequestspagination(groups, page, size, sortingitems, sortingorders, filterfields, keyword, additionalfilter, userid) requestqueue = [] for request in requests.items: _receiveddate = maya.parse(request.created_at).datetime(to_timezone='America/Vancouver', naive=False) if(request.version != 1 and request.sourceofsubmission != "intake") or request.sourceofsubmission == "intake": _receiveddate = parser.parse(request.receivedDateUF) if(request.ministryrequestid == None): unopenrequest = self.__preparefoirequestinfo(request.id, request.firstName, request.lastName, request.requestType, request.currentState, _receiveddate.strftime(SHORT_DATEFORMAT), _receiveddate.strftime(LONG_DATEFORMAT), request.assignedGroup, request.assignedTo, 'U-00' + request.idNumber, request.version, request.assignedToFirstName, request.assignedToLastName) requestqueue.append(unopenrequest) else: _openrequest = self.__preparefoirequestinfo(request.id, request.firstName, request.lastName, request.requestType, request.currentState, _receiveddate.strftime(SHORT_DATEFORMAT), _receiveddate.strftime(LONG_DATEFORMAT), request.assignedGroup, request.assignedGroup, request.idNumber, request.version, request.assignedToFirstName, request.assignedToLastName) _openrequest.update({'ministryrequestid':request.ministryrequestid}) requestqueue.append(_openrequest) meta = { 'page': requests.page, 'pages': requests.pages, 'total': requests.total, 'prev_num': requests.prev_num, 'next_num': requests.next_num, 'has_next': requests.has_next, 'has_prev': requests.has_prev, } return jsonify({'data': requestqueue, 'meta': meta})
def saverawrequest(self, requestdatajson, sourceofsubmission, userid,notes): assigneegroup = requestdatajson["assignedGroup"] if requestdatajson.get("assignedGroup") != None else None assignee = requestdatajson["assignedTo"] if requestdatajson.get("assignedTo") not in (None,'') else None assigneefirstname = requestdatajson["assignedToFirstName"] if requestdatajson.get("assignedToFirstName") != None else None assigneemiddlename = requestdatajson["assignedToMiddleName"] if requestdatajson.get("assignedToMiddleName") != None else None assigneelastname = requestdatajson["assignedToLastName"] if requestdatajson.get("assignedToLastName") != None else None ispiiredacted = requestdatajson["ispiiredacted"] if 'ispiiredacted' in requestdatajson else False requirespayment = rawrequestservice.doesrequirepayment(requestdatajson) if sourceofsubmission == "onlineform" else False result = FOIRawRequest.saverawrequest( _requestrawdata=requestdatajson, sourceofsubmission= sourceofsubmission, ispiiredacted=ispiiredacted, userid= userid, assigneegroup=assigneegroup, assignee=assignee, requirespayment=requirespayment, notes=notes, assigneefirstname=assigneefirstname, assigneemiddlename=assigneemiddlename, assigneelastname=assigneelastname ) if result.success: redispubservice = RedisPublisherService() data = {} data['id'] = result.identifier data['assignedGroup'] = assigneegroup data['assignedTo'] = assignee json_data = json.dumps(data) asyncio.create_task(redispubservice.publishrequest(json_data)) return result
def saverawrequestversion(self, _requestdatajson, _requestid, _assigneegroup, _assignee, status, userid, username, isministryuser, assigneefirstname, assigneemiddlename, assigneelastname): ispiiredacted = _requestdatajson["ispiiredacted"] if 'ispiiredacted' in _requestdatajson else False #Get documents result = FOIRawRequest.saverawrequestversion(_requestdatajson, _requestid, _assigneegroup, _assignee, status,ispiiredacted, userid, assigneefirstname, assigneemiddlename, assigneelastname) documentservice().createrawrequestdocumentversion(_requestid) asyncio.create_task(eventservice().postevent(_requestid,"rawrequest",userid, username, isministryuser)) return result
def __getversionforrequest(self, requestid, requesttype): """ Returns the active version of the request id based on type. """ if requesttype == "ministryrequest": return FOIMinistryRequest.getversionforrequest(requestid)[0] else: return FOIRawRequest.getversionforrequest(requestid)[0]
def getrawrequestfieldsforid(self, requestid, fields): request = FOIRawRequest.get_request(requestid) fieldsresp = {} for field in fields: if field == "ministries" and request['status'] == 'Archived': fieldsresp[ 'openedMinistries'] = FOIMinistryRequest.getministriesopenedbyuid( request["requestid"]) return fieldsresp
def createrawrequestwatcher(self, data, userid, usergroups): """Creates a watcher for a user with groups passed in for an unopened request. """ version = FOIRawRequest.getversionforrequest(data["requestid"]) if 'watchedbygroup' in data: return FOIRawRequestWatcher.savewatcher(data, version, userid) else: return FOIRawRequestWatcher.savewatcherbygroups( data, version, userid, self.__getwatchablegroups(usergroups))
def __hasreopened(self, requestid, requesttype): if requesttype == "rawrequest": states = FOIRawRequest.getstatenavigation(requestid) else: states = FOIMinistryRequest.getstatenavigation(requestid) if len(states) == 2: newstate = states[0] oldstate = states[1] if newstate != oldstate and oldstate == "Closed": return True return False
def __haschanged(self, requestid, requesttype): if requesttype == "rawrequest": states = FOIRawRequest.getstatenavigation(requestid) else: states = FOIMinistryRequest.getstatenavigation(requestid) if len(states) == 2: newstate = states[0] oldstate = states[1] if newstate != oldstate: return newstate return None
def __getauditfromrawrequest(self, type, id, groups): _rawdescriptions = [] if type == "ministryrequest": requestrecord = FOIRequest().getrequest(id) rawrequestid= requestrecord['foirawrequestid'] else: rawrequestid= id rawrecords = FOIRawRequest().getDescriptionSummaryById(rawrequestid) for entry in rawrecords: fromdate =dateutil.parser.parse(entry['fromdate']).strftime('%Y-%m-%d') if entry['fromdate'] is not None else None todate = dateutil.parser.parse(entry['todate']).strftime('%Y-%m-%d') if entry['todate'] is not None else None if AuthHelper.getusertype() == "iao": _rawdescriptions.append({"description": entry['description'], "fromdate": fromdate, "todate": todate, "createdat": entry['createdat'] , "createdby": entry['createdby'], "status": entry['status']}) else: if entry['ispiiredacted'] == True: _rawdescriptions.append({"description": entry['description'], "fromdate": fromdate, "todate": todate, "createdat": entry['createdat'] , "createdby": entry['createdby'], "status": entry['status']}) return _rawdescriptions
def getallrawrequests(self): requests = FOIRawRequest.getrequests() unopenedrequests = [] for request in requests: firstname, lastname, requesttype = '', '', '' if (request.version != 1 and request.sourceofsubmission != "intake" ) or request.sourceofsubmission == "intake": firstname = request.requestrawdata['firstName'] lastname = request.requestrawdata['lastName'] requesttype = request.requestrawdata['requestType'] elif (request.sourceofsubmission != "intake" and request.version == 1): firstname = request.requestrawdata['contactInfo']['firstName'] lastname = request.requestrawdata['contactInfo']['lastName'] requesttype = request.requestrawdata['requestType'][ 'requestType'] assignedgroupvalue = request.assignedgroup if request.assignedgroup else "Unassigned" assignedtovalue = request.assignedto if request.assignedto else "Unassigned" _createddate = request.created_at unopenrequest = { 'id': request.requestid, 'firstName': firstname, 'lastName': lastname, 'requestType': requesttype, 'currentState': request.status, 'receivedDate': _createddate.strftime('%Y %b, %d'), 'receivedDateUF': str(_createddate), 'assignedGroup': assignedgroupvalue, 'assignedTo': assignedtovalue, 'xgov': 'No', 'idNumber': 'U-00' + str(request.requestid), 'version': request.version } unopenedrequests.append(unopenrequest) return unopenedrequests
def advancedsearch(self, params={'groups':None, 'page':1, 'size':10, 'sortingitems':[], 'sortingorders':[], 'requeststate':[], 'requeststatus':[], 'requesttype':[], 'publicbody':[], 'fromdate':None, 'todate':None, 'search':None, 'keywords':[], 'userid':None}): requests = FOIRawRequest.advancedsearch(params) requestqueue = [] for request in requests.items: _receiveddate = maya.parse(request.created_at).datetime(to_timezone='America/Vancouver', naive=False) if(request.version != 1 and request.sourceofsubmission != "intake") or request.sourceofsubmission == "intake": _receiveddate = parser.parse(request.receivedDateUF) if(request.ministryrequestid == None): unopenrequest = self.__preparefoirequestinfo(request.id, request.firstName, request.lastName, request.requestType, request.currentState, _receiveddate.strftime(SHORT_DATEFORMAT), _receiveddate.strftime(LONG_DATEFORMAT), request.assignedGroup, request.assignedTo, 'U-00' + request.idNumber, request.version, request.assignedToFirstName, request.assignedToLastName) unopenrequest.update({'description':request.description}) unopenrequest.update({'duedate':request.duedate}) requestqueue.append(unopenrequest) else: _openrequest = self.__preparefoirequestinfo(request.id, request.firstName, request.lastName, request.requestType, request.currentState, _receiveddate.strftime(SHORT_DATEFORMAT), _receiveddate.strftime(LONG_DATEFORMAT), request.assignedGroup, request.assignedGroup, request.idNumber, request.version, request.assignedToFirstName, request.assignedToLastName) _openrequest.update({'ministryrequestid':request.ministryrequestid}) _openrequest.update({'description':request.description}) _openrequest.update({'duedate':request.duedate}) requestqueue.append(_openrequest) meta = { 'page': requests.page, 'pages': requests.pages, 'total': requests.total, 'prev_num': requests.prev_num, 'next_num': requests.next_num, 'has_next': requests.has_next, 'has_prev': requests.has_prev, } return jsonify({'data': requestqueue, 'meta': meta})
def updateworkflowinstancewithstatus(self, wfinstanceid, requestid,notes, userid): return FOIRawRequest.updateworkflowinstancewithstatus(wfinstanceid,requestid,notes, userid)
def updateworkflowinstance(self, wfinstanceid, requestid, userid): return FOIRawRequest.updateworkflowinstance(wfinstanceid, requestid, userid)
def __getassignments(self, requestid, requesttype): if requesttype == "ministryrequest": return FOIMinistryRequest.getassignmenttransition(requestid) else: return FOIRawRequest.getassignmenttransition(requestid)
def createrawrequestcomment(self, data, userid, type=1): version = FOIRawRequest.getversionforrequest(data["requestid"]) return FOIRawRequestComment.savecomment(type, data, version, userid)
def __getrequest(self, requestid, requesttype): if requesttype == "ministryrequest": return FOIMinistryRequest.getrequestbyministryrequestid(requestid) else: return FOIRawRequest.get_request(requestid)
def __preparebaserequestinfo(self, requestid, request, requesttype, requestrawdata): contactinfo = requestrawdata.get('contactInfo') dt = maya.parse(request['created_at']).datetime( to_timezone='America/Vancouver', naive=False) _createddate = dt decriptiontimeframe = requestrawdata.get('descriptionTimeframe') contactinfooptions = requestrawdata.get('contactInfoOptions') _fromdate = parse(decriptiontimeframe['fromDate']) _todate = parse(decriptiontimeframe['toDate']) return { 'id': request['requestid'], 'wfinstanceid': request['wfinstanceid'], 'ispiiredacted': request['ispiiredacted'], 'sourceOfSubmission': request['sourceofsubmission'], 'requestType': requesttype, 'firstName': contactinfo['firstName'], 'middleName': requestrawdata['contactInfo']['middleName'], 'lastName': contactinfo['lastName'], 'businessName': contactinfo['businessName'], 'currentState': request['status'], 'receivedDate': _createddate.strftime('%Y %b, %d'), 'receivedDateUF': _createddate.strftime('%Y-%m-%d %H:%M:%S.%f'), 'assignedGroup': "Unassigned", 'assignedTo': "Unassigned", 'xgov': 'No', 'idNumber': 'U-00' + str(request['requestid']), 'email': contactinfooptions['email'], 'phonePrimary': contactinfooptions['phonePrimary'], 'phoneSecondary': contactinfooptions['phoneSecondary'], 'address': contactinfooptions['address'], 'city': contactinfooptions['city'], 'postal': contactinfooptions['postal'], 'province': contactinfooptions['province'], 'country': contactinfooptions['country'], 'description': decriptiontimeframe['description'], 'fromDate': _fromdate.strftime(self.__generaldateformat()), 'toDate': _todate.strftime(self.__generaldateformat()), 'correctionalServiceNumber': decriptiontimeframe['correctionalServiceNumber'], 'publicServiceEmployeeNumber': decriptiontimeframe['publicServiceEmployeeNumber'], 'topic': decriptiontimeframe['topic'], 'selectedMinistries': requestrawdata['ministry']['selectedMinistry'], 'lastStatusUpdateDate': FOIRawRequest.getLastStatusUpdateDate( requestid, request['status']).strftime(self.__generaldateformat()), 'stateTransition': FOIRawRequest.getstatesummary(requestid) }