Skip to content

Commit 8c3a67c

Browse files
Merge pull request #897 from bcgov/dev-rook-sync-20240320
Dev rook sync 20240320
2 parents a813532 + 2a84382 commit 8c3a67c

File tree

150 files changed

+5313
-4833
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+5313
-4833
lines changed

.github/workflows/zap-scan.yml

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
branches:
88
- dev
99
- dev-ac-1398
10+
- dev-RQ-3026
1011

1112
workflow_dispatch:
1213
inputs:
@@ -26,7 +27,7 @@ jobs:
2627
name: Scan the frontend
2728
steps:
2829
- name: ZAP Scan
29-
uses: zaproxy/action-full-scan@v0.4.0
30+
uses: zaproxy/action-full-scan@v0.9.0
3031
with:
3132
allow_issue_writing: false
3233
token: ${{ secrets.GITHUB_TOKEN }}
@@ -39,7 +40,7 @@ jobs:
3940
name: Scan the forms frontend
4041
steps:
4142
- name: ZAP Scan
42-
uses: zaproxy/action-full-scan@v0.4.0
43+
uses: zaproxy/action-full-scan@v0.9.0
4344
with:
4445
allow_issue_writing: false
4546
token: ${{ secrets.GITHUB_TOKEN }}
@@ -51,22 +52,22 @@ jobs:
5152
name: Scan the reviewer frontend
5253
steps:
5354
- name: ZAP Scan
54-
uses: zaproxy/action-full-scan@v0.4.0
55+
uses: zaproxy/action-full-scan@v0.9.0
5556
with:
5657
allow_issue_writing: false
5758
token: ${{ secrets.GITHUB_TOKEN }}
5859
issue_title: 'ZAP Scan Report'
59-
target: ${{ secrets.ZAP_SCAN_REVIEWER_URL }}
60+
target: ${{ secrets.ZAP_SCAN_REVIEWER_URL_DEV }}
6061

6162

6263
zap_scan_backend:
6364
runs-on: ubuntu-latest
6465
name: Scan the backend
6566
steps:
6667
- name: ZAP Scan
67-
uses: zaproxy/action-api-scan@v0.2.0
68+
uses: zaproxy/action-api-scan@v0.6.0
6869
with:
6970
allow_issue_writing: false
7071
token: ${{ secrets.GITHUB_TOKEN }}
7172
issue_title: 'ZAP Scan Report'
72-
target: ${{ secrets.ZAP_SCAN_BACKEND_URL }}
73+
target: ${{ secrets.ZAP_SCAN_BACKEND_URL_DEV }}
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,149 @@
1-

2-
using Serilog;
1+

2+
using Serilog;
33
using Syncfusion.DocIO.DLS;
4-
using Syncfusion.DocIO;
5-
using Syncfusion.DocIORenderer;
4+
using Syncfusion.DocIO;
5+
using Syncfusion.DocIORenderer;
66
using Syncfusion.Pdf;
77
using DocumentFormat.OpenXml.Packaging;
8-
using DocumentFormat.OpenXml.Wordprocessing;
9-
10-
11-
12-
namespace MCS.FOI.DocToPDF
13-
{
14-
public class DocFileProcessor : IDocFileProcessor, IDisposable
15-
{
16-
17-
18-
public DocFileProcessor() { }
19-
20-
public DocFileProcessor(Stream SourceStream)
21-
{
22-
this.SourceStream = SourceStream;
23-
}
24-
25-
public Stream SourceStream { get; set; }
26-
27-
public int FailureAttemptCount { get; set; }
28-
29-
public int WaitTimeinMilliSeconds { get; set; }
30-
31-
public bool IsSinglePDFOutput { get; set; }
32-
33-
34-
private MemoryStream? output = null;
35-
public (bool, Stream) ConvertToPDF()
36-
{
37-
bool converted = false;
38-
string message = string.Empty;
39-
bool _isSinglePDFOutput = IsSinglePDFOutput;
40-
output = new MemoryStream();
41-
try
42-
{
43-
for (int attempt = 1; attempt <= FailureAttemptCount && !converted; attempt++)
44-
{
45-
try
46-
{
47-
using (WordDocument wordDocument = new WordDocument(SourceStream, Syncfusion.DocIO.FormatType.Automatic))
48-
{
49-
SourceStream.Position = 0;
50-
51-
using (var docXML = WordprocessingDocument.Open(SourceStream, false))
52-
{
8+
using DocumentFormat.OpenXml.Wordprocessing;
539

54-
DocumentFormat.OpenXml.Wordprocessing.Body body = docXML.MainDocumentPart.Document.Body;
55-
List<String> originalDates = new List<String>();
56-
foreach (var textItem in body.Descendants<FieldCode>().Where(textItem => textItem.Text.Contains("DATE")))
57-
{
58-
var datetext = textItem.Parent.NextSibling().NextSibling();
59-
originalDates.Add(datetext.InnerText);
60-
}
6110

62-
List<Entity> datefields = wordDocument.FindAllItemsByProperty(EntityType.Field, "FieldType", FieldType.FieldDate.ToString());
63-
foreach (var (datefield, i) in datefields.Select((datefield, i) => (datefield, i)))
11+
12+
namespace MCS.FOI.DocToPDF
13+
{
14+
public class DocFileProcessor : IDocFileProcessor, IDisposable
15+
{
16+
17+
18+
public DocFileProcessor() { }
19+
20+
public DocFileProcessor(Stream SourceStream)
21+
{
22+
this.SourceStream = SourceStream;
23+
}
24+
25+
public Stream SourceStream { get; set; }
26+
27+
public int FailureAttemptCount { get; set; }
28+
29+
public int WaitTimeinMilliSeconds { get; set; }
30+
31+
public bool IsSinglePDFOutput { get; set; }
32+
33+
34+
private MemoryStream? output = null;
35+
public (bool, Stream) ConvertToPDF()
36+
{
37+
bool converted = false;
38+
string message = string.Empty;
39+
bool _isSinglePDFOutput = IsSinglePDFOutput;
40+
output = new MemoryStream();
41+
try
42+
{
43+
for (int attempt = 1; attempt <= FailureAttemptCount && !converted; attempt++)
44+
{
45+
try
46+
{
47+
using (WordDocument wordDocument = new WordDocument(SourceStream, Syncfusion.DocIO.FormatType.Automatic))
48+
{
49+
SourceStream.Position = 0;
50+
51+
if (wordDocument.ActualFormatType == FormatType.Docx)
52+
{
53+
using (var docXML = WordprocessingDocument.Open(SourceStream, false))
6454
{
65-
var dateField = datefield as WField;
66-
//Takes the owner paragraph.
67-
WParagraph ownerPara = dateField.OwnerParagraph;
68-
int dateFieldIndex = ownerPara.ChildEntities.IndexOf(dateField);
69-
//Removes the date field.
70-
ownerPara.ChildEntities.Remove(dateField);
71-
//Creating a new text range with required date.
72-
WTextRange textRange = new WTextRange(ownerPara.Document);
73-
textRange.Text = originalDates[i];//"February 12, 2023";
74-
//Inserting the date field with the created text range.
75-
ownerPara.ChildEntities.Insert(dateFieldIndex, textRange);
55+
56+
DocumentFormat.OpenXml.Wordprocessing.Body body = docXML.MainDocumentPart.Document.Body;
57+
List<String> originalDates = new List<String>();
58+
foreach (var textItem in body.Descendants<FieldCode>().Where(textItem => textItem.Text.Contains("DATE")))
59+
{
60+
var datetext = textItem.Parent.NextSibling().NextSibling();
61+
originalDates.Add(datetext.InnerText);
62+
}
63+
64+
List<Entity> datefields = wordDocument.FindAllItemsByProperty(EntityType.Field, "FieldType", FieldType.FieldDate.ToString());
65+
if (datefields != null)
66+
{
67+
foreach (var (datefield, i) in datefields.Select((datefield, i) => (datefield, i)))
68+
{
69+
var dateField = datefield as WField;
70+
//Takes the owner paragraph.
71+
WParagraph ownerPara = dateField.OwnerParagraph;
72+
int dateFieldIndex = ownerPara.ChildEntities.IndexOf(dateField);
73+
//Removes the date field.
74+
ownerPara.ChildEntities.Remove(dateField);
75+
//Creating a new text range with required date.
76+
WTextRange textRange = new WTextRange(ownerPara.Document);
77+
textRange.Text = originalDates[i];//"February 12, 2023";
78+
//Inserting the date field with the created text range.
79+
ownerPara.ChildEntities.Insert(dateFieldIndex, textRange);
80+
}
81+
}
7682
}
7783
}
7884

79-
wordDocument.RevisionOptions.CommentDisplayMode = CommentDisplayMode.ShowInBalloons;
80-
wordDocument.RevisionOptions.CommentColor = RevisionColor.Blue;
81-
wordDocument.RevisionOptions.ShowMarkup = RevisionType.Deletions | RevisionType.Insertions;
82-
83-
using (DocIORenderer renderer = new DocIORenderer())
84-
{
85-
using PdfDocument pdfDocument = renderer.ConvertToPDF(wordDocument);
86-
//Save the PDF file
87-
//Close the instance of document objects
88-
pdfDocument.Save(output);
89-
pdfDocument.Close(true);
90-
converted = true;
91-
92-
}
93-
94-
}
95-
}
96-
catch (Exception e)
97-
{
98-
string errorMessage = $"Exception occured while coverting a document file, exception : {e.Message}";
99-
message = $"Exception happened while accessing File, re-attempting count : {attempt} , Error Message : {e.Message} , Stack trace : {e.StackTrace}";
100-
Log.Error(message);
101-
Console.WriteLine(message);
102-
if (attempt == FailureAttemptCount)
103-
{
104-
throw new Exception(errorMessage);
105-
}
106-
Thread.Sleep(WaitTimeinMilliSeconds);
107-
}
108-
}
109-
}
110-
catch (Exception ex)
111-
{
112-
converted = false;
113-
string error = $"Exception occured while coverting Doc file, exception : {ex.Message} , stacktrace : {ex.StackTrace}";
114-
Log.Error(error);
115-
Console.WriteLine(error);
116-
throw;
117-
}
118-
return (converted, output);
119-
}
120-
121-
public void Dispose()
122-
{
123-
Dispose(true);
124-
GC.SuppressFinalize(this);
125-
}
126-
127-
protected virtual void Dispose(bool disposing)
128-
{
129-
if (disposing)
130-
{
131-
if (this.SourceStream != null)
132-
{
133-
this.SourceStream.Close();
134-
this.SourceStream.Dispose();
135-
}
136-
137-
if (output != null) output.Dispose();
138-
// free managed resources
139-
}
140-
141-
}
142-
}
143-
}
85+
wordDocument.RevisionOptions.CommentDisplayMode = CommentDisplayMode.ShowInBalloons;
86+
wordDocument.RevisionOptions.CommentColor = RevisionColor.Blue;
87+
wordDocument.RevisionOptions.ShowMarkup = RevisionType.Deletions | RevisionType.Insertions;
88+
89+
using (DocIORenderer renderer = new DocIORenderer())
90+
{
91+
using PdfDocument pdfDocument = renderer.ConvertToPDF(wordDocument);
92+
//Save the PDF file
93+
//Close the instance of document objects
94+
pdfDocument.Save(output);
95+
pdfDocument.Close(true);
96+
converted = true;
97+
98+
}
99+
100+
}
101+
}
102+
catch (Exception e)
103+
{
104+
string errorMessage = $"Exception occured while coverting a document file, exception : {e.Message}";
105+
message = $"Exception happened while accessing File, re-attempting count : {attempt} , Error Message : {e.Message} , Stack trace : {e.StackTrace}";
106+
Log.Error(message);
107+
Console.WriteLine(message);
108+
if (attempt == FailureAttemptCount)
109+
{
110+
throw new Exception(errorMessage);
111+
}
112+
Thread.Sleep(WaitTimeinMilliSeconds);
113+
}
114+
}
115+
}
116+
catch (Exception ex)
117+
{
118+
converted = false;
119+
string error = $"Exception occured while coverting Doc file, exception : {ex.Message} , stacktrace : {ex.StackTrace}";
120+
Log.Error(error);
121+
Console.WriteLine(error);
122+
throw;
123+
}
124+
return (converted, output);
125+
}
126+
127+
public void Dispose()
128+
{
129+
Dispose(true);
130+
GC.SuppressFinalize(this);
131+
}
132+
133+
protected virtual void Dispose(bool disposing)
134+
{
135+
if (disposing)
136+
{
137+
if (this.SourceStream != null)
138+
{
139+
this.SourceStream.Close();
140+
this.SourceStream.Dispose();
141+
}
142+
143+
if (output != null) output.Dispose();
144+
// free managed resources
145+
}
146+
147+
}
148+
}
149+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""empty message
2+
3+
Revision ID: 7db1cd6f0b36
4+
Revises: 549893ea9059
5+
Create Date: 2024-03-15 13:30:30.604299
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '7db1cd6f0b36'
14+
down_revision = '549893ea9059'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.execute(
22+
'CREATE INDEX "idx_documentpgflag_multicolumn" ON "DocumentPageflags" (foiministryrequestid, documentid, documentversion, redactionlayerid);'
23+
)
24+
op.execute(
25+
'ALTER TABLE "DocumentPageflags" ADD CONSTRAINT "unique_documentpgflag" UNIQUE (foiministryrequestid, documentid, documentversion, redactionlayerid);'
26+
)
27+
# ### end Alembic commands ###
28+
29+
30+
def downgrade():
31+
# ### commands auto generated by Alembic - please adjust! ###
32+
op.execute('DROP INDEX "idx_documentpgflag_multicolumn";')
33+
op.execute('ALTER TABLE "DocumentPageflags" DROP CONSTRAINT "unique_documentpgflag";')
34+
# ### end Alembic commands ###

api/migrations/versions/c787e6d82903_PageCalculatorJob.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""empty message
22
33
Revision ID: c787e6d82903
4-
Revises: 549893ea9059
4+
Revises: e0e3a10b850d
55
Create Date: 2024-02-06 15:12:03.310271
66
77
"""
@@ -12,7 +12,7 @@
1212

1313
# revision identifiers, used by Alembic.
1414
revision = 'c787e6d82903'
15-
down_revision = '549893ea9059'
15+
down_revision = 'e0e3a10b850d'
1616
branch_labels = None
1717
depends_on = None
1818

0 commit comments

Comments
 (0)