Skip to content

Commit

Permalink
feat(RulesTable): RHICOMPL-1549 remediationAvailableFilter
Browse files Browse the repository at this point in the history
Add a filter to the rules table for rules with remediations available.
When remediationsEnabled, this filter will also be enabled.

Signed-off-by: Andrew Kofink <akofink@redhat.com>
  • Loading branch information
akofink committed Mar 25, 2021
1 parent 30a83ef commit d29c69f
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 11 deletions.
6 changes: 3 additions & 3 deletions packages/inventory-compliance/src/Fixtures/Fixtures.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ export const selectColumns = (columnTitles) => (
);

class SystemRulesTable extends React.Component {
remediationAvailableFilter = this.props.remediationAvailableFilter || this.props.remediationsEnabled;

config = buildFilterConfig({
selectedFilter: this.props.selectedFilter,
remediationAvailableFilter: this.remediationAvailableFilter,
showPassFailFilter: (this.props.columns.filter((c) => (c.title === 'Passed')).length > 0)
});
filterConfigBuilder = new FilterConfigBuilder(this.config);
Expand All @@ -47,7 +50,8 @@ class SystemRulesTable extends React.Component {
openIds: [],
activeFilters: this.filterConfigBuilder.initialDefaultState({
selected: this.props.selectedFilter ? [ 'selected' ] : undefined,
passed: this.props.hidePassed ? 'failed' : undefined
passed: this.props.hidePassed ? 'failed' : undefined,
remediationAvailable: this.remediationAvailableFilter ? 'true' : undefined
})
};

Expand Down Expand Up @@ -403,6 +407,7 @@ SystemRulesTable.propTypes = {
tailoringEnabled: propTypes.bool,
selectedRefIds: propTypes.array,
selectedFilter: propTypes.bool,
remediationAvailableFilter: propTypes.bool,
handleSelect: propTypes.func,
columns: propTypes.arrayOf(
propTypes.shape(
Expand All @@ -419,6 +424,7 @@ SystemRulesTable.defaultProps = {
profileRules: [{ rules: [] }],
hidePassed: false,
selectedFilter: false,
remediationAvailableFilter: false,
remediationsEnabled: true,
tailoringEnabled: false,
selectedRefIds: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ describe('SystemRulesTable component', () => {
expect(instance.getRules().length).toEqual(1);
});

it('should render filtered rows by remediationAvailable', async () => {
const wrapper = shallow(
<SystemRulesTable
profileRules={ profileRules }
remediationAvailableFilter
loading={ false }
system={ system }
itemsPerPage={ 100 }
columns={ columns }
/>
);
const instance = wrapper.instance();
expect(instance.getRules().length).toEqual(52);
await instance.onFilterUpdate('remediationAvailable', [ 'true' ]);
expect(instance.getRules().length).toEqual(3);
});

it('should render filtered rows by severity', async () => {
const wrapper = shallow(
<SystemRulesTable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,22 @@ exports[`SystemRulesTable component should render 1`] = `
"placeholder": "Filter by passed",
"type": "radio",
},
Object {
"filterValues": Object {
"items": Array [
Object {
"label": "Remediation available",
"value": "true",
},
],
"onChange": [Function],
"value": Array [],
},
"id": "remediationavailable",
"label": "Remediation available",
"placeholder": "Filter by remediation available",
"type": "checkbox",
},
],
}
}
Expand Down Expand Up @@ -1304,6 +1320,22 @@ exports[`SystemRulesTable component should render filtered and search mixed resu
"placeholder": "Filter by passed",
"type": "radio",
},
Object {
"filterValues": Object {
"items": Array [
Object {
"label": "Remediation available",
"value": "true",
},
],
"onChange": [Function],
"value": Array [],
},
"id": "remediationavailable",
"label": "Remediation available",
"placeholder": "Filter by remediation available",
"type": "checkbox",
},
],
}
}
Expand Down Expand Up @@ -1677,6 +1709,22 @@ exports[`SystemRulesTable component should render search results by rule name 1`
"placeholder": "Filter by passed",
"type": "radio",
},
Object {
"filterValues": Object {
"items": Array [
Object {
"label": "Remediation available",
"value": "true",
},
],
"onChange": [Function],
"value": Array [],
},
"id": "remediationavailable",
"label": "Remediation available",
"placeholder": "Filter by remediation available",
"type": "checkbox",
},
],
}
}
Expand Down Expand Up @@ -2104,6 +2152,22 @@ exports[`SystemRulesTable component should render search results on any page, re
"placeholder": "Filter by passed",
"type": "radio",
},
Object {
"filterValues": Object {
"items": Array [
Object {
"label": "Remediation available",
"value": "true",
},
],
"onChange": [Function],
"value": Array [],
},
"id": "remediationavailable",
"label": "Remediation available",
"placeholder": "Filter by remediation available",
"type": "checkbox",
},
],
}
}
Expand Down Expand Up @@ -2522,6 +2586,22 @@ exports[`SystemRulesTable component should render sorted rows 1`] = `
"placeholder": "Filter by passed",
"type": "radio",
},
Object {
"filterValues": Object {
"items": Array [
Object {
"label": "Remediation available",
"value": "true",
},
],
"onChange": [Function],
"value": Array [],
},
"id": "remediationavailable",
"label": "Remediation available",
"placeholder": "Filter by remediation available",
"type": "checkbox",
},
],
}
}
Expand Down Expand Up @@ -3618,6 +3698,22 @@ exports[`SystemRulesTable component should render sorted rows 2`] = `
"placeholder": "Filter by passed",
"type": "radio",
},
Object {
"filterValues": Object {
"items": Array [
Object {
"label": "Remediation available",
"value": "true",
},
],
"onChange": [Function],
"value": Array [],
},
"id": "remediationavailable",
"label": "Remediation available",
"placeholder": "Filter by remediation available",
"type": "checkbox",
},
],
}
}
Expand Down Expand Up @@ -4014,7 +4110,12 @@ exports[`SystemRulesTable component should render sorted rows 2`] = `
/>,
},
Object {
"title": "No",
"title": <CheckCircleIcon
className="ins-u-passed"
color="currentColor"
noVerticalAlign={false}
size="sm"
/>,
},
],
"isOpen": false,
Expand Down Expand Up @@ -4046,7 +4147,7 @@ exports[`SystemRulesTable component should render sorted rows 2`] = `
"rationale": "The atd service could be used by an unsophisticated insider to carry out activities outside of a normal login session, which could complicate accountability. Furthermore, the need to schedule tasks with at or batch is not common.",
"refId": "xccdf_org.ssgproject.content_rule_service_atd_disabled",
"references": Array [],
"remediationAvailable": false,
"remediationAvailable": true,
"rowKey": "xccdf_org.ssgproject.content_rule_service_atd_disabled-xccdf_org.ssgproject.content_profile_pci-dss",
"severity": "medium",
"title": "Disable At Service (atd)",
Expand Down Expand Up @@ -4088,7 +4189,12 @@ exports[`SystemRulesTable component should render sorted rows 2`] = `
/>,
},
Object {
"title": "No",
"title": <CheckCircleIcon
className="ins-u-passed"
color="currentColor"
noVerticalAlign={false}
size="sm"
/>,
},
],
"isOpen": false,
Expand Down Expand Up @@ -4120,7 +4226,7 @@ exports[`SystemRulesTable component should render sorted rows 2`] = `
"rationale": "Mishandling crash data could expose sensitive information about vulnerabilities in software executing on the system, as well as sensitive information from within a process's address space or registers.",
"refId": "xccdf_org.ssgproject.content_rule_service_abrtd_disabled",
"references": Array [],
"remediationAvailable": false,
"remediationAvailable": true,
"rowKey": "xccdf_org.ssgproject.content_rule_service_abrtd_disabled-xccdf_org.ssgproject.content_profile_pci-dss",
"severity": "medium",
"title": "Disable Automatic Bug Reporting Tool (abrtd)",
Expand Down Expand Up @@ -4310,7 +4416,12 @@ exports[`SystemRulesTable component should render sorted rows 2`] = `
/>,
},
Object {
"title": "No",
"title": <CheckCircleIcon
className="ins-u-passed"
color="currentColor"
noVerticalAlign={false}
size="sm"
/>,
},
],
"isOpen": false,
Expand Down Expand Up @@ -4342,7 +4453,7 @@ exports[`SystemRulesTable component should render sorted rows 2`] = `
"rationale": "The oddjobd service may provide necessary functionality in some environments, and can be disabled if it is not needed. Execution of tasks by privileged programs, on behalf of unprivileged ones, has traditionally been a source of privilege escalation security issues.",
"refId": "xccdf_org.ssgproject.content_rule_service_oddjobd_disabled",
"references": Array [],
"remediationAvailable": false,
"remediationAvailable": true,
"rowKey": "xccdf_org.ssgproject.content_rule_service_oddjobd_disabled-xccdf_org.ssgproject.content_profile_pci-dss",
"severity": "medium",
"title": "Disable Odd Job Daemon (oddjobd)",
Expand Down Expand Up @@ -5747,6 +5858,22 @@ exports[`SystemRulesTable component tailoring rules should be able to filter by
"placeholder": "Filter by selected",
"type": "checkbox",
},
Object {
"filterValues": Object {
"items": Array [
Object {
"label": "Remediation available",
"value": "true",
},
],
"onChange": [Function],
"value": Array [],
},
"id": "remediationavailable",
"label": "Remediation available",
"placeholder": "Filter by remediation available",
"type": "checkbox",
},
],
}
}
Expand Down Expand Up @@ -6072,6 +6199,22 @@ exports[`SystemRulesTable component tailoring rules should be able to filter by
"placeholder": "Filter by selected",
"type": "checkbox",
},
Object {
"filterValues": Object {
"items": Array [
Object {
"label": "Remediation available",
"value": "true",
},
],
"onChange": [Function],
"value": Array [],
},
"id": "remediationavailable",
"label": "Remediation available",
"placeholder": "Filter by remediation available",
"type": "checkbox",
},
],
}
}
Expand Down Expand Up @@ -7030,6 +7173,22 @@ exports[`SystemRulesTable component tailoring rules should be able to show all s
"placeholder": "Filter by selected",
"type": "checkbox",
},
Object {
"filterValues": Object {
"items": Array [
Object {
"label": "Remediation available",
"value": "true",
},
],
"onChange": [Function],
"value": Array [],
},
"id": "remediationavailable",
"label": "Remediation available",
"placeholder": "Filter by remediation available",
"type": "checkbox",
},
],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,16 @@ export const POLICIES_FILTER_CONFIG = (policies) => ({
))
});

const buildFilterConfig = ({ showPassFailFilter, policies, selectedFilter }) => {
export const REMEDIATION_AVAILABLE_FILTER_CONFIG = {
type: conditionalFilterType.checkbox,
label: 'Remediation available',
items: [
{ label: 'Remediation available', value: 'true' }
],
filter: (rules, value) => rules.filter(rule => rule.remediationAvailable)
};

const buildFilterConfig = ({ showPassFailFilter, policies, selectedFilter, remediationAvailableFilter }) => {
const config = [ ...BASE_FILTER_CONFIGURATION ];

if (showPassFailFilter) {
Expand All @@ -91,6 +100,10 @@ const buildFilterConfig = ({ showPassFailFilter, policies, selectedFilter }) =>
config.push(POLICIES_FILTER_CONFIG(policies));
}

if (remediationAvailableFilter) {
config.push(REMEDIATION_AVAILABLE_FILTER_CONFIG);
}

return config;
};

Expand Down

0 comments on commit d29c69f

Please sign in to comment.