Skip to content

Commit

Permalink
Merge pull request #5385 from bcgov/dev-RQ-3110
Browse files Browse the repository at this point in the history
and condition for each keyword
  • Loading branch information
richard-aot authored Aug 29, 2024
2 parents 410b0a0 + e18d5f5 commit 06f6418
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
13 changes: 8 additions & 5 deletions request-management-api/request_api/models/FOIMinistryRequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,16 +438,19 @@ def getrequestssubquery(cls, groups, filterfields, keyword, additionalfilter, us
if(len(filterfields) > 0 and keyword is not None):
filtercondition = []
for _keyword in _keywords:
onekeywordfiltercondition = []
if(_keyword != "restricted"):
for field in filterfields:
filtercondition.append(FOIMinistryRequest.findfield(field, iaoassignee, ministryassignee).ilike('%'+_keyword+'%'))
onekeywordfiltercondition.append(FOIMinistryRequest.findfield(field, iaoassignee, ministryassignee).ilike('%'+_keyword+'%'))
else:
if(requestby == 'IAO'):
filtercondition.append(FOIRestrictedMinistryRequest.isrestricted == True)
onekeywordfiltercondition.append(FOIRestrictedMinistryRequest.isrestricted == True)
else:
filtercondition.append(ministry_restricted_requests.isrestricted == True)
onekeywordfiltercondition.append(ministry_restricted_requests.isrestricted == True)
if (_keyword == "oipc"):
filtercondition.append(FOIMinistryRequest.isoipcreview == True)
onekeywordfiltercondition.append(FOIMinistryRequest.isoipcreview == True)

filtercondition.append(or_(*onekeywordfiltercondition))

intakesorting = case([
(and_(FOIMinistryRequest.assignedto == None, FOIMinistryRequest.assignedgroup == 'Intake Team'), # Unassigned requests first
Expand Down Expand Up @@ -708,7 +711,7 @@ def getrequestssubquery(cls, groups, filterfields, keyword, additionalfilter, us
if(keyword is None):
return dbquery
else:
return dbquery.filter(or_(*filtercondition))
return dbquery.filter(and_(*filtercondition))

@classmethod
def getrequestspagination(cls, group, page, size, sortingitems, sortingorders, filterfields, keyword, additionalfilter, userid, isiaorestrictedfilemanager, isministryrestrictedfilemanager):
Expand Down
15 changes: 9 additions & 6 deletions request-management-api/request_api/models/FOIRawRequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -696,22 +696,25 @@ def getfilterforrequestssubquery(cls, filterfields, keyword):
#filter/search
filtercondition = []
for _keyword in _keywords:
onekeywordfiltercondition = []
if(_keyword != 'restricted'):
for field in filterfields:
if(field == 'idNumber'):
_keyword = _keyword.replace('u-00', '')

filtercondition.append(FOIRawRequest.findfield(field).ilike('%'+_keyword+'%'))
onekeywordfiltercondition.append(FOIRawRequest.findfield(field).ilike('%'+_keyword+'%'))
if(field == 'firstName'):
filtercondition.append(FOIRawRequest.findfield('contactFirstName').ilike('%'+_keyword+'%'))
onekeywordfiltercondition.append(FOIRawRequest.findfield('contactFirstName').ilike('%'+_keyword+'%'))
if(field == 'lastName'):
filtercondition.append(FOIRawRequest.findfield('contactLastName').ilike('%'+_keyword+'%'))
onekeywordfiltercondition.append(FOIRawRequest.findfield('contactLastName').ilike('%'+_keyword+'%'))
if(field == 'requestType'):
filtercondition.append(FOIRawRequest.findfield('requestTypeRequestType').ilike('%'+_keyword+'%'))
onekeywordfiltercondition.append(FOIRawRequest.findfield('requestTypeRequestType').ilike('%'+_keyword+'%'))
else:
filtercondition.append(FOIRawRequest.isiaorestricted == True)
onekeywordfiltercondition.append(FOIRawRequest.isiaorestricted == True)

filtercondition.append(or_(*onekeywordfiltercondition))

return or_(*filtercondition)
return and_(*filtercondition)


@classmethod
Expand Down

0 comments on commit 06f6418

Please sign in to comment.