Skip to content

Commit

Permalink
PDF report update:
Browse files Browse the repository at this point in the history
- fix broken AFFECTED SYSTEMS field (affected by later update)
- add suport for multiline in DESCRIPTION, AFFECTED SYSTEMS & RECOMMENDATIONS fields
  • Loading branch information
Jan Polonsky committed Feb 2, 2024
1 parent f48f021 commit 82915ee
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 13 deletions.
69 changes: 69 additions & 0 deletions src/core/migrations/versions/dfc12c30395b_Affected_systems.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""Affected systems to text area
Revision ID: dfc12c30395b
Revises: e87b34c74db0
Create Date: 2024-01-31 13:35:10.639848
"""
from alembic import op
from datetime import datetime
from sqlalchemy import orm, Column, ForeignKey, String, Integer, DateTime, Boolean, Enum, text
from sqlalchemy.ext.declarative import declarative_base
import sqlalchemy as sa

Base = declarative_base()

# revision identifiers, used by Alembic.
revision = 'dfc12c30395b'
down_revision = 'e87b34c74db0'
branch_labels = None
depends_on = None

class ReportItemType_dfc12c30395b(Base):
__tablename__ = 'report_item_type'
id = Column(Integer, primary_key=True, server_default=text("nextval('report_item_type_id_seq'::regclass)"))
title = Column(String)

class AttributeGroup_dfc12c30395b(Base):
__tablename__ = 'attribute_group'
id = Column(Integer, primary_key=True, server_default=text("nextval('attribute_group_id_seq'::regclass)"))
title = Column(String)
report_item_type_id = Column(ForeignKey('report_item_type.id'))

class AttributeGroupItem_dfc12c30395b(Base):
__tablename__ = 'attribute_group_item'
id = Column(Integer, primary_key=True, server_default=text("nextval('attribute_group_item_id_seq'::regclass)"))
title = Column(String)
attribute_group_id = Column(ForeignKey('attribute_group.id'))
attribute_id = Column(ForeignKey('attribute.id'))

class Attribute_dfc12c30395b(Base):
__tablename__ = 'attribute'
id = Column(Integer, primary_key=True, server_default=text("nextval('attribute_id_seq'::regclass)"))
name = Column(String, nullable=False)

def upgrade():
bind = op.get_bind()
session = orm.Session(bind=bind)

# ======= Update existing old report =======
rit = session.query(ReportItemType_dfc12c30395b).filter_by(title = 'Vulnerability Report').first()
if rit:
ag = session.query(AttributeGroup_dfc12c30395b).filter_by(title = 'Identify and Act', report_item_type_id = rit.id).first()
if ag:
atr_text_id = session.query(Attribute_dfc12c30395b).filter_by(name = 'Text').first().id
agi = session.query(AttributeGroupItem_dfc12c30395b).filter_by(title = 'Affected systems', attribute_group_id = ag.id, attribute_id = atr_text_id).first()
if agi:
atr_text_area_id = session.query(Attribute_dfc12c30395b).filter_by(name = 'Text Area').first().id
agi.attribute_id = atr_text_area_id
session.add(agi)
session.commit()
else:
print("Nothing to upgrade...", flush=True)
else:
print("No report attribute group to upgrade...", flush=True)
else:
print("No report to upgrade...", flush=True)

def downgrade():
pass
3 changes: 3 additions & 0 deletions src/presenters/templates/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ input {
.checkbox-button__control {
transform: scale(0.75)
}
.crlf {
white-space: pre-line;
}

/*FOOTER*/
.footer_text {
Expand Down
16 changes: 3 additions & 13 deletions src/presenters/templates/pdf_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@
<th class="th_data" style="color:white; background-color: #256ec2 !important">DESCRIPTION</th>
</tr>
<tr>
<td class="text-justify text_in_tab">
{{ report_item.attrs.description|e }}
</td>
<td class="text-justify text_in_tab crlf">{{ report_item.attrs.description|e }}</td>
</tr>
</table>

Expand Down Expand Up @@ -202,13 +200,7 @@
<th class="th_data" style="color:white; background-color: #256ec2 !important">AFFECTED SYSTEMS</th>
</tr>
<tr>
<td class="text-justify text_in_tab">
{% if report_item.attrs.affected_systems %}
{% for i in report_item.attrs.affected_systems %}
<div>{{ i|e }}</div>
{% endfor %}
{% endif %}
</td>
<td class="text-justify text_in_tab crlf">{{ report_item.attrs.affected_systems }}</td>
</tr>
</table>

Expand All @@ -217,9 +209,7 @@
<th class="th_data" style="color:white; background-color: #256ec2 !important">RECOMMENDATIONS</th>
</tr>
<tr>
<td class="text-justify text_in_tab">
{{ report_item.attrs.recommendations }}
</td>
<td class="text-justify text_in_tab crlf">{{ report_item.attrs.recommendations }}</td>
</tr>
</table>

Expand Down

0 comments on commit 82915ee

Please sign in to comment.