Skip to content

Commit

Permalink
fix: [website] date_from and date_to are no more set with a default v…
Browse files Browse the repository at this point in the history
…alue, it is up to the client to specify the values. The query of the dashboard are now specifying the value.
  • Loading branch information
cedricbonhomme committed Nov 26, 2024
1 parent dc5b473 commit 036ca3a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
22 changes: 8 additions & 14 deletions website/web/api/v1/sighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,6 @@ def get(self) -> Tuple[ResultType, int]:

if limit > 1000:
limit = 1000
if date_from is None:
if sighting_type == "confirmed":
date_from = (date.today() - relativedelta(days=30)).strftime("%Y-%m-%d")
else:
date_from = (date.today() - relativedelta(days=7)).strftime("%Y-%m-%d")
if date_to is None:
date_to = date.today().strftime("%Y-%m-%d")

result: ResultType = {
"data": [],
Expand All @@ -184,13 +177,14 @@ def get(self) -> Tuple[ResultType, int]:
query = query.filter(Sighting.vulnerability.ilike(vuln_id))
if sighting_type is not None:
query = query.filter(Sighting.type == sighting_type)
query = query.filter(
func.date(Sighting.creation_timestamp) >= date_from,
)

query = query.filter(
func.date(Sighting.creation_timestamp) <= date_to,
)
if date_from is not None:
query = query.filter(
func.date(Sighting.creation_timestamp) >= date_from,
)
if date_to is not None:
query = query.filter(
func.date(Sighting.creation_timestamp) <= date_to,
)
query = query.order_by(Sighting.creation_timestamp.desc())
total = query.count()
query = query.limit(limit)
Expand Down
18 changes: 15 additions & 3 deletions website/web/templates/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,21 @@ <h5>All the vulnerabilites related to {{vendor}} - {{product}}</h5>
});
});

function getDateSinceToday(daysAgo) {
const today = new Date();
// Subtract the given number of days
today.setDate(today.getDate() - daysAgo);

// Format the date as YYYY-MM-DD
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, '0'); // Months are 0-based
const day = String(today.getDate()).padStart(2, '0');

return `${year}-${month}-${day}`;
}

function loadSightings() {
fetch("{{ url_for('apiv1.sighting_sightings_list', type='seen') }}")
fetch("{{ url_for('apiv1.sighting_sightings_list', type='seen') }}&date_from="+getDateSinceToday(7))
.then(response => response.json())
.then(result => {
if (result.metadata.count == 0) {
Expand All @@ -301,7 +313,7 @@ <h5>All the vulnerabilites related to {{vendor}} - {{product}}</h5>
console.error('Error:', error);
});

fetch("{{ url_for('apiv1.sighting_sightings_list', type='exploited') }}")
fetch("{{ url_for('apiv1.sighting_sightings_list', type='exploited') }}&date_from="+getDateSinceToday(7))
.then(response => response.json())
.then(result => {
if (result.metadata.count == 0) {
Expand All @@ -315,7 +327,7 @@ <h5>All the vulnerabilites related to {{vendor}} - {{product}}</h5>
console.error('Error:', error);
});

fetch("{{ url_for('apiv1.sighting_sightings_list', type='confirmed') }}")
fetch("{{ url_for('apiv1.sighting_sightings_list', type='confirmed') }}&date_from="+getDateSinceToday(7))
.then(response => response.json())
.then(result => {
if (result.metadata.count == 0) {
Expand Down

0 comments on commit 036ca3a

Please sign in to comment.