From 5e8a8dd051e2a72175e09ad34bf8305b0f400fdd Mon Sep 17 00:00:00 2001 From: Stephanie Moallic Date: Fri, 1 Dec 2023 15:01:18 +0100 Subject: [PATCH] fix(dedicated.firewall): disable toggle button ref: UXCT-512 disable toggle button if mitigation is on PERMANENT or FORCED status Signed-off-by: Stephanie Moallic --- .../list/firewall/ip-ip-firewall-rule.service.js | 13 +++++++++++++ .../list/firewall/ip-ip-firewall.controller.js | 13 +++++++++++++ .../ip/components/list/firewall/ip-ip-firewall.html | 13 ++++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/packages/manager/apps/dedicated/client/app/ip/components/list/firewall/ip-ip-firewall-rule.service.js b/packages/manager/apps/dedicated/client/app/ip/components/list/firewall/ip-ip-firewall-rule.service.js index 51bcf281bcc8..5c8ecd64f029 100644 --- a/packages/manager/apps/dedicated/client/app/ip/components/list/firewall/ip-ip-firewall-rule.service.js +++ b/packages/manager/apps/dedicated/client/app/ip/components/list/firewall/ip-ip-firewall-rule.service.js @@ -137,6 +137,19 @@ export default /* @ngInject */ function IpFirewallService( ); }; + this.getMitigation = function getMitigation(ipBlock, ip) { + const url = [ + '/ip', + window.encodeURIComponent(ipBlock), + 'mitigation', + ip, + ].join('/'); + return $http.get(url, { serviceType: 'apiv6' }).then( + (result) => result.data, + (http) => $q.reject(http.data), + ); + }; + this.getFirewallRuleConstants = function getFirewallRuleConstants() { return self.getIpModels().then((ipModels) => ({ actions: ipModels['ip.FirewallActionEnum'].enum, diff --git a/packages/manager/apps/dedicated/client/app/ip/components/list/firewall/ip-ip-firewall.controller.js b/packages/manager/apps/dedicated/client/app/ip/components/list/firewall/ip-ip-firewall.controller.js index 2694cf6e0f68..be3919b5dbe4 100644 --- a/packages/manager/apps/dedicated/client/app/ip/components/list/firewall/ip-ip-firewall.controller.js +++ b/packages/manager/apps/dedicated/client/app/ip/components/list/firewall/ip-ip-firewall.controller.js @@ -57,6 +57,7 @@ export default /* @ngInject */ function IpFirewallCtrl( self.successMessage = null; self.denyMessage = null; self.firewallStatus = null; + self.disabledToggle = false; function paginate(pageSize, offset) { self.rulesTable = self.rules.list.results.slice( @@ -149,6 +150,16 @@ export default /* @ngInject */ function IpFirewallCtrl( loadRules(self.FIREWALL_MAX_RULES, 0); } + function getMitigationDetail() { + IpFirewall.getMitigation(self.selectedBlock, self.selectedIp).then( + (mitigation) => { + if (mitigation.permanent || mitigation.auto) { + self.disabledToggle = true; + } + }, + ); + } + function getFirewallDetail() { IpFirewall.getFirewallDetails(self.selectedBlock, self.selectedIp).then( (firewallDetails) => { @@ -161,6 +172,8 @@ export default /* @ngInject */ function IpFirewallCtrl( firewall: firewallDetails.enabled ? 'ACTIVATED' : 'DEACTIVATED', }; self.firewallStatus = firewallDetails.enabled; + + getMitigationDetail(); paginate(self.pageSize, self.offset); }, ); diff --git a/packages/manager/apps/dedicated/client/app/ip/components/list/firewall/ip-ip-firewall.html b/packages/manager/apps/dedicated/client/app/ip/components/list/firewall/ip-ip-firewall.html index e8f17177d228..6a228e2989c4 100644 --- a/packages/manager/apps/dedicated/client/app/ip/components/list/firewall/ip-ip-firewall.html +++ b/packages/manager/apps/dedicated/client/app/ip/components/list/firewall/ip-ip-firewall.html @@ -78,7 +78,18 @@ data-model="IpFirewallCtrl.firewallToggle.status" data-name="firewallStatus" data-on-change="setAction('ip/firewall/toggle/ip-ip-firewall-toggle', {ipBlock: IpFirewallCtrl.ipBlock, ip: IpFirewallCtrl.firewallToggle, tracking: IpFirewallCtrl.tracking['update-firewall-status']})" - > + data-ng-if="!IpFirewallCtrl.disabledToggle" + > + + +