From 66822781d91a8fa34a974c7c2ee9a5ac9021ee75 Mon Sep 17 00:00:00 2001 From: Sylvia van Os Date: Tue, 1 Jun 2021 19:30:51 +0200 Subject: [PATCH] Made requested changes --- app/models.py | 4 ++-- cron.py | 6 +++--- ...8614d64d1c_.py => 2021_060119_4d501f682763_.py} | 14 ++++++++------ .../emails/transactional/hibp-new-breaches.html | 2 +- .../emails/transactional/hibp-new-breaches.txt | 2 +- 5 files changed, 15 insertions(+), 13 deletions(-) rename migrations/versions/{2021_052419_618614d64d1c_.py => 2021_060119_4d501f682763_.py} (77%) diff --git a/app/models.py b/app/models.py index 07d14976..5afe5f2e 100644 --- a/app/models.py +++ b/app/models.py @@ -164,7 +164,7 @@ class AliasGeneratorEnum(EnumE): class HibpDataClass(db.Model, ModelMixin): __tablename__ = "hibpdataclass" - description = db.Column(db.Text, nullable=False, unique=True, index=True) + attribute = db.Column(db.Text, nullable=False, unique=True, index=True) breaches = db.relationship("Hibp", secondary="hibp_hibpdataclass") @@ -2089,7 +2089,7 @@ class HibpHibpDataClass(db.Model, ModelMixin): ), ) - hibp_id = db.Column(db.Integer(), db.ForeignKey("hibp.id")) + hibp_id = db.Column(db.Integer(), db.ForeignKey("hibp.id"), index=True) hibp_dataclass_id = db.Column(db.Integer(), db.ForeignKey("hibpdataclass.id")) hibp = db.relationship( diff --git a/cron.py b/cron.py index 88160588..3f2f8ef5 100644 --- a/cron.py +++ b/cron.py @@ -842,7 +842,7 @@ async def check_hibp(): LOG.d("Updating list of known breach types") r = requests.get("https://haveibeenpwned.com/api/v3/dataclasses") for entry in r.json(): - HibpDataClass.get_or_create(description=entry) + HibpDataClass.get_or_create(attribute=entry) db.session.commit() @@ -853,8 +853,8 @@ async def check_hibp(): hibp_entry.date = arrow.get(entry["BreachDate"]) hibp_entry.description = entry["Description"] hibp_entry.data_classes = [ - HibpDataClass.get_by(description=description) - for description in entry["DataClasses"] + HibpDataClass.get_by(attribute=attribute) + for attribute in entry["DataClasses"] ] db.session.commit() diff --git a/migrations/versions/2021_052419_618614d64d1c_.py b/migrations/versions/2021_060119_4d501f682763_.py similarity index 77% rename from migrations/versions/2021_052419_618614d64d1c_.py rename to migrations/versions/2021_060119_4d501f682763_.py index 31cf5d58..82a1c8df 100644 --- a/migrations/versions/2021_052419_618614d64d1c_.py +++ b/migrations/versions/2021_060119_4d501f682763_.py @@ -1,8 +1,8 @@ """empty message -Revision ID: 618614d64d1c +Revision ID: 4d501f682763 Revises: 6cc7f073b358 -Create Date: 2021-05-24 19:44:26.161445 +Create Date: 2021-06-01 19:30:15.904980 """ import sqlalchemy_utils @@ -11,7 +11,7 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. -revision = '618614d64d1c' +revision = '4d501f682763' down_revision = '6cc7f073b358' branch_labels = None depends_on = None @@ -23,10 +23,10 @@ def upgrade(): sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), sa.Column('created_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=False), sa.Column('updated_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=True), - sa.Column('description', sa.Text(), nullable=False), + sa.Column('attribute', sa.Text(), nullable=False), sa.PrimaryKeyConstraint('id') ) - op.create_index(op.f('ix_hibpdataclass_description'), 'hibpdataclass', ['description'], unique=True) + op.create_index(op.f('ix_hibpdataclass_attribute'), 'hibpdataclass', ['attribute'], unique=True) op.create_table('hibp_hibpdataclass', sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), sa.Column('created_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=False), @@ -38,6 +38,7 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('hibp_id', 'hibp_dataclass_id', name='uq_hibp_hibpdataclass') ) + op.create_index(op.f('ix_hibp_hibpdataclass_hibp_id'), 'hibp_hibpdataclass', ['hibp_id'], unique=False) op.add_column('hibp', sa.Column('date', sqlalchemy_utils.types.arrow.ArrowType(), nullable=True)) op.add_column('hibp', sa.Column('description', sa.Text(), nullable=True)) # ### end Alembic commands ### @@ -47,7 +48,8 @@ def downgrade(): # ### commands auto generated by Alembic - please adjust! ### op.drop_column('hibp', 'description') op.drop_column('hibp', 'date') + op.drop_index(op.f('ix_hibp_hibpdataclass_hibp_id'), table_name='hibp_hibpdataclass') op.drop_table('hibp_hibpdataclass') - op.drop_index(op.f('ix_hibpdataclass_description'), table_name='hibpdataclass') + op.drop_index(op.f('ix_hibpdataclass_attribute'), table_name='hibpdataclass') op.drop_table('hibpdataclass') # ### end Alembic commands ### diff --git a/templates/emails/transactional/hibp-new-breaches.html b/templates/emails/transactional/hibp-new-breaches.html index 9b0a6737..77f97544 100644 --- a/templates/emails/transactional/hibp-new-breaches.html +++ b/templates/emails/transactional/hibp-new-breaches.html @@ -18,7 +18,7 @@ {{ render_text(breach.name + " (" + breach.date.format('YYYY-MM-DD') + ")") }} {{ render_text(breach.description) }} - {{ render_text("Breached data: " + breach.data_classes|join(', ', attribute='description')) }} + {{ render_text("Breached data: " + breach.data_classes|join(', ', attribute='attribute')) }} {%- endif %} {%- endfor %} {%- endif %} diff --git a/templates/emails/transactional/hibp-new-breaches.txt b/templates/emails/transactional/hibp-new-breaches.txt index d9e81cc5..03db98db 100644 --- a/templates/emails/transactional/hibp-new-breaches.txt +++ b/templates/emails/transactional/hibp-new-breaches.txt @@ -18,7 +18,7 @@ And {{ (alias.hibp_breaches_not_notified_user|length) - 3 }} more data breaches. {{ breach.name }} ({{ breach.date.format('YYYY-MM-DD') }}) {{ breach.description|striptags }} -Breached data: {{ breach.data_classes|join(', ', attribute='description') }} +Breached data: {{ breach.data_classes|join(', ', attribute='attribute') }} {%- endif %} {%- endfor %} {%- endif %}