Skip to content

Commit

Permalink
fix(dedicated.firewall): disable toggle button
Browse files Browse the repository at this point in the history
ref: UXCT-512

disable toggle button if mitigation is on PERMANENT or FORCED status

Signed-off-by: Stephanie Moallic <[email protected]>
  • Loading branch information
Stephanie Moallic committed Dec 5, 2023
1 parent c01d697 commit 15ac05e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ export default /* @ngInject */ function IpFirewallService(
);
};

this.sortList = function sortList(listToSort) {
return listToSort.sort((a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
});
};

this.getFirewallDetails = function getFirewallDetails(ipBlock, ip) {
const url = [
'/ip',
Expand All @@ -137,6 +149,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.permanent || result.data.auto)
.catch((http) => $q.reject(http.data));
};

this.getFirewallRuleConstants = function getFirewallRuleConstants() {
return self.getIpModels().then((ipModels) => ({
actions: ipModels['ip.FirewallActionEnum'].enum,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -81,21 +82,9 @@ export default /* @ngInject */ function IpFirewallCtrl(
}
}

function sortList(listToSort) {
return listToSort.sort((a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
});
}

function loadConstants() {
IpFirewall.getFirewallRuleConstants().then((constants) => {
const sequences = sortList(
const sequences = IpFirewall.sortList(
transform(constants.sequences, (result, name, key) => {
const newResult = result;
const map = {
Expand Down Expand Up @@ -149,6 +138,14 @@ export default /* @ngInject */ function IpFirewallCtrl(
loadRules(self.FIREWALL_MAX_RULES, 0);
}

function getMitigationDetail() {
IpFirewall.getMitigation(self.selectedBlock, self.selectedIp).then(
(mitigation) => {
self.disabledToggle = mitigation;
},
);
}

function getFirewallDetail() {
IpFirewall.getFirewallDetails(self.selectedBlock, self.selectedIp).then(
(firewallDetails) => {
Expand All @@ -161,6 +158,8 @@ export default /* @ngInject */ function IpFirewallCtrl(
firewall: firewallDetails.enabled ? 'ACTIVATED' : 'DEACTIVATED',
};
self.firewallStatus = firewallDetails.enabled;

getMitigationDetail();
paginate(self.pageSize, self.offset);
},
);
Expand Down Expand Up @@ -204,17 +203,15 @@ export default /* @ngInject */ function IpFirewallCtrl(
self.selectedIp,
result.sequence,
).then(() => {
self.successMessage = $translate.instant(
'ip_firewall_delete_success',
);
if (result.state === self.constants.CREATION_PENDING) {
self.successMessage = $translate.instant(
'ip_firewall_add_success',
);
reloadRules();
} else {
self.successMessage = $translate.instant(
'ip_firewall_delete_success',
);
reloadRules();
}
reloadRules();
});
}
});
Expand All @@ -231,7 +228,9 @@ export default /* @ngInject */ function IpFirewallCtrl(
.finally(() => {
// Sort list to display deny action first
if (self.rules.list.results) {
self.rules.list.results = sortList(self.rules.list.results);
self.rules.list.results = IpFirewall.sortList(
self.rules.list.results,
);
}
self.rulesLoading = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']})"
></oui-switch>
data-ng-if="!IpFirewallCtrl.disabledToggle"
>
</oui-switch>
<oui-switch
data-model="IpFirewallCtrl.firewallToggle.status"
data-name="firewallStatus"
data-ng-if="IpFirewallCtrl.disabledToggle"
data-oui-tooltip-placement="left"
data-oui-tooltip="{{:: 'ip_table_manage_firewall_disable_tooltip' | translate }}"
disabled
>
</oui-switch>
</div>
</div>
<div
Expand Down

0 comments on commit 15ac05e

Please sign in to comment.