diff --git a/webapp/views.py b/webapp/views.py index 2321000..b20c8aa 100644 --- a/webapp/views.py +++ b/webapp/views.py @@ -90,13 +90,9 @@ def get_cves(**kwargs): # query cves by filters. Default filter by active CVEs if cve_status: - cves_query: Query = db.session.query(CVE).filter( - CVE.status == cve_status - ) + cves_query: Query = db.session.query(CVE).filter(CVE.status == cve_status) else: - cves_query: Query = db.session.query(CVE).filter( - CVE.status == "active" - ) + cves_query: Query = db.session.query(CVE).filter(CVE.status == "active") # order by priority if group_by == "priority": @@ -133,9 +129,7 @@ def get_cves(**kwargs): ) # filter the CVEs that fulfill criteria - cves_query = cves_query.filter( - CVE.statuses.any(or_(*[p for p in parameters])) - ) + cves_query = cves_query.filter(CVE.statuses.any(or_(*[p for p in parameters]))) else: # If an empty string is provided for the status, @@ -250,9 +244,7 @@ def bulk_upsert_cve(*args, **kwargs): update_cve = True cve.status = data.get("status") - published_date = ( - cve.published.strftime("%Y-%B-%d") if cve.published else None - ) + published_date = cve.published.strftime("%Y-%B-%d") if cve.published else None data_published_date = ( dateutil.parser.parse(data.get("published")).strftime("%Y-%B-%d") if data.get("published") @@ -382,9 +374,7 @@ def get_notice(notice_id, **kwargs): selectinload(Notice.cves).options( selectinload(CVE.statuses), selectinload(CVE.notices).options( - load_only( - Notice.id, Notice.is_hidden, Notice.release_packages - ) + load_only(Notice.id, Notice.is_hidden, Notice.release_packages) ), ) ) @@ -394,9 +384,7 @@ def get_notice(notice_id, **kwargs): if not notice: return make_response( - jsonify( - {"message": f"Notice with id '{notice_id}' does not exist"} - ), + jsonify({"message": f"Notice with id '{notice_id}' does not exist"}), 404, ) @@ -412,7 +400,6 @@ def get_notices(**kwargs): release = kwargs.get("release") limit = kwargs.get("limit", 20) offset = kwargs.get("offset", 0) - order_by = kwargs.get("order") notices_query: Query = db.session.query(Notice) @@ -437,21 +424,16 @@ def get_notices(**kwargs): ) ) - sort = asc if order_by == "oldest" else desc - notices = ( notices_query.options( selectinload(Notice.cves).options( selectinload(CVE.statuses), selectinload(CVE.notices).options( - load_only( - Notice.id, Notice.is_hidden, Notice.release_packages - ) + load_only(Notice.id, Notice.is_hidden, Notice.release_packages) ), ) ) .options(selectinload(Notice.releases)) - .order_by(sort(Notice.published), sort(Notice.id)) .offset(offset) .limit(limit) .all() @@ -472,9 +454,7 @@ def get_notices(**kwargs): def create_notice(**kwargs): notice_data = request.json - db.session.add( - _update_notice_object(Notice(id=notice_data["id"]), notice_data) - ) + db.session.add(_update_notice_object(Notice(id=notice_data["id"]), notice_data)) db.session.commit() @@ -518,9 +498,7 @@ def delete_notice(notice_id): db.session.delete(notice) db.session.commit() - return make_response( - jsonify({"message": f"Notice {notice_id} deleted"}), 200 - ) + return make_response(jsonify({"message": f"Notice {notice_id} deleted"}), 200) @marshal_with(ReleaseAPISchema, code=200) @@ -663,9 +641,7 @@ def _sort_by_priority(cves_query): return cves_query -def _params_with_conditions( - versions, statuses, parameters, package, component -): +def _params_with_conditions(versions, statuses, parameters, package, component): conditions = [] clean_versions = _get_clean_versions(versions) @@ -812,8 +788,7 @@ def _update_notice_object(notice, data): notice.is_hidden = strtobool(data.get("is_hidden", "false")) notice.releases = [ - Release.query.get(codename) - for codename in data["release_packages"].keys() + Release.query.get(codename) for codename in data["release_packages"].keys() ] notice.cves.clear()