Skip to content

Commit 713717c

Browse files
committed
#3394 show reserved CVE ID on Search Results page
1 parent c264b14 commit 713717c

File tree

3 files changed

+78
-19
lines changed

3 files changed

+78
-19
lines changed

src/stores/cveListSearch.js

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
88
cveId: '',
99
from: 0,
1010
isArecord: undefined,
11+
isAnId: undefined,
1112
isSeachButtonDisabled: true,
1213
isIdOrRecordFound: true,
1314
isPublished: false,
@@ -19,6 +20,7 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
1920
isLookUpRecordServerError: false,
2021
isSearchServerError: false,
2122
query: '',
23+
idData: {},
2224
recordData: {},
2325
searchResults: [],
2426
searchType: true,
@@ -73,36 +75,40 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
7375
this.isSearching = true;
7476
try{
7577

76-
// * 2nd, query search service
78+
// * query search service
7779
this.totalExecutingRequests = 1;
7880
await this.getSearchResults();
7981

8082
// * Check if keyword is CVE ID
8183
if (this.isCveIdPattern()) {
8284
this.totalExecutingRequests = 2;
8385

84-
// 1st, lookup ID to get Record data, and continue to get CVE Records that mention that ID
86+
// lookup ID to get Record data
8587
this.cveId = this.query.toUpperCase();
86-
await this.getRecordData();
88+
await this.getRecordData();
8789
}
8890

8991
} catch (error) {
90-
throw new Error('search() >> error with getRecordData() and or getSearchResults()');
92+
// if record is not found, find potential reserved ID
93+
if (this.isCveIdPattern() && Object.keys(this.recordData).length === 0) {
94+
await this.getIdData();
95+
}
96+
97+
throw new Error('search() >> error with getSearchResults(), getRecordData(), or getIdData()');
9198
} finally {
9299
this.isSearching = false;
93100
this.setUpInitialPagination();
94101
}
95102
},
96103
async getRecordData() {
97104
this.isLookingUpRecord = true;
98-
const getRecordUrl = `/api/cve/${this.cveId}`;
105+
const getRecordUrl = `${useGenericGlobalsStore().currentServicesUrl}/api/cve/${this.cveId}`;
99106

100107
try {
101-
axios.defaults.baseURL = useGenericGlobalsStore().currentServicesUrl;
102108
const response = await axios.get(getRecordUrl);
103109
const cveRecordData = response?.data || {};
104110
this.isArecord = true;
105-
this.isIdOrRecordFound = false;
111+
this.isIdOrRecordFound = true;
106112

107113
// format description
108114
let descriptions = [];
@@ -124,20 +130,42 @@ export const useCveListSearchStore = defineStore('cveListSearch ', {
124130
this.isRejected = true;
125131
}
126132

127-
} catch (e) {
133+
} catch (error) {
128134
this.isLookUpRecordServerError = true;
129135

130136
this.isPublished = false;
131137
this.isReserved = false;
132138
this.isRejected = false;
133139
this.isIdOrRecordFound = false;
134140
this.isArecord = false;
135-
throw new Error('getRecordData >> throwing wrroe')
141+
throw new Error('getRecordData >> throwing error');
136142
} finally {
137143
this.isLookingUpRecord = false;
138144
this.decrement('totalExecutingRequests');
139145
}
140146
},
147+
async getIdData() {
148+
const getIdUrl = `${useGenericGlobalsStore().currentServicesUrl}/api/cve-id/${this.cveId}`;
149+
try {
150+
const response = await axios.get(getIdUrl);
151+
const idData = response || {};
152+
this.isIdOrRecordFound = true;
153+
this.isAnId = true;
154+
if (idData.status === 200 && idData?.data?.error === undefined) {
155+
this.idData = idData.data;
156+
if (idData.state === 'RESERVED') {
157+
this.isReserved = true;
158+
this.isArecord = false;
159+
} else if (this.$store.state.idData.state === 'REJECTED') {
160+
this.isRejected = true;
161+
this.isArecord = false;
162+
}
163+
}
164+
165+
} catch (error) {
166+
throw new Error('getIdData >> throwing error');
167+
}
168+
},
141169
async getSearchResults() {
142170
this.isQueryingSearchService = true;
143171
const searchUrl = `${import.meta.env.VITE_API_BASE_URL}${import.meta.env.VITE_LIST_SEARCH_PATH}`;

src/views/CVERecord/CVERecord.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export default {
214214
const errorToStr = error.toString() || '';
215215
if (!errorToStr.match(regex)) {
216216
usecveRecordStore().isPublished = false;
217-
usecveRecordStore().isReserved = false;
217+
usecveRecordStore().isReserved = false; // only a cve-id can be in a 'reserved' state; this should always be false
218218
usecveRecordStore().isRejected = false;
219219
this.handleServerError();
220220
}

src/views/CVERecord/SearchResults.vue

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,36 @@
3434
<p>You are accessing <span class="has-text-weight-bold">Production</span> data from {{ resultUrl }}</p>
3535
</div>
3636
</div>
37-
<div class="mb-3" v-if="Object.keys(cveListSearchStore.recordData).length > 0">
38-
<h2 class="title">CVE Record Found</h2>
37+
<div class="mb-3" v-if="hasRecordData || hasIdData">
38+
<h2 class="title"> CVE {{ getRecordOrIdLabel }} Found</h2>
3939
<p class="cve-help-text">
40-
See the CVE Record below. If you are searching for this CVE ID in other CVE Records, view the Search Results section below.
40+
<span v-if="hasRecordData">View the CVE {{ getRecordOrIdLabel }} below.</span>
41+
<span v-if="hasIdData">
42+
The <router-link to="/ResourcesSupport/Glossary#glossaryCVEID">CVE ID</router-link> below has no corresponding
43+
<router-link to="/ResourcesSupport/Glossary#glossaryRecord">CVE Record</router-link>.
44+
</span>
45+
If you are searching for this CVE ID in other CVE Records, view the Search Results section below.
4146
</p>
42-
<div class="columns cve-columns is-variable is-1-desktop is-0-mobile mt-5 mr-2 mb-0 ml-2">
47+
<div class="columns cve-columns is-variable is-1-desktop is-0-mobile mt-0 mr-2 mb-0 ml-2">
4348
<div class="column cve-column">
4449
<div class="columns cve-columns">
4550
<div class="column cve-column">
46-
<router-link :to="`/CVERecord?id=${cveListSearchStore.recordData.cveId}`" target="_blank">{{ cveListSearchStore.recordData.cveId }}</router-link>
51+
<router-link v-if="hasRecordData"
52+
:to="`/CVERecord?id=${cveListSearchStore.recordData.cveId}`" target="_blank">
53+
{{ cveListSearchStore.recordData.cveId }}
54+
</router-link>
55+
<router-link v-if="hasIdData"
56+
:to="`/CVERecord?id=${cveListSearchStore.idData.cve_id}`" target="_blank">
57+
{{ cveListSearchStore.idData.cve_id}}
58+
</router-link>
4759
</div>
48-
<div class="column cve-column">
60+
<div class="column cve-column" v-if="hasRecordData">
4961
<p>
5062
<span>CNA: </span>
5163
{{ partnerStore.partnerShortLongNameMap[cveListSearchStore.recordData.cnaOrgId] ? partnerStore.partnerShortLongNameMap[cveListSearchStore.recordData.cnaOrgId] : cveListSearchStore.recordData.cna }}</p>
5264
</div>
5365
</div>
54-
<div class="columns cve-columns">
66+
<div class="columns cve-columns" v-if="hasRecordData">
5567
<div class="column cve-column">
5668
<div v-for="(description, index) in cveListSearchStore.recordData.descriptions" :key="description.key" class="mb-0">
5769
<p v-if="!description.showMore" class="mb-0">
@@ -73,7 +85,7 @@
7385
</div>
7486
<div id="cve-search-results-container" v-if="cveListSearchStore.totalSearchResultCount > 0">
7587
<h2 class="title">Search Results</h2>
76-
<p class="cve-help-text" v-if="Object.keys(cveListSearchStore.recordData).length > 0">
88+
<p class="cve-help-text" v-if="hasRecordData || hasIdData">
7789
Includes all record(s) that reference this CVE ID.
7890
</p>
7991
<div class="mt-4 mb-2">
@@ -123,7 +135,7 @@
123135
</div>
124136
</div>
125137
</div>
126-
<div v-if="Object.keys(cveListSearchStore.recordData).length > 0 || cveListSearchStore.totalSearchResultCount > 0">
138+
<div v-if="cveListSearchStore.totalSearchResultCount > 0">
127139
<div class="columns cve-columns" v-for="(result, resultIndex) in cveListSearchStore.searchResults" :key="result.index">
128140
<div class="column cve-column">
129141
<div class="column cve-column" :class="{'cve-top-border': resultIndex !== 0}">
@@ -282,6 +294,25 @@ function backToTop() {
282294
const websiteEnv = computed(() => {
283295
return import.meta.env.VITE_WEBSITE_ENVIRONMENT;
284296
});
297+
298+
let getRecordOrIdLabel = computed(() => {
299+
if (cveListSearchStore?.isArecord){
300+
return 'Record';
301+
} else if (Object.keys(cveListSearchStore.idData).length > 0) {
302+
return 'ID';
303+
} else {
304+
return '';
305+
}
306+
});
307+
308+
let hasRecordData = computed(() => {
309+
return Object.keys(cveListSearchStore.recordData).length > 0;
310+
});
311+
312+
313+
let hasIdData = computed(() => {
314+
return Object.keys(cveListSearchStore.idData).length > 0;
315+
});
285316
</script>
286317
287318
<style lang="scss">

0 commit comments

Comments
 (0)