Skip to content

Commit c80ce00

Browse files
committed
genericGlobals: add isProductionWebsite; use production services for search results
1 parent a1e9a04 commit c80ce00

File tree

4 files changed

+40
-20
lines changed

4 files changed

+40
-20
lines changed

src/components/cveRecordSearchModule.vue

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
22
<div class="mt-1">
3-
<div v-if="!isProductionWebsite" role="alert" class="notification is-warning is-light">
3+
<div v-if="!cveGenericGlobalsStore.isProductionWebsite" role="alert"
4+
class="notification is-warning is-light">
45
<div class="is-flex is-align-items-flex-start mt-1" style="max-width: 820px; column-gap: 1rem;">
56
<div class="pl-3">
67
<p id="alertIconVariousFormts" class="is-hidden">alert</p>
@@ -18,7 +19,8 @@
1819
</div>
1920
<div class="field has-addons mt-1">
2021
<p class="control">
21-
<span v-if="!isProductionWebsite" class="select cve-search-selector">
22+
<span v-if="!cveGenericGlobalsStore.isProductionWebsite"
23+
class="select cve-search-selector">
2224
<select v-model="searchType">
2325
<option>{{ searchOptionLabel }}</option>
2426
<option>{{ legacyOptionLabel }}</option>
@@ -65,8 +67,6 @@ import { useGenericGlobalsStore } from '@/stores/genericGlobals';
6567
const cveIdRegex = /^CVE\p{Pd}(?<year>\d{4})\p{Pd}(?<id>\d{4,})$/iu;
6668
const wordRegex = /^[a-z0-9 ]+$/i;
6769
68-
const isProductionWebsite = import.meta.env.VITE_WEBSITE_ENVIRONMENT === 'prd';
69-
7070
// This is the current maximum supported length of the "suffix" portion of
7171
// the CVE ID. The schema defines a suffix length up to 19, but code in
7272
// other modules only supports what's defined here.
@@ -115,7 +115,8 @@ watch(
115115
// find than the normal search (cveawg). In this case, we need to switch
116116
// the search type to "legacy". (issue #3426)
117117
118-
if (route?.name === cveRecordRouteName && !isProductionWebsite)
118+
if (route?.name === cveRecordRouteName
119+
&& !cveGenericGlobalsStore.isProductionWebsite)
119120
searchType.value = legacyOptionLabel;
120121
else if (route.query?.query) {
121122
queryString.value = route.query.query.trim();
@@ -156,9 +157,7 @@ function startSearch() {
156157
} else
157158
cveListSearchStore.search();
158159
} else {
159-
const lookupPath = `/CVERecord?id=${cveId}`;
160-
161-
router.push({path: lookupPath, query: {id: cveId}})
160+
router.push({name: cveRecordRouteName, query: {id: cveId}})
162161
}
163162
}
164163

src/stores/genericGlobals.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const useGenericGlobalsStore = defineStore('genericGlobals', {
66
const storedUseSearch = sessionStorage.getItem('useSearch');
77
const storedCurrentServicesUrl = sessionStorage.getItem('currentServicesUrl');
88
return {
9+
isProductionWebsite: import.meta.env.VITE_WEBSITE_ENVIRONMENT === 'prd',
910
useSearch: storedUseSearch ? JSON.parse(storedUseSearch) : true,
1011
currentServicesUrl: storedCurrentServicesUrl ? JSON.parse(storedCurrentServicesUrl)
1112
: cveServicesBaseUrlFromEnv,

src/views/CVERecord/CVERecord.vue

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</div>
2222
<div v-else>
2323
<div v-if="usecveRecordStore.isIdOrRecordFound">
24-
<div v-if="websiteEnv !== 'prd'" class="notification is-warning is-light" role="alert">
24+
<div v-if="!genericGlobalsStore.isProductionWebsite" class="notification is-warning is-light" role="alert">
2525
<div class="is-flex" style="justify-content: center;">
2626
<p id="alertIconCveRecordsRequestErrored" class="is-hidden">alert</p>
2727
<font-awesome-icon style="flex: 0 0 40px;" size="1x" icon="triangle-exclamation" role="img"
@@ -103,7 +103,9 @@ export default {
103103
: this.GenericGlobalsStore.cveServiceTestBaseUrl,
104104
usecveRecordStore: usecveRecordStore(),
105105
cveId: usecveRecordStore().cveId,
106+
cveServicesUrl: undefined,
106107
errorMessageStore: useErrorMessageStore(),
108+
genericGlobalsStore: useGenericGlobalsStore(),
107109
showHelpText: false,
108110
disabled: true,
109111
getIdStatusCode: undefined,
@@ -122,12 +124,15 @@ export default {
122124
}
123125
},
124126
created() {
125-
const fullPathArr = this.$route.fullPath.split('id=');
126-
if (fullPathArr.length === 2) {
127-
const cveId = fullPathArr[1];
127+
const cveId = this.$route.query?.id;
128+
if (cveId) {
128129
this.cveId = this.cveIdToUpperCase(cveId);
129130
this.validateCveId();
130131
if (!this.disabled) {
132+
if (this.$route.query?.prod ?? 'false' === 'true')
133+
this.currentServicesUrl = this.genericGlobalsStore.cveServicesBaseUrl;
134+
else
135+
this.currentServicesUrl = this.genericGlobalsStore.currentServicesUrl;
131136
this.startLookup();
132137
} else {
133138
usecveRecordStore().showHelpText = true;
@@ -138,10 +143,15 @@ export default {
138143
},
139144
watch: {
140145
$route(to) {
141-
if (Object.prototype.hasOwnProperty.call(to.query, 'id')) {
142-
this.cveId = this.cveIdToUpperCase(to.query.id);
146+
const cveId = to.query?.id;
147+
if (cveId) {
148+
this.cveId = this.cveIdToUpperCase(cveId);
143149
this.validateCveId();
144150
if (!this.disabled) {
151+
if (this.$route.query?.prod ?? 'false' === 'true')
152+
this.currentServicesUrl = this.genericGlobalsStore.cveServicesBaseUrl;
153+
else
154+
this.currentServicesUrl = this.genericGlobalsStore.currentServicesUrl;
145155
this.startLookup();
146156
} else {
147157
this.resetStates();
@@ -203,7 +213,7 @@ export default {
203213
204214
const getIdUrl = `/api/cve-id/${usecveRecordStore().cveId}`;
205215
try {
206-
axios.defaults.baseURL = this.GenericGlobalsStore.currentServicesUrl;
216+
axios.defaults.baseURL = this.currentServicesUrl;
207217
const idData = await axios.get(getIdUrl);
208218
this.getIdStatusCode = 200;
209219
if (idData.status === 200 && idData?.data?.error === undefined) {
@@ -239,7 +249,7 @@ export default {
239249
}
240250
},
241251
async getRecordData() {
242-
const getRecordUrl = `${useGenericGlobalsStore().currentServicesUrl}/api/cve/${usecveRecordStore().cveId}`;
252+
const getRecordUrl = `${this.currentServicesUrl}/api/cve/${usecveRecordStore().cveId}`;
243253
if (this.GenericGlobalsStore.useSearch) {
244254
this.isResultFromProd = true;
245255
} else {

src/views/CVERecord/SearchResults.vue

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@
5050
<div class="columns cve-columns">
5151
<div class="column cve-column">
5252
<router-link v-if="hasRecordData"
53-
:to="`/CVERecord?id=${cveListSearchStore.recordData.cveId}`" target="_blank">
53+
:to="cveRecordRoute(cveListSearchStore.recordData.cveId)" target="_blank">
5454
{{ cveListSearchStore.recordData.cveId }}
5555
</router-link>
5656
<router-link v-if="hasIdData"
57-
:to="`/CVERecord?id=${cveListSearchStore.idData.cve_id}`" target="_blank">
57+
:to="cveRecordRoute(cveListSearchStore.idData.cve_id)" target="_blank">
5858
{{ cveListSearchStore.idData.cve_id}}
5959
</router-link>
6060
</div>
@@ -160,7 +160,7 @@
160160
</div>
161161
<div class="columns cve-columns">
162162
<div class="column cve-column">
163-
<router-link :to="`/CVERecord?id=${result.cveId}`" target="_blank">{{ result.cveId }}</router-link>
163+
<router-link :to="cveRecordRoute(result.cveId)" target="_blank">{{ result.cveId }}</router-link>
164164
</div>
165165
<div class="column cve-column">
166166
<p>
@@ -287,10 +287,11 @@ import { useRouter } from 'vue-router';
287287
import ServiceUnavailable from '@/components/ServiceUnavailable.vue'
288288
289289
const cveListSearchStore = useCveListSearchStore();
290+
const generalGlobalsStore = useGenericGlobalsStore();
290291
const partnerStore = usePartnerStore();
291292
const router = useRouter();
292293
const app = createApp({});
293-
const resultUrl = ref(useGenericGlobalsStore().cveServicesBaseUrl);
294+
const resultUrl = ref(generalGlobalsStore.cveServicesBaseUrl);
294295
295296
app.component('ServiceUnavailable', ServiceUnavailable);
296297
@@ -310,6 +311,15 @@ function backToTop() {
310311
});
311312
}
312313
314+
function cveRecordRoute(cveId) {
315+
let recordRoute = `/CVERecord?id=${cveId}`;
316+
317+
if (!generalGlobalsStore.isProductionWebsite)
318+
recordRoute += '&prod=true';
319+
320+
return recordRoute
321+
}
322+
313323
const websiteEnv = computed(() => {
314324
return import.meta.env.VITE_WEBSITE_ENVIRONMENT;
315325
});

0 commit comments

Comments
 (0)