From 9f74d9abef0333bab51f0240b864683c518311a3 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Thu, 24 Sep 2020 17:09:45 +0300 Subject: [PATCH] Improved rule display: merged warnings and dangers are displayed the same, added sorting --- .../scoutsuite/ScoutSuiteRuleModal.js | 32 +++++++++++++- .../ScoutSuiteSingleRuleDropdown.js | 43 ++++++++++--------- 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/scoutsuite/ScoutSuiteRuleModal.js b/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/scoutsuite/ScoutSuiteRuleModal.js index 01df2a162..05058ef8f 100644 --- a/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/scoutsuite/ScoutSuiteRuleModal.js +++ b/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/scoutsuite/ScoutSuiteRuleModal.js @@ -2,8 +2,9 @@ import React, {useState} from 'react'; import {Modal} from 'react-bootstrap'; import * as PropTypes from 'prop-types'; import Pluralize from 'pluralize'; -import ScoutSuiteSingleRuleDropdown from './ScoutSuiteSingleRuleDropdown'; +import ScoutSuiteSingleRuleDropdown, {getRuleStatus} from './ScoutSuiteSingleRuleDropdown'; import '../../../../styles/components/scoutsuite/RuleModal.scss'; +import STATUSES from '../../common/consts/StatusConsts'; export default function ScoutSuiteRuleModal(props) { @@ -17,9 +18,36 @@ export default function ScoutSuiteRuleModal(props) { } } + function compareRules(firstRule, secondRule) { + let firstStatus = getRuleStatus(firstRule); + let secondStatus = getRuleStatus(secondRule); + return compareRuleStatuses(firstStatus, secondStatus); + } + + + function compareRuleStatuses(ruleStatusOne, ruleStatusTwo) { + if (ruleStatusOne === ruleStatusTwo) { + return 0; + } else if (ruleStatusOne === STATUSES.STATUS_FAILED) { + return -1; + } else if (ruleStatusTwo === STATUSES.STATUS_FAILED) { + return 1; + } else if (ruleStatusOne === STATUSES.STATUS_VERIFY) { + return -1; + } else if (ruleStatusTwo === STATUSES.STATUS_VERIFY) { + return 1; + } else if (ruleStatusOne === STATUSES.STATUS_PASSED) { + return -1; + } else if (ruleStatusTwo === STATUSES.STATUS_PASSED) { + return 1; + } + } + function renderRuleDropdowns() { let dropdowns = []; - props.scoutsuite_rules.forEach(rule => { + let rules = props.scoutsuite_rules; + rules.sort(compareRules); + rules.forEach(rule => { let dropdown = ( toggleRuleDropdown(rule.description)} rule={rule} diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/scoutsuite/ScoutSuiteSingleRuleDropdown.js b/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/scoutsuite/ScoutSuiteSingleRuleDropdown.js index f93bbb7fd..4118d50d3 100644 --- a/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/scoutsuite/ScoutSuiteSingleRuleDropdown.js +++ b/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/scoutsuite/ScoutSuiteSingleRuleDropdown.js @@ -8,7 +8,7 @@ import classNames from 'classnames'; import * as PropTypes from 'prop-types'; import RULE_LEVELS from '../../common/consts/ScoutSuiteConsts/RuleLevels'; import STATUSES from '../../common/consts/StatusConsts'; -import {faCheckCircle, faCircle, faExclamationCircle, faQuestionCircle} from '@fortawesome/free-solid-svg-icons'; +import {faCheckCircle, faCircle, faExclamationCircle} from '@fortawesome/free-solid-svg-icons'; import RuleDisplay from './RuleDisplay'; export default function ScoutSuiteSingleRuleDropdown(props) { @@ -20,7 +20,7 @@ export default function ScoutSuiteSingleRuleDropdown(props) {