Skip to content

Commit

Permalink
core: frontend: Add checks prior to delete IPs
Browse files Browse the repository at this point in the history
* Add a check layer prior to deleting IPs on interfaces avoiding to
  delete the last IP or curently being useed IP by mistake
  • Loading branch information
JoaoMario109 committed Mar 5, 2024
1 parent 792cf68 commit 24434e2
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions core/frontend/src/components/ethernet/InterfaceCard.vue
Expand Up @@ -85,6 +85,8 @@
import Vue, { PropType } from 'vue'
import Notifier from '@/libs/notifier'
import Popup from '@/libs/popup'
import beacon from '@/store/beacon'
import ethernet from '@/store/ethernet'
import { AddressMode, EthernetInterface } from '@/types/ethernet'
import { ethernet_service } from '@/types/frontend_services'
Expand Down Expand Up @@ -127,8 +129,54 @@ export default Vue.extend({
is_static_ip_present(): boolean {
return this.adapter.addresses.some((address) => address.mode === AddressMode.unmanaged)
},
is_interface_last_ip_address(): boolean {
return this.adapter.addresses.length === 1
},
},
mounted() {
beacon.registerBeaconListener(this)
},
methods: {
/**
* Opens a dialog and requests the user to confirm the deletion of the IP address.
* @returns {Promise<boolean>} - Resolves to true if no confirmation is needed or
* granted and false otherwise.
*/
async confirm_last_interface_ip(): Promise<boolean> {
if (this.is_interface_last_ip_address) {
const result = await Popup.fire({
title: 'Last IP Address',
text: 'This is the last IP address on the interface. Are you sure you want to proceed?',
confirmButtonText: 'Yes',
showCancelButton: true,
})
return result.confirmed
}
return true
},
/**
* Opens a dialog and requests the user to confirm the deletion of current used IP address.
* @returns {Promise<boolean>} - Resolves to true if no confirmation is needed or
* granted and false otherwise.
*/
async confirm_ip_being_used(ip: string): Promise<boolean> {
const ip_being_used = ip === beacon.nginx_ip_address
if (ip_being_used) {
const result = await Popup.fire({
title: 'IP Address in Use',
text: 'The IP address is currently being used to access BlueOS. Are you sure you want to proceed?',
confirmButtonText: 'Yes',
showCancelButton: true,
})
return result.confirmed
}
return true
},
showable_mode_name(mode: AddressMode): string {
switch (mode) {
case AddressMode.client: return 'Dynamic IP'
Expand All @@ -141,6 +189,13 @@ export default Vue.extend({
this.show_creation_dialog = true
},
async deleteAddress(ip: string): Promise<void> {
const confirmed_ip_used = await this.confirm_ip_being_used(ip)
const confirmed_last_ip = await this.confirm_last_interface_ip()
if (!confirmed_ip_used || !confirmed_last_ip) {
return
}
ethernet.setUpdatingInterfaces(true)
await back_axios({
Expand Down

0 comments on commit 24434e2

Please sign in to comment.