From 76e27418c616fc08db4580b526e424f16aaa42ac Mon Sep 17 00:00:00 2001 From: Joao Mario Lago Date: Tue, 5 Mar 2024 11:36:05 -0300 Subject: [PATCH] core: frontend: Add checks prior to delete IPs * Add a check layer prior to deleting IPs on interfaces avoiding to delete the last IP or curently being useed IP by mistake --- .../ethernet/AddressDeletionDialog.vue | 65 +++++++++++++++++++ .../src/components/ethernet/InterfaceCard.vue | 65 +++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 core/frontend/src/components/ethernet/AddressDeletionDialog.vue diff --git a/core/frontend/src/components/ethernet/AddressDeletionDialog.vue b/core/frontend/src/components/ethernet/AddressDeletionDialog.vue new file mode 100644 index 0000000000..e9f95ff73f --- /dev/null +++ b/core/frontend/src/components/ethernet/AddressDeletionDialog.vue @@ -0,0 +1,65 @@ + + + diff --git a/core/frontend/src/components/ethernet/InterfaceCard.vue b/core/frontend/src/components/ethernet/InterfaceCard.vue index 769652b31b..c7ed16ad23 100644 --- a/core/frontend/src/components/ethernet/InterfaceCard.vue +++ b/core/frontend/src/components/ethernet/InterfaceCard.vue @@ -47,6 +47,10 @@ v-model="show_creation_dialog" :interface-name="adapter.name" /> + 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} - Resolves to true if no confirmation is needed or + * granted and false otherwise. + */ + async confirm_last_interface_ip(): Promise { + if (this.is_interface_last_ip_address) { + const dialog = this.$refs.deletionDialog as InstanceType + + dialog.title = 'Last IP Address' + dialog.message = 'This is the last IP address on the interface. Are you sure you want to proceed?' + + this.show_deletion_dialog = true + + return new Promise((resolve) => { + dialog.resolveCallback = resolve + }) + } + + return true + }, + /** + * Opens a dialog and requests the user to confirm the deletion of current used IP address. + * @returns {Promise} - Resolves to true if no confirmation is needed or + * granted and false otherwise. + */ + async confirm_ip_being_used(ip: string): Promise { + const ip_being_used = ip === beacon.nginx_ip_address + + if (ip_being_used) { + const dialog = this.$refs.deletionDialog as InstanceType + + dialog.title = 'IP Address in Use' + dialog.message = 'The IP address is currently being used to access BlueOS. Are you sure you want to proceed?' + + this.show_deletion_dialog = true + + return new Promise((resolve) => { + dialog.resolveCallback = resolve + }) + } + + return true + }, showable_mode_name(mode: AddressMode): string { switch (mode) { case AddressMode.client: return 'Dynamic IP' @@ -141,6 +199,13 @@ export default Vue.extend({ this.show_creation_dialog = true }, async deleteAddress(ip: string): Promise { + const confirmed_ip_used = await this.confirm_ip_being_used(ip) + const confirmed_last_ip = confirmed_ip_used && await this.confirm_last_interface_ip() + + if (!confirmed_ip_used || !confirmed_last_ip) { + return + } + ethernet.setUpdatingInterfaces(true) await back_axios({