Skip to content

Commit

Permalink
Merge pull request #1209 from bcgov/test-marshal-merge-FOIMOD-3574
Browse files Browse the repository at this point in the history
Dev-Marshal <> Test-Marshal Merge
  • Loading branch information
JieunSon96 authored Nov 6, 2024
2 parents 5c150fa + f8f6776 commit 5cf5a93
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 2 deletions.
101 changes: 101 additions & 0 deletions api/reviewer_api/models/AnnotationSections.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,107 @@ def getredactedsectionsbyrequest(cls, ministryrequestid, redactionlayerid):
finally:
db.session.close()

@classmethod
def getredactedpagebyrequest(cls, ministryrequestid):
mapping = []
try:
sql = """
SELECT d.foiministryrequestid, d.documentmasterid, d.pagecount, dp.pageflag, dp.created_at from public."Documents" d
JOIN public."DocumentMaster" dm ON dm.documentmasterid = d.documentmasterid AND dm.ministryrequestid = :ministryrequestid
LEFT JOIN public."DocumentDeleted" dd ON dm.filepath ILIKE dd.filepath || '%' AND dd.ministryrequestid = dm.ministryrequestid
LEFT JOIN public."DocumentPageflags" dp ON dp.documentid = d.documentid
WHERE (dd.deleted IS NULL OR dd.deleted = FALSE)
"""
rs = db.session.execute(text(sql), {"ministryrequestid": ministryrequestid})

for row in rs:
pageflags = row["pageflag"]
if isinstance(pageflags, str):
try:
pageflags = json.loads(pageflags)
except json.JSONDecodeError as ex:
print(f"JSON decode error for pageflag: {ex}")
pageflags = []

# Convert created_at to desired format
created_at_str = row["created_at"].strftime("%Y-%m-%d %H:%M:%S") if row["created_at"] else None

mapping.append(
{
"foiministryrequestid": row["foiministryrequestid"],
"documentmasterid": row["documentmasterid"],
"pagecount": row["pagecount"],
"foiministryrequestid": row["foiministryrequestid"],
"pageflag": pageflags,
"created_at": created_at_str,
}
)
except Exception as ex:
logging.error(ex)
finally:
db.session.close()
return mapping

@classmethod
def getdocumentpageflagbyrequest(cls, ministryrequestid):
mapping = []
try:
sql = """
WITH pageflag_data AS (
SELECT
jsonb_array_elements(pageflag::jsonb) AS pageflag_item,
created_at
FROM public."DocumentPageflags"
WHERE foiministryrequestid = :ministryrequestid
),
program_area_pages AS (
SELECT
(jsonb_array_elements(pageflag_item->'programareaid')::text)::int AS consultation_number,
(pageflag_item->>'page')::int AS consultation_page_count,
created_at AS consultation_date
FROM
pageflag_data
),
aggregated_pages AS (
SELECT
consultation_number,
SUM(consultation_page_count) AS consultation_page_count,
MIN(consultation_date) AS consultation_date
FROM
program_area_pages
GROUP BY
consultation_number
)
SELECT
pa.name AS consultation_name,
ap.consultation_page_count,
ap.consultation_date
FROM
aggregated_pages ap
JOIN
public."ProgramAreas" pa ON ap.consultation_number = pa.programareaid
ORDER BY
consultation_name;
"""
rs = db.session.execute(text(sql), {"ministryrequestid": ministryrequestid})

for row in rs:
consultation_name = row["consultation_name"]
consultation_page_count = row["consultation_page_count"]
consultation_date = row["consultation_date"].strftime("%Y-%m-%d %H:%M:%S") if row["consultation_date"] else None

mapping.append(
{
"consultation_name": consultation_name,
"consultation_page_count": consultation_page_count,
"consultation_date": consultation_date,
}
)
except Exception as ex:
logging.error(ex)
finally:
db.session.close()
return mapping

class AnnotationSectionSchema(ma.Schema):
class Meta:
Expand Down
35 changes: 35 additions & 0 deletions api/reviewer_api/resources/redaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,42 @@ def get(ministryrequestid):
return json.dumps(data), 200
except BusinessException as exception:
return {"status": exception.status_code, "message": exception.message}, 500

@cors_preflight("GET,OPTIONS")
@API.route("/documentpage/ministryrequest/<int:ministryrequestid>")
class GetRedactedDocumentPages(Resource):
"""get document data"""

@staticmethod
@TRACER.trace()
@cross_origin(origins=allowedorigins())
@auth.require
def get(ministryrequestid):
try:
data = annotationservice().getredactedpagebyrequest(ministryrequestid)
return json.dumps(data), 200
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

@cors_preflight("GET,OPTIONS")
@API.route("/documentpageflags/ministryrequest/<int:ministryrequestid>")
class GetRedactedPageFlags(Resource):
"""get document flag data"""

@staticmethod
@TRACER.trace()
@cross_origin(origins=allowedorigins())
@auth.require
def get(ministryrequestid):
try:
data = annotationservice().getdocumentpageflagbyrequest(ministryrequestid)
return json.dumps(data), 200
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

@cors_preflight("GET,OPTIONS")
@API.route("/account")
Expand Down
8 changes: 8 additions & 0 deletions api/reviewer_api/services/annotationservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ def getredactedsectionsbyrequest(self, ministryrequestid):
sections[layer["name"]] = redactedsections
return sections

def getredactedpagebyrequest(self, ministryrequestid):
data = AnnotationSection.getredactedpagebyrequest(ministryrequestid)
return {"data": data}

def getdocumentpageflagbyrequest(self, ministryrequestid):
data = AnnotationSection.getdocumentpageflagbyrequest(ministryrequestid)
return {"data": data}

def getannotationsections(self, ministryid, redactionlayerid):
annotationsections = AnnotationSection.get_by_ministryid(ministryid, redactionlayerid)
return annotationsections
Expand Down
7 changes: 5 additions & 2 deletions web/src/components/FOI/Home/Redlining.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,13 +804,18 @@ const Redlining = React.forwardRef(
// from the server or individual changes from other users


/**Fix for lengthy section cutoff issue with response pkg
* download - changed overlaytext to freetext annotations after
* redaction applied*/

/**Fix for lengthy section cutoff issue with response pkg
* download - changed overlaytext to freetext annotations after
* redaction applied*/
if (info['source'] === 'redactionApplied') {
annotations.forEach((annotation) => {
if(annotation.Subject == "Free Text"){
docInstance?.Core?.annotationManager.addAnnotation(annotation);
docInstance?.Core?.annotationManager.addAnnotation(annotation);
}
});
}
Expand All @@ -825,8 +830,6 @@ const Redlining = React.forwardRef(
info.source !== "redactionApplied" &&
info.source !== "cancelRedaction"
) {


//ignore annots/redact changes made by applyRedaction
if (info.imported) return;
//do not run if redline is saving
Expand Down

0 comments on commit 5cf5a93

Please sign in to comment.