Skip to content

Commit

Permalink
Merge pull request #4187 from greenbone/GEA-712_Remove_feature_toggle…
Browse files Browse the repository at this point in the history
…_COMPLIANCE_REPORTS_opensight

Removed feature toggle for compliance report views.
  • Loading branch information
a-h-abdelsalam authored Nov 7, 2024
2 parents bfbd85a + 15ef6bd commit f355cbf
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 200 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

1 change: 0 additions & 1 deletion src/web/components/menu/menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ const Menu = () => {
label: 'Compliance Audit Reports',
to: '/auditreports',
activeCondition: useIsActive('/auditreports'),
featureEnabled: 'COMPLIANCE_REPORTS',
},
],
secInfo: [
Expand Down
120 changes: 10 additions & 110 deletions src/web/pages/audits/__tests__/row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import {getActionItems} from 'web/components/testing';
import Row from '../row';

const gmp = {settings: {}};
const featureList = [{name: 'COMPLIANCE_REPORTS', _enabled: 0}];
const caps = new Capabilities(['everything'], featureList);
const caps = new Capabilities(['everything']);

const lastReport = {
report: {
Expand Down Expand Up @@ -110,11 +109,11 @@ describe('Audit Row tests', () => {
const detailsLinks = screen.getAllByTestId('details-link');

expect(detailsLinks[0]).toHaveTextContent('Done');
expect(detailsLinks[0]).toHaveAttribute('href', '/report/1234');
expect(detailsLinks[0]).toHaveAttribute('href', '/auditreport/1234');

// Report
expect(detailsLinks[1]).toHaveTextContent('Wed, Jul 10, 2019 2:51 PM CEST');
expect(detailsLinks[1]).toHaveAttribute('href', '/report/1234');
expect(detailsLinks[1]).toHaveAttribute('href', '/auditreport/1234');

// Compliance Status
expect(bars[1]).toHaveAttribute('title', '50%');
Expand Down Expand Up @@ -375,7 +374,7 @@ describe('Audit Row tests', () => {
const detailsLinks = getAllByTestId('details-link');

expect(detailsLinks[0]).toHaveTextContent('0 %');
expect(detailsLinks[0]).toHaveAttribute('href', '/report/5678');
expect(detailsLinks[0]).toHaveAttribute('href', '/auditreport/5678');

// Report
expect(detailsLinks.length).toBe(1);
Expand Down Expand Up @@ -483,11 +482,11 @@ describe('Audit Row tests', () => {
const detailsLinks = getAllByTestId('details-link');

expect(detailsLinks[0]).toHaveTextContent('Stopped');
expect(detailsLinks[0]).toHaveAttribute('href', '/report/5678');
expect(detailsLinks[0]).toHaveAttribute('href', '/auditreport/5678');

// Report
expect(detailsLinks[1]).toHaveTextContent('Wed, Jul 10, 2019 2:51 PM CEST');
expect(detailsLinks[1]).toHaveAttribute('href', '/report/1234');
expect(detailsLinks[1]).toHaveAttribute('href', '/auditreport/1234');

// Compliance Status
expect(bars[1]).toHaveAttribute('title', '50%');
Expand Down Expand Up @@ -593,11 +592,11 @@ describe('Audit Row tests', () => {
const detailsLinks = getAllByTestId('details-link');

expect(detailsLinks[0]).toHaveTextContent('Done');
expect(detailsLinks[0]).toHaveAttribute('href', '/report/1234');
expect(detailsLinks[0]).toHaveAttribute('href', '/auditreport/1234');

// Report
expect(detailsLinks[1]).toHaveTextContent('Wed, Jul 10, 2019 2:51 PM CEST');
expect(detailsLinks[1]).toHaveAttribute('href', '/report/1234');
expect(detailsLinks[1]).toHaveAttribute('href', '/auditreport/1234');

// Compliance Status
expect(bars[1]).toHaveAttribute('title', '50%');
Expand Down Expand Up @@ -706,11 +705,11 @@ describe('Audit Row tests', () => {
const detailsLinks = getAllByTestId('details-link');

expect(detailsLinks[0]).toHaveTextContent('Done');
expect(detailsLinks[0]).toHaveAttribute('href', '/report/1234');
expect(detailsLinks[0]).toHaveAttribute('href', '/auditreport/1234');

// Report
expect(detailsLinks[1]).toHaveTextContent('Wed, Jul 10, 2019 2:51 PM CEST');
expect(detailsLinks[1]).toHaveAttribute('href', '/report/1234');
expect(detailsLinks[1]).toHaveAttribute('href', '/auditreport/1234');

// Compliance Status
expect(bars[1]).toHaveAttribute('title', '50%');
Expand Down Expand Up @@ -760,102 +759,3 @@ describe('Audit Row tests', () => {

console.warn = consoleError;
});

describe('Audit Row tests - compliance reports enabled', () => {
// deactivate console.error for tests
// to make it possible to test a row without a table
console.error = () => {};
const featureList = [{name: 'COMPLIANCE_REPORTS', _enabled: 1}];
const caps = new Capabilities(['everything'], featureList);

test('should render', () => {
const audit = Audit.fromElement({
_id: '314',
owner: {name: 'username'},
name: 'foo',
comment: 'bar',
status: AUDIT_STATUS.done,
alterable: '0',
last_report: lastReport,
permissions: {permission: [{name: 'everything'}]},
target: {_id: '5678', name: 'target'},
usage_type: 'audit',
});

const handleAuditClone = testing.fn();
const handleAuditDelete = testing.fn();
const handleAuditDownload = testing.fn();
const handleAuditEdit = testing.fn();
const handleAuditResume = testing.fn();
const handleAuditStart = testing.fn();
const handleAuditStop = testing.fn();
const handleReportDownload = testing.fn();
const handleToggleDetailsClick = testing.fn();

const {render, store} = rendererWith({
gmp,
capabilities: caps,
store: true,
router: true,
});

store.dispatch(setTimezone('CET'));
store.dispatch(setUsername('username'));

const {baseElement, getAllByTestId} = render(
<Row
entity={audit}
links={true}
gcrFormatDefined={true}
onAuditCloneClick={handleAuditClone}
onAuditDeleteClick={handleAuditDelete}
onAuditDownloadClick={handleAuditDownload}
onAuditEditClick={handleAuditEdit}
onAuditResumeClick={handleAuditResume}
onAuditStartClick={handleAuditStart}
onAuditStopClick={handleAuditStop}
onReportDownloadClick={handleReportDownload}
onToggleDetailsClick={handleToggleDetailsClick}
/>,
);

expect(baseElement).toBeVisible();

// Name
expect(baseElement).toHaveTextContent('foo');
expect(baseElement).toHaveTextContent('(bar)');

// Status
const bars = getAllByTestId('progressbar-box');

expect(bars[0]).toHaveAttribute('title', AUDIT_STATUS.done);
expect(bars[0]).toHaveTextContent(AUDIT_STATUS.done);

const detailsLinks = getAllByTestId('details-link');

expect(detailsLinks[0]).toHaveTextContent('Done');
expect(detailsLinks[0]).toHaveAttribute('href', '/auditreport/1234');

// Report
expect(detailsLinks[1]).toHaveTextContent('Wed, Jul 10, 2019 2:51 PM CEST');
expect(detailsLinks[1]).toHaveAttribute('href', '/auditreport/1234');

// Compliance Status
expect(bars[1]).toHaveAttribute('title', '50%');
expect(bars[1]).toHaveTextContent('50%');

// Actions
const icons = getAllByTestId('svg-icon');

expect(icons[0]).toHaveAttribute('title', 'Start');
expect(icons[1]).toHaveAttribute('title', 'Audit is not stopped');
expect(icons[2]).toHaveAttribute('title', 'Move Audit to trashcan');
expect(icons[3]).toHaveAttribute('title', 'Edit Audit');
expect(icons[4]).toHaveAttribute('title', 'Clone Audit');
expect(icons[5]).toHaveAttribute('title', 'Export Audit');
expect(icons[6]).toHaveAttribute(
'title',
'Download Greenbone Compliance Report',
);
});
});
10 changes: 2 additions & 8 deletions src/web/pages/audits/row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ import {GREENBONE_SENSOR_SCANNER_TYPE} from 'gmp/models/scanner';

import ComplianceStatusBar from 'web/components/bar/compliancestatusbar';

import {renderReport} from 'web/pages/tasks/row';
import DateTime from 'web/components/date/datetime';
import DetailsLink from 'web/components/link/detailslink';
import useCapabilities from 'web/hooks/useCapabilities';

const renderAuditReport = (report, links) => {
if (!isDefined(report)) {
Expand Down Expand Up @@ -86,7 +84,6 @@ const Row = ({
}) => {
const {scanner, observers} = entity;
const obs = [];
const caps = useCapabilities();

if (isDefined(observers)) {
if (isDefined(observers.user)) {
Expand Down Expand Up @@ -146,15 +143,12 @@ const Row = ({
</TableData>
<TableData>
<AuditStatus
isAudit={caps.featureEnabled('COMPLIANCE_REPORTS')}
isAudit={true}
task={entity}
links={links}/>
</TableData>
<TableData>
{caps.featureEnabled('COMPLIANCE_REPORTS')
? renderAuditReport(entity.last_report, links)
: renderReport(entity.last_report, links)
}
{renderAuditReport(entity.last_report, links)}
</TableData>
<TableData>
{isDefined(entity.last_report) && (
Expand Down
9 changes: 2 additions & 7 deletions src/web/pages/filters/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import FilterDialog from 'web/pages/filters/dialog';

const FILTER_OPTIONS = [
['alert', _l('Alert')],
['audit_report', _l('Audit Report')],
['credential', _l('Credential')],
['filter', _l('Filter')],
['group', _l('Group')],
Expand Down Expand Up @@ -75,13 +76,7 @@ class FilterComponent extends React.Component {

openFilterDialog(filter) {
const {capabilities} = this.props;
const filterOptions = [
...(capabilities.featureEnabled('COMPLIANCE_REPORTS')
? [['audit_report', _l('Audit Report')]]
: []),
...FILTER_OPTIONS
];
let types = filterOptions.filter(option =>
let types = FILTER_OPTIONS.filter(option =>
filter_types(capabilities, option[0]),
);

Expand Down
13 changes: 3 additions & 10 deletions src/web/pages/start/dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {DFNCERT_DISPLAYS} from '../dfncert/dashboard';
import {TICKETS_DISPLAYS} from '../tickets/dashboard';
import {AUDIT_REPORTS_DISPLAYS} from '../reports/auditdashboard';
import {DEFAULT_DISPLAYS} from './newdashboarddialog';
import useCapabilities from 'web/hooks/useCapabilities';

const ALL_DISPLAYS = [
...TASKS_DISPLAYS,
Expand All @@ -46,6 +45,7 @@ const ALL_DISPLAYS = [
...CPES_DISPLAYS,
...DFNCERT_DISPLAYS,
...TICKETS_DISPLAYS,
...AUDIT_REPORTS_DISPLAYS,
];

const StartDashboard = ({
Expand All @@ -58,21 +58,14 @@ const StartDashboard = ({
onResetDashboard,
...props
}) => {
const caps = useCapabilities();
const displayIds = [
...ALL_DISPLAYS,
...(caps.featureEnabled('COMPLIANCE_REPORTS')
? AUDIT_REPORTS_DISPLAYS
: [])
];
return (
<Layout flex="column" grow>
<Layout align="end">
<DashboardControls
settings={settings}
canAdd={canAddDisplay(props)}
dashboardId={id}
displayIds={displayIds}
displayIds={ALL_DISPLAYS}
onInteraction={onInteraction}
onNewDisplay={onNewDisplay}
onResetClick={onResetDashboard}
Expand All @@ -86,7 +79,7 @@ const StartDashboard = ({
showFilterSelection
showFilterString
defaultDisplays={DEFAULT_DISPLAYS}
permittedDisplays={displayIds}
permittedDisplays={ALL_DISPLAYS}
loadSettings={loadSettings}
saveSettings={saveSettings}
onInteraction={onInteraction}
Expand Down
9 changes: 2 additions & 7 deletions src/web/pages/tags/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const MAX_RESOURCES = 40; // concerns listing in "Assigned Resources" tab
const TYPES = [
'alert',
'audit',
'auditreport',
'host',
'operatingsystem',
'cpe',
Expand Down Expand Up @@ -108,13 +109,7 @@ class TagComponent extends React.Component {

getResourceTypes() {
const {capabilities} = this.props;
const types = [
...TYPES,
...(capabilities.featureEnabled('COMPLIANCE_REPORTS')
? ['auditreport']
: [])
].sort();
return types.map(type =>
return TYPES.map(type =>
capabilities.mayAccess(type) ? [type, typeName(type)] : undefined,
).filter(isDefined);
}
Expand Down
24 changes: 10 additions & 14 deletions src/web/pages/usersettings/filterpart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import PropTypes from 'web/utils/proptypes';
import {renderSelectItems, UNSET_VALUE} from 'web/utils/render';

import useTranslation from 'web/hooks/useTranslation';
import useCapabilities from 'web/hooks/useCapabilities';

const filterFilters = (filters, type) =>
filters.filter(filter => filter.filter_type === type);
Expand Down Expand Up @@ -52,7 +51,6 @@ const FilterPart = ({
onChange,
}) => {
const [_] = useTranslation();
const caps = useCapabilities();
return (
<React.Fragment>
<FormGroup title={_('Alerts Filter')} titleSize="3">
Expand All @@ -66,19 +64,17 @@ const FilterPart = ({
onChange={onChange}
/>
</FormGroup>
{caps.featureEnabled('COMPLIANCE_REPORTS') && (
<FormGroup title={_('Audit Reports Filter')} titleSize="3">
<Select
name="auditReportsFilter"
value={auditReportsFilter}
items={renderSelectItems(
filterFilters(filters, 'audit_report'),
UNSET_VALUE,
)}
onChange={onChange}
/>
<FormGroup title={_('Audit Reports Filter')} titleSize="3">
<Select
name="auditReportsFilter"
value={auditReportsFilter}
items={renderSelectItems(
filterFilters(filters, 'audit_report'),
UNSET_VALUE,
)}
onChange={onChange}
/>
</FormGroup>
)}
<FormGroup title={_('Scan Configs Filter')} titleSize="3">
<Select
name="configsFilter"
Expand Down
Loading

0 comments on commit f355cbf

Please sign in to comment.