Skip to content

Commit

Permalink
Merge pull request #5386 from bcgov/dev
Browse files Browse the repository at this point in the history
Enable multiple keywords on queue search FOIMOD-3110
  • Loading branch information
richard-aot authored Aug 29, 2024
2 parents a5dda29 + ea80531 commit 2314b5f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
29 changes: 17 additions & 12 deletions request-management-api/request_api/models/FOIMinistryRequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,20 +432,25 @@ def getrequestssubquery(cls, groups, filterfields, keyword, additionalfilter, us
ministry_restricted_requests = aliased(FOIRestrictedMinistryRequest)

#filter/search
_keywords = []
if(keyword is not None):
_keywords = keyword.lower().replace(",", " ").split()
if(len(filterfields) > 0 and keyword is not None):

filtercondition = []

if(keyword != "restricted"):
for field in filterfields:
filtercondition.append(FOIMinistryRequest.findfield(field, iaoassignee, ministryassignee).ilike('%'+keyword+'%'))
else:
if(requestby == 'IAO'):
filtercondition.append(FOIRestrictedMinistryRequest.isrestricted == True)
for _keyword in _keywords:
onekeywordfiltercondition = []
if(_keyword != "restricted"):
for field in filterfields:
onekeywordfiltercondition.append(FOIMinistryRequest.findfield(field, iaoassignee, ministryassignee).ilike('%'+_keyword+'%'))
else:
filtercondition.append(ministry_restricted_requests.isrestricted == True)
if (keyword.lower() == "oipc"):
filtercondition.append(FOIMinistryRequest.isoipcreview == True)
if(requestby == 'IAO'):
onekeywordfiltercondition.append(FOIRestrictedMinistryRequest.isrestricted == True)
else:
onekeywordfiltercondition.append(ministry_restricted_requests.isrestricted == True)
if (_keyword == "oipc"):
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 @@ -706,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
38 changes: 22 additions & 16 deletions request-management-api/request_api/models/FOIRawRequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,26 +689,32 @@ def getrequestssubquery(cls, filterfields, keyword, additionalfilter, userid, is

@classmethod
def getfilterforrequestssubquery(cls, filterfields, keyword):
keyword = keyword.lower()
_keywords = []
if(keyword is not None):
_keywords = keyword.lower().replace(",", " ").split()

#filter/search
filtercondition = []
if(keyword != 'restricted'):
for field in filterfields:
if(field == 'idNumber'):
keyword = keyword.replace('u-00', '')

filtercondition.append(FOIRawRequest.findfield(field).ilike('%'+keyword+'%'))
if(field == 'firstName'):
filtercondition.append(FOIRawRequest.findfield('contactFirstName').ilike('%'+keyword+'%'))
if(field == 'lastName'):
filtercondition.append(FOIRawRequest.findfield('contactLastName').ilike('%'+keyword+'%'))
if(field == 'requestType'):
filtercondition.append(FOIRawRequest.findfield('requestTypeRequestType').ilike('%'+keyword+'%'))
else:
filtercondition.append(FOIRawRequest.isiaorestricted == True)
for _keyword in _keywords:
onekeywordfiltercondition = []
if(_keyword != 'restricted'):
for field in filterfields:
if(field == 'idNumber'):
_keyword = _keyword.replace('u-00', '')

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

filtercondition.append(or_(*onekeywordfiltercondition))

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


@classmethod
Expand Down

0 comments on commit 2314b5f

Please sign in to comment.