Skip to content

Commit

Permalink
Merge pull request #1250 from bcgov/dev-rook-NK-FOIMOD-3584
Browse files Browse the repository at this point in the history
merge additional 14.0 changes - oi keycloak team, oi package names
  • Loading branch information
Aman-Hundal authored Jan 6, 2025
2 parents 7047c94 + 2681349 commit 33d2ed5
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 22 deletions.
45 changes: 45 additions & 0 deletions api/reviewer_api/models/DocumentPageflags.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,51 @@ def getpageflag_by_request_documentids(cls, _foiministryrequestid, redactionlaye
db.session.close()
return pageflags

@classmethod
def get_pageflag_count_by_requestids(cls, requestid, redactionlayerid):
try:
# Return empty dict if requestids is empty or None
if not requestid:
logging.error("RequestIDs is empty or None")
return {}
sql = """
select dp.foiministryrequestid, count(distinct dp.documentid) as page_count
from "DocumentPageflags" dp
where dp.foiministryrequestid in :requestid
and dp.redactionlayerid = :redactionlayerid
group by dp.foiministryrequestid
order by dp.foiministryrequestid;
"""

rs = db.session.execute(
text(sql),
{
"requestid": tuple(requestid),
"redactionlayerid": redactionlayerid
}
)

result = {}
rows = rs.fetchall()

# Return empty dict if no results found
if not rows:
return {}

# Process results if exists
for row in rows:
count = row["page_count"]
result[row["foiministryrequestid"]] = None if count == 0 else count

return result

except Exception as ex:
logging.error(f"Error in get_pageflag_count_by_requestids: {str(ex)}")
db.session.close()
raise ex
finally:
db.session.close()

@classmethod
def getpublicbody_by_request(cls, _foiministryrequestid, _redactionlayerid):
pageflags = []
Expand Down
27 changes: 26 additions & 1 deletion api/reviewer_api/resources/documentpageflag.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,29 @@ def post(requestid, redactionlayer):
except KeyError as error:
return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400
except BusinessException as exception:
return {'status': exception.status_code, 'message':exception.message}, 500
return {'status': exception.status_code, 'message':exception.message}, 500


@cors_preflight('GET,OPTIONS')
@API.route('/ministryrequest/<requestid>/pageflag/count')
class GetDocumentPageflagCount(Resource):
"""Get document page flag count for openinfo layer"""
@staticmethod
@TRACER.trace()
@cross_origin(origins=allowedorigins())
@auth.require
@auth.ismemberofgroups(getrequiredmemberships())
def get(requestid):
try:
# Get page flag count for openinfo layer (redactionlayerid=4)
result = documentpageflagservice().get_total_pages_by_ministryrequest_openinfo(requestid)

if result is None:
return None, 200

return json.dumps(result), 200

except BusinessException as exception:
return {'status': exception.status_code, 'message': exception.message}, 500
except Exception as error:
return {'status': False, 'message': str(error)}, 400
2 changes: 2 additions & 0 deletions api/reviewer_api/resources/foiflowmasterdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ def post(ministryrequestid, redactionlayer="responsepackage"):
# generate save url for stitched file
filepathlist = data["filepath"].split("/")[4:]
filename = filepathlist[0]
if redactionlayer == "openinfo":
filename = "Response_Package_" + filename
filepath_put = "{0}/{2}/{1}.pdf".format(
filepathlist[0], filename, redactionlayer
)
Expand Down
19 changes: 15 additions & 4 deletions api/reviewer_api/services/documentpageflagservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,29 @@
class documentpageflagservice:
def getpageflags_by_requestid_docids(self, requestid, redactionlayer, documentids):
layerids = []

if redactionlayerservice().isopeninfolayer(redactionlayer):
layerids.append(redactionlayerservice().getdefaultredactionlayerid())
else:
layerids.append(redactionlayerservice().getredactionlayerid(redactionlayer))
#layerids.append(redactionlayerservice().getdefaultredactionlayerid())
print("layerids:",layerids)
print("documentids:",documentids)

pageflags = DocumentPageflag.getpageflag_by_request_documentids(requestid, layerids, documentids)
print("pageflags:",pageflags)
return self.__removedeletedpages(requestid, pageflags)

def get_total_pages_by_ministryrequest_openinfo(self, ministryrequestids):
layerid = 4 # openinfo layer id

result = DocumentPageflag.get_pageflag_count_by_requestids(
requestid=ministryrequestids,
redactionlayerid=layerid
)

if not result:
return None

return result

def getpublicbody(self, requestid, redactionlayer):
redactionlayerid = redactionlayerservice().getredactionlayerid(redactionlayer)
return DocumentPageflag.getpublicbody_by_request(requestid, redactionlayerid)
Expand Down
2 changes: 1 addition & 1 deletion api/reviewer_api/utils/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def getrequiredmemberships():
membership += "{0},".format(group.value)
for procgroup in ProcessingTeamWithKeycloackGroup:
membership += "{0},".format(procgroup.value)
membership += "Intake Team,Flex Team"
membership += "Intake Team,Flex Team,OI Team"
return membership


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from utils import getdbconnection
from utils import getdbconnection, getfoidbconnection
import logging
import json

Expand Down Expand Up @@ -225,6 +225,8 @@ def getrecentredactionlayerid(cls, ministryrequestid):
select redactionlayerid
from "DocumentPageflags"
where foiministryrequestid = %s::integer
and redactionlayerid != 4
--openinfo layer is excluded latest redaction layer because it always uses the normal redaction summary
order by created_at desc limit 1;
'''
cursor.execute(query, (ministryrequestid,))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class redactionsummary():

def prepareredactionsummary(self, message, documentids, pageflags, programareas):
_ismcfpersonalrequest = True if message.bcgovcode == 'mcf' and message.requesttype == 'personal' else False
if _ismcfpersonalrequest and message.category == "responsepackage":
if _ismcfpersonalrequest and message.category in ("responsepackage", "openinfo"):
redactionsummary = self.__packagesummaryforcfdrequests(message, documentids)
else:
redactionsummary = self.__packaggesummary(message, documentids, pageflags, programareas)
if message.category == "responsepackage" and _ismcfpersonalrequest == False:
if message.category in ("responsepackage", "openinfo") and _ismcfpersonalrequest == False:
consolidated_redactions = []
for entry in redactionsummary['data']:
consolidated_redactions += entry['sections']
Expand Down Expand Up @@ -350,6 +350,8 @@ def generate_text(self, range_result):
def __getredactionlayerid(self, message):
if message.category == "responsepackage":
return documentpageflag().getrecentredactionlayerid(message.ministryrequestid)
elif message.category == "openinfo":
return 1 # openinfo uses summary from redline layer
return message.redactionlayerid

def __getdeletedpages(self, ministryid, ordereddocids):
Expand Down Expand Up @@ -410,7 +412,7 @@ def __format_redaction_summary(self, pageflag, pageredactions, category):
range_sections = currentpg["sections"] if range_start == 0 else range_sections
range_start = currentpg["stitchedpageno"] if range_start == 0 else range_start
range_consults = currentpg["consults"]
skipconsult = True if category in ('oipcreviewredline','responsepackage', 'CFD_responsepackage') else False
skipconsult = True if category in ('oipcreviewredline','responsepackage', 'CFD_responsepackage', 'openinfo') else False
if currentpg["stitchedpageno"]+1 == nextpg["stitchedpageno"] and (skipconsult == True or (skipconsult == False and currentpg["consults"] == nextpg["consults"])):
range_sections.extend(nextpg["sections"])
range_end = nextpg["stitchedpageno"]
Expand Down Expand Up @@ -459,15 +461,15 @@ def __get_pages_by_flagid(self, _docpageflags, deletedpages, totalpages, flagid,

def __get_skippagenos(self, _docpageflags, category):
skippages = []
if category in ['responsepackage', 'CFD_responsepackage', 'oipcreviewredline']:
if category in ['responsepackage', 'CFD_responsepackage', 'oipcreviewredline', 'openinfo']:
for x in _docpageflags:
if x['flagid'] in (5,6) and x['page'] not in skippages:
skippages.append(x['page'])
return skippages

def __calcstitchedpageno(self, pageno, totalpages, category, skippages, deletedpages):
skipcount = 0
if category in ["responsepackage", 'CFD_responsepackage', 'oipcreviewredline']:
if category in ["responsepackage", 'CFD_responsepackage', 'oipcreviewredline', "openinfo"]:
skipcount = self.__calculateskipcount(pageno, skippages)
skipcount = self.__calculateskipcount(pageno, deletedpages, skipcount)
return (pageno+totalpages)-skipcount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def processmessage(self,incomingmessage):
#Condition for handling oipcredline category
bcgovcode= message.bcgovcode
requesttype = message.requesttype
if bcgovcode == 'mcf' and requesttype == 'personal' and category == 'responsepackage':
if bcgovcode == 'mcf' and requesttype == 'personal' and category in ('responsepackage', 'openinfo'):
documenttypename= 'CFD_responsepackage_redaction_summary'
else:
documenttypename= category+"_redaction_summary" if category == 'responsepackage' else "redline_redaction_summary"
documenttypename= "responsepackage_redaction_summary" if category in ('responsepackage', 'openinfo') else "redline_redaction_summary"
print('\n 2. documenttypename', documenttypename)
upload_responses=[]
pageflags = self.__get_pageflags(category)
Expand All @@ -49,11 +49,11 @@ def processmessage(self,incomingmessage):
divisioname = None
if len(messageattributes)>1:
filesobj=(next(item for item in messageattributes if item['divisionid'] == divisionid))['files'][0]
divisioname=(next(item for item in messageattributes if item['divisionid'] == divisionid))['divisionname'] if category not in ('responsepackage','oipcreviewredline') else None
divisioname=(next(item for item in messageattributes if item['divisionid'] == divisionid))['divisionname'] if category not in ('responsepackage','oipcreviewredline', 'openinfo') else None

else:
filesobj= messageattributes[0]['files'][0]
divisioname = messageattributes[0]['divisionname'] if category not in ('responsepackage','oipcreviewredline') else None
divisioname = messageattributes[0]['divisionname'] if category not in ('responsepackage','oipcreviewredline', 'openinfo') else None

stitcheddocs3uri = filesobj['s3uripath']
stitcheddocfilename = filesobj['filename']
Expand Down Expand Up @@ -84,8 +84,10 @@ def processmessage(self,incomingmessage):

def __get_summaryfilename(self, requestnumber, category, divisionname, stitcheddocfilename):
stitchedfilepath = stitcheddocfilename[:stitcheddocfilename.rfind( '/')+1]
if category == 'responsepackage':
if category in 'responsepackage':
_filename = requestnumber
elif category == 'openinfo':
return "Redaction_Summary_" + requestnumber + ".pdf"
elif category == 'oipcreviewredline':
_filename = requestnumber+ ' - Redline'
else:
Expand All @@ -96,7 +98,7 @@ def __get_summaryfilename(self, requestnumber, category, divisionname, stitchedd
return stitchedfilepath+_filename+" - summary.pdf"

def __get_pageflags(self, category):
if category == "responsepackage":
if category in ("responsepackage", "openinfo"):
return documentpageflag().get_all_pageflags(['Consult', 'Not Responsive', 'Duplicate'])
return documentpageflag().get_all_pageflags(['Consult'])

Expand Down
3 changes: 0 additions & 3 deletions web/src/components/FOI/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,6 @@ function Home() {

//useEffect to manage and apply oipc layer to current layer
useEffect(() => {
/** TODO: CHECK with SARAH for OI Analyst group details!
* ADD condition for valid OIlayer exists check as well
*/
const oiLayer = redactionLayers.find((layer) => layer.name === "Open Info")
if(user && user?.groups?.includes("/OI Team") && oiLayer?.count > 0){
store.dispatch(setCurrentLayer(oiLayer));
Expand Down
9 changes: 8 additions & 1 deletion web/src/helper/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ const isIntakeTeam = (userGroups: any) => {
);
};

const isOITeam = (userGroups : any) => {
return (
userGroups?.map((userGroup : any) => userGroup.replace("/", "")).indexOf("OI Team") !== -1
);
}

const encrypt = (obj: any) => {
return CryptoJS.AES.encrypt(
JSON.stringify(obj),
Expand Down Expand Up @@ -202,5 +208,6 @@ export {
isIntakeTeam,
encrypt,
decrypt,
warningToast
warningToast,
isOITeam
};
2 changes: 2 additions & 0 deletions web/src/services/UserService.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
isProcessingTeam,
isIntakeTeam,
isFlexTeam,
isOITeam,
} from "../helper/helper";

const tokenRefreshInterval = 180000; // how often we should check for token expiry --> 180000 = 3 mins
Expand Down Expand Up @@ -48,6 +49,7 @@ const initKeycloak = (store, ...rest) => {
isIntakeTeam(userGroups) ||
isFlexTeam(userGroups) ||
isProcessingTeam(userGroups) ||
isOITeam(userGroups) ||
isMinistryLogin(userGroups);
store.dispatch(setUserAuthorization(authorized));
});
Expand Down

0 comments on commit 33d2ed5

Please sign in to comment.