Skip to content

Commit b84fc8a

Browse files
committed
ui: fix info card showing invalid template, iso link
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 6bc7f48 commit b84fc8a

2 files changed

Lines changed: 79 additions & 5 deletions

File tree

ui/src/components/view/InfoCard.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -609,15 +609,17 @@
609609
<div class="resource-detail-item__details">
610610
<resource-icon v-if="images.template || images.guestoscategory" :image="images.template || images.guestoscategory" size="1x" style="margin-right: 5px"/>
611611
<SaveOutlined v-else />
612-
<router-link :to="{ path: (resource.templateformat === 'ISO' ? '/iso/' : '/template/') + resource.templateid }">{{ resource.templatedisplaytext || resource.templatename || resource.templateid }} </router-link>
612+
<router-link v-if="validLinks.template" :to="{ path: (resource.templateformat === 'ISO' ? '/iso/' : '/template/') + resource.templateid }">{{ resource.templatedisplaytext || resource.templatename || resource.templateid }} </router-link>
613+
<span v-else>{{ resource.templatedisplaytext || resource.templatename || resource.templateid }}</span>
613614
</div>
614615
</div>
615616
<div class="resource-detail-item" v-if="resource.isoid">
616617
<div class="resource-detail-item__label">{{ $t('label.isoname') }}</div>
617618
<div class="resource-detail-item__details">
618619
<resource-icon v-if="images.iso || (resource.isoid === resource.templateid && images.guestoscategory)" :image="images.iso || images.guestoscategory" size="1x" style="margin-right: 5px"/>
619620
<UsbOutlined v-else />
620-
<router-link :to="{ path: '/iso/' + resource.isoid }">{{ resource.isodisplaytext || resource.isoname || resource.isoid }} </router-link>
621+
<router-link v-if="validLinks.iso" :to="{ path: '/iso/' + resource.isoid }">{{ resource.isodisplaytext || resource.isoname || resource.isoid }} </router-link>
622+
<span v-else>{{ resource.isodisplaytext || resource.isoname || resource.isoid }}</span>
621623
</div>
622624
</div>
623625
<div class="resource-detail-item" v-if="resource.serviceofferingname && resource.serviceofferingid">
@@ -980,7 +982,7 @@
980982
<script>
981983
import { getAPI, postAPI } from '@/api'
982984
import { createPathBasedOnVmType } from '@/utils/plugins'
983-
import { validateLinks } from '@/utils/links'
985+
import { validateLinksAsync } from '@/utils/links'
984986
import Console from '@/components/widgets/Console'
985987
import OsLogo from '@/components/widgets/OsLogo'
986988
import Status from '@/components/widgets/Status'
@@ -1068,12 +1070,12 @@ export default {
10681070
},
10691071
resource: {
10701072
deep: true,
1071-
handler (newData, oldData) {
1073+
async handler (newData, oldData) {
10721074
if (newData === oldData) return
10731075
this.newResource = newData
10741076
this.showKeys = false
10751077
this.setData()
1076-
this.validLinks = validateLinks(this.$router, this.isStatic, this.resource)
1078+
this.validLinks = await validateLinksAsync(this.$router, this.isStatic, this.resource)
10771079
10781080
if ('apikey' in this.resource) {
10791081
this.getUserKeys()

ui/src/utils/links.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
import { getAPI } from '@/api'
19+
20+
async function isValidObject (apiName, id, params) {
21+
try {
22+
const allParams = { ...params, listAll: true, id }
23+
const json = await getAPI(apiName, allParams)
24+
const responseName = Object.keys(json).find(key => key.endsWith('response')) || apiName.toLowerCase() + 'response'
25+
const response = json?.[responseName]
26+
if (!response) {
27+
return false
28+
}
29+
const objectName = Object.keys(response).find(key => key !== 'count')
30+
if (!objectName || !Array.isArray(response[objectName])) {
31+
return false
32+
}
33+
return response[objectName].some(item => item.id === id)
34+
} catch (e) {
35+
return false
36+
}
37+
}
38+
1839
export function validateLinks (router, isStatic, resource) {
1940
const validLinks = {
2041
volume: false
@@ -34,3 +55,54 @@ export function validateLinks (router, isStatic, resource) {
3455

3556
return validLinks
3657
}
58+
59+
export async function validateLinksAsync (router, isStatic, resource) {
60+
const validLinks = {
61+
volume: false,
62+
template: false,
63+
iso: false
64+
}
65+
const pendingChecks = []
66+
67+
if (isStatic) {
68+
return validLinks
69+
}
70+
71+
if (resource.volumeid && router.resolve('/volume/' + resource.volumeid).matched[0].redirect !== '/exception/404') {
72+
if (resource.volumestate) {
73+
validLinks.volume = resource.volumestate !== 'Expunged'
74+
} else {
75+
validLinks.volume = true
76+
}
77+
}
78+
79+
if (resource.templateid) {
80+
const templatePath = (resource.templateformat === 'ISO' ? '/iso/' : '/template/') + resource.templateid
81+
if (router.resolve(templatePath).matched[0].redirect !== '/exception/404') {
82+
pendingChecks.push(
83+
isValidObject('listTemplates', resource.templateid, { templatefilter: 'executable' }).then(result => {
84+
validLinks.template = result
85+
})
86+
)
87+
}
88+
}
89+
90+
if (resource.isoid) {
91+
const isoPath = '/iso/' + resource.isoid
92+
if (router.resolve(isoPath).matched[0].redirect !== '/exception/404') {
93+
pendingChecks.push(
94+
isValidObject('listIsos', resource.isoid, { isofilter: 'executable' }).then(result => {
95+
validLinks.iso = result
96+
})
97+
)
98+
}
99+
}
100+
101+
if (pendingChecks.length) {
102+
await Promise.all(pendingChecks).catch(error => {
103+
console.error('Error validating links:', error)
104+
})
105+
}
106+
107+
return validLinks
108+
}

0 commit comments

Comments
 (0)