diff --git a/src/controller/cve-id.controller/cve-id.controller.js b/src/controller/cve-id.controller/cve-id.controller.js index 6d886569..4ad2a7c5 100644 --- a/src/controller/cve-id.controller/cve-id.controller.js +++ b/src/controller/cve-id.controller/cve-id.controller.js @@ -455,9 +455,10 @@ 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 (daysUntilYear(year) <= 90) { + if (!isYearInPast(year) && daysUntilYear(year) <= 90) { // Auto reserve the year const successfullyReservedYear = await reserveYear(year, req) if (!successfullyReservedYear) { @@ -544,9 +545,10 @@ 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 (daysUntilYear(year) <= 90) { + if (!isYearInPast(year) && daysUntilYear(year) <= 90) { // Auto reserve the year const successfullyReservedYear = await reserveYear(year, req) if (!successfullyReservedYear) { @@ -653,9 +655,10 @@ 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 (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()