diff --git a/app/api/serializer.py b/app/api/serializer.py index 2b150311..54e0d181 100644 --- a/app/api/serializer.py +++ b/app/api/serializer.py @@ -323,7 +323,11 @@ def get_alias_infos_with_pagination_v3( elif alias_filter == "disabled": q = q.filter(Alias.enabled.is_(False)) elif alias_filter == "hibp": - q = q.filter(or_(Alias.hibp_breaches_notified_user, Alias.hibp_breaches_not_notified_user)) + q = q.filter( + or_( + Alias.hibp_breaches_notified_user, Alias.hibp_breaches_not_notified_user + ) + ) q = q.order_by(Alias.pinned.desc()) diff --git a/app/models.py b/app/models.py index bae208b9..07d14976 100644 --- a/app/models.py +++ b/app/models.py @@ -2083,7 +2083,11 @@ class DomainMailbox(db.Model, ModelMixin): class HibpHibpDataClass(db.Model, ModelMixin): __tablename__ = "hibp_hibpdataclass" - __table_args__ = (db.UniqueConstraint("hibp_id", "hibp_dataclass_id", name="uq_hibp_hibpdataclass"),) + __table_args__ = ( + db.UniqueConstraint( + "hibp_id", "hibp_dataclass_id", name="uq_hibp_hibpdataclass" + ), + ) hibp_id = db.Column(db.Integer(), db.ForeignKey("hibp.id")) hibp_dataclass_id = db.Column(db.Integer(), db.ForeignKey("hibpdataclass.id")) @@ -2092,7 +2096,8 @@ class HibpHibpDataClass(db.Model, ModelMixin): "Hibp", backref=db.backref("hibp_hibpdataclass", cascade="all, delete-orphan") ) hibpdataclass = db.relationship( - "HibpDataClass", backref=db.backref("hibp_hibpdataclass", cascade="all, delete-orphan") + "HibpDataClass", + backref=db.backref("hibp_hibpdataclass", cascade="all, delete-orphan"), ) diff --git a/cron.py b/cron.py index c1651fe7..88160588 100644 --- a/cron.py +++ b/cron.py @@ -56,7 +56,7 @@ from app.models import ( DeletedAlias, DomainDeletedAlias, Hibp, - HibpDataClass + HibpDataClass, ) from app.utils import sanitize_email from server import create_app @@ -794,9 +794,7 @@ async def _hibp_check(api_key, queue): if r.status_code == 200: # Breaches found - breaches = [ - Hibp.get_by(name=entry["Name"]) for entry in r.json() - ] + breaches = [Hibp.get_by(name=entry["Name"]) for entry in r.json()] if len(alias.hibp_breaches) > 0: LOG.w("%s appears in HIBP breaches %s", alias, alias.hibp_breaches) elif r.status_code == 404: @@ -811,8 +809,16 @@ async def _hibp_check(api_key, queue): ) return - alias.hibp_breaches_not_notified_user = [breach for breach in breaches if breach not in alias.hibp_breaches_notified_user] - alias.hibp_breaches_notified_user = [breach for breach in breaches if breach not in alias.hibp_breaches_not_notified_user] + alias.hibp_breaches_not_notified_user = [ + breach + for breach in breaches + if breach not in alias.hibp_breaches_notified_user + ] + alias.hibp_breaches_notified_user = [ + breach + for breach in breaches + if breach not in alias.hibp_breaches_not_notified_user + ] alias.hibp_last_check = arrow.utcnow() db.session.add(alias) @@ -847,7 +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(description=description) + for description in entry["DataClasses"] ] db.session.commit() @@ -893,7 +900,11 @@ def notify_hibp(): Send aggregated email reports for HIBP breaches """ for user in User.query.all(): - new_breaches = Alias.query.filter(Alias.user_id == user.id).filter(Alias.hibp_breaches_not_notified_user).all() + new_breaches = ( + Alias.query.filter(Alias.user_id == user.id) + .filter(Alias.hibp_breaches_not_notified_user) + .all() + ) if len(new_breaches) == 0: return @@ -906,17 +917,20 @@ def notify_hibp(): render( "transactional/hibp-new-breaches.txt", user=user, - breached_aliases=new_breaches + breached_aliases=new_breaches, ), render( "transactional/hibp-new-breaches.html", user=user, - breached_aliases=new_breaches + breached_aliases=new_breaches, ), ) for alias in new_breaches: - alias.hibp_breaches_notified_user = alias.hibp_breaches_notified_user + alias.hibp_breaches_not_notified_user + alias.hibp_breaches_notified_user = ( + alias.hibp_breaches_notified_user + + alias.hibp_breaches_not_notified_user + ) alias.hibp_breaches_not_notified_user = [] db.session.add(alias) @@ -942,7 +956,7 @@ if __name__ == "__main__": "delete_old_monitoring", "check_custom_domain", "check_hibp", - "notify_hibp" + "notify_hibp", ], ) args = parser.parse_args() @@ -982,4 +996,4 @@ if __name__ == "__main__": asyncio.run(check_hibp()) elif args.job == "notify_hibp": LOG.d("Notify users with new HIBP breaches") - notify_hibp() \ No newline at end of file + notify_hibp()