From 6c6bb1960683c4400d758be997a2bf5f7adc4fdb Mon Sep 17 00:00:00 2001 From: david-rocca Date: Tue, 14 Jan 2025 12:59:15 -0500 Subject: [PATCH 1/2] Fixed issue allowing auto reservations for years in the past) --- .../cve-id.controller/cve-id.controller.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/controller/cve-id.controller/cve-id.controller.js b/src/controller/cve-id.controller/cve-id.controller.js index 6d886569..3be6ab3f 100644 --- a/src/controller/cve-id.controller/cve-id.controller.js +++ b/src/controller/cve-id.controller/cve-id.controller.js @@ -456,8 +456,9 @@ async function priorityReservation (year, amount, shortName, orgShortName, reque // Cve Id Range for 'year' does not exists if (!result) { // If there are less than or equal to 90 days until the end of the year, auto reserve it and move on. + // We also do not want the auto reservation feature to allow to reserve years in the past. // Otherwise throw failure - if (daysUntilYear(year) <= 90) { + if (!isYearInPast(year) && daysUntilYear(year) <= 90) { // Auto reserve the year const successfullyReservedYear = await reserveYear(year, req) if (!successfullyReservedYear) { @@ -545,8 +546,9 @@ async function sequentialReservation (year, amount, shortName, orgShortName, req // Cve Id Range for 'year' does not exists if (!result) { // If there are less than or equal to 90 days until the end of the year, auto reserve it and move on. + // We also do not want the auto reserve to work on any year in the past. // Otherwise throw failure - if (daysUntilYear(year) <= 90) { + if (!isYearInPast(year) && daysUntilYear(year) <= 90) { // Auto reserve the year const successfullyReservedYear = await reserveYear(year, req) if (!successfullyReservedYear) { @@ -654,8 +656,9 @@ async function nonSequentialReservation (year, amount, shortName, orgShortName, // Cve Id Range for 'year' does not exists if (!result) { // If there are less than or equal to 90 days until the end of the year, auto reserve it and move on. + // We also do not want to auto reserve any years in the past. // Otherwise throw failure - if (daysUntilYear(year) <= 90) { + if (!isYearInPast(year) && daysUntilYear(year) <= 90) { // Auto reserve the year const successfullyReservedYear = await reserveYear(year, req) if (!successfullyReservedYear) { @@ -983,6 +986,12 @@ function setMinAggregateObj (query) { ] } +// Function to check if a year is in the past +function isYearInPast (year) { + const currentYear = new Date().getFullYear() + return year < currentYear +} + function daysUntilYear (targetYear) { // Get today's date const today = new Date() From bc6461619bcbee998e240159921f26e74f381a0d Mon Sep 17 00:00:00 2001 From: david-rocca Date: Tue, 14 Jan 2025 13:34:25 -0500 Subject: [PATCH 2/2] Be more explicit about the end of the year in the text comment --- src/controller/cve-id.controller/cve-id.controller.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controller/cve-id.controller/cve-id.controller.js b/src/controller/cve-id.controller/cve-id.controller.js index 3be6ab3f..4ad2a7c5 100644 --- a/src/controller/cve-id.controller/cve-id.controller.js +++ b/src/controller/cve-id.controller/cve-id.controller.js @@ -455,7 +455,7 @@ async function priorityReservation (year, amount, shortName, orgShortName, reque // Cve Id Range for 'year' does not exists if (!result) { - // If there are less than or equal to 90 days until the end of the year, auto reserve it and move on. + // if reservations are not allowed for the current year, or if there are less than or equal to 90 days until the end of the year, auto reserve it and move on. // We also do not want the auto reservation feature to allow to reserve years in the past. // Otherwise throw failure if (!isYearInPast(year) && daysUntilYear(year) <= 90) { @@ -545,7 +545,7 @@ async function sequentialReservation (year, amount, shortName, orgShortName, req // Cve Id Range for 'year' does not exists if (!result) { - // If there are less than or equal to 90 days until the end of the year, auto reserve it and move on. + // if reservations are not allowed for the current year, or if there are less than or equal to 90 days until the end of the year, auto reserve it and move on. // We also do not want the auto reserve to work on any year in the past. // Otherwise throw failure if (!isYearInPast(year) && daysUntilYear(year) <= 90) { @@ -655,7 +655,7 @@ async function nonSequentialReservation (year, amount, shortName, orgShortName, // Cve Id Range for 'year' does not exists if (!result) { - // If there are less than or equal to 90 days until the end of the year, auto reserve it and move on. + // if reservations are not allowed for the current year, or if there are less than or equal to 90 days until the end of the year, auto reserve it and move on. // We also do not want to auto reserve any years in the past. // Otherwise throw failure if (!isYearInPast(year) && daysUntilYear(year) <= 90) {