Skip to content

Commit

Permalink
Remove notices sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
samhotep committed Jun 12, 2024
1 parent 4db1684 commit 95ac3c1
Showing 1 changed file with 11 additions and 36 deletions.
47 changes: 11 additions & 36 deletions webapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 93 in webapp/views.py

View check run for this annotation

Codecov / codecov/patch

webapp/views.py#L93

Added line #L93 was not covered by tests
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":
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
),
)
)
Expand All @@ -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,
)

Expand All @@ -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)

Expand All @@ -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()
Expand 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()

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 95ac3c1

Please sign in to comment.