Skip to content

Commit

Permalink
Merge pull request #1671 from saberlynx/task-dialog-default
Browse files Browse the repository at this point in the history
Decide whether to default to full and fast scan config (task dialog)
  • Loading branch information
bjoernricks authored Oct 9, 2019
2 parents 17fd0bf + 943dc70 commit 80b2985
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 70 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
[#1466](https://github.com/greenbone/gsa/pull/1466) [#1467](https://github.com/greenbone/gsa/pull/1467)

### Changed
- Decide whether to default to full and fast scan config (task dialog)[#1671](https://github.com/greenbone/gsa/pull/1671)
- Determine the to be applied filter of a list page in GSA and don't rely on the
backend [#1631](https://github.com/greenbone/gsa/pull/1631), [#1653](https://github.com/greenbone/gsa/pull/1653)
- Change gmpname for vulnerability and secinfo pages [#1652](https://github.com/greenbone/gsa/pull/1652)
Expand Down
146 changes: 76 additions & 70 deletions gsa/src/web/pages/tasks/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

import React from 'react';
import React, {useState} from 'react';

import _ from 'gmp/locale';

import logger from 'gmp/log';

import {forEach, first} from 'gmp/utils/array';
import {isDefined, isArray} from 'gmp/utils/identity';
import {selectSaveId} from 'gmp/utils/id';
Expand Down Expand Up @@ -75,8 +73,6 @@ import Layout from 'web/components/layout/layout';
import AddResultsToAssetsGroup from './addresultstoassetsgroup';
import AutoDeleteReportsGroup from './autodeletereportsgroup';

const log = logger.getLogger('web.tasks.dialog');

const sort_scan_configs = (scan_configs = []) => {
const sorted_scan_configs = {
[OPENVAS_SCAN_CONFIG_TYPE]: [],
Expand Down Expand Up @@ -105,64 +101,21 @@ const get_scanner = (scanners, scanner_id) => {
});
};

class ScannerSelect extends React.Component {
constructor(...args) {
super(...args);

this.handleScannerChange = this.handleScannerChange.bind(this);
}

handleScannerChange(value, name) {
const {
scanners,
scanConfigs,
onScanConfigChange,
onScannerChange,
} = this.props;
let config_id;

const scanner = get_scanner(scanners, value);
const scanner_type = isDefined(scanner) ? scanner.scannerType : undefined;

if (
scanner_type === OPENVAS_SCANNER_TYPE ||
scanner_type === GMP_SCANNER_TYPE
) {
config_id = selectSaveId(
scanConfigs[OPENVAS_SCAN_CONFIG_TYPE],
FULL_AND_FAST_SCAN_CONFIG_ID,
);
} else if (scanner_type === OSP_SCANNER_TYPE) {
config_id = selectSaveId(scanConfigs[OSP_SCAN_CONFIG_TYPE], UNSET_VALUE);
} else {
config_id = UNSET_VALUE;
}

log.debug('on scanner change', value, config_id, scanner);
const ScannerSelect = props => {
const {changeTask, scannerId, scanners, onChange} = props;

if (isDefined(onScannerChange)) {
onScannerChange(value);
}
if (isDefined(onScanConfigChange)) {
onScanConfigChange(config_id);
}
}

render() {
const {changeTask, scannerId, scanners} = this.props;
return (
<FormGroup title={_('Scanner')}>
<Select
name="scanner_id"
value={scannerId}
disabled={!changeTask}
items={renderSelectItems(scanners)}
onChange={this.handleScannerChange}
/>
</FormGroup>
);
}
}
return (
<FormGroup title={_('Scanner')}>
<Select
name="scanner_id"
value={scannerId}
disabled={!changeTask}
items={renderSelectItems(scanners)}
onChange={onChange}
/>
</FormGroup>
);
};

ScannerSelect.propTypes = {
changeTask: PropTypes.bool.isRequired,
Expand All @@ -172,8 +125,7 @@ ScannerSelect.propTypes = {
}),
scannerId: PropTypes.id.isRequired,
scanners: PropTypes.array.isRequired,
onScanConfigChange: PropTypes.func.isRequired,
onScannerChange: PropTypes.func.isRequired,
onChange: PropTypes.func.isRequired,
};

const TaskDialog = ({
Expand All @@ -186,7 +138,7 @@ const TaskDialog = ({
auto_delete_data = AUTO_DELETE_KEEP_DEFAULT_VALUE,
capabilities,
comment = '',
config_id = FULL_AND_FAST_SCAN_CONFIG_ID,
config_id,
hosts_ordering = HOSTS_ORDERING_SEQUENTIAL,
in_assets = YES_VALUE,
max_checks = DEFAULT_MAX_CHECKS,
Expand Down Expand Up @@ -225,6 +177,55 @@ const TaskDialog = ({
const scanner = get_scanner(scanners, scanner_id);
const scanner_type = isDefined(scanner) ? scanner.scannerType : undefined;

const [configType, setConfigType] = useState('openvas');
const [prevConfigType, setPrevConfigType] = useState('openvas');

// eslint-disable-next-line no-shadow
const handleScannerChange = (value, name) => {
// eslint-disable-next-line no-shadow
const scanner = get_scanner(scanners, value);
// eslint-disable-next-line no-shadow
const scanner_type = isDefined(scanner) ? scanner.scannerType : undefined;

if (
scanner_type === OPENVAS_SCANNER_TYPE ||
scanner_type === OSP_SENSOR_SCANNER_TYPE ||
scanner_type === GMP_SCANNER_TYPE
) {
setConfigType('openvas');
} else if (scanner_type === OSP_SCANNER_TYPE) {
setConfigType('osp');
} else {
setConfigType('other');
}

if (isDefined(onScannerChange)) {
onScannerChange(value);
}

if (configType !== prevConfigType && isDefined(onScanConfigChange)) {
if (
scanner_type === OPENVAS_SCANNER_TYPE ||
scanner_type === GMP_SCANNER_TYPE ||
scanner_type === OSP_SENSOR_SCANNER_TYPE
) {
onScanConfigChange(
selectSaveId(
sorted_scan_configs[OPENVAS_SCAN_CONFIG_TYPE],
FULL_AND_FAST_SCAN_CONFIG_ID,
),
);
} else if (scanner_type === OSP_SCANNER_TYPE) {
onScanConfigChange(
selectSaveId(sorted_scan_configs[OSP_SCAN_CONFIG_TYPE], UNSET_VALUE),
);
} else {
onScanConfigChange(UNSET_VALUE);
}
}
setPrevConfigType(configType);
};

const tag_items = renderSelectItems(tags);

const target_items = renderSelectItems(targets);
Expand Down Expand Up @@ -260,6 +261,7 @@ const TaskDialog = ({
auto_delete,
auto_delete_data,
comment,
config_id,
hosts_ordering,
in_assets,
max_checks,
Expand Down Expand Up @@ -464,12 +466,10 @@ const TaskDialog = ({
}
>
<ScannerSelect
scanConfigs={sorted_scan_configs}
scanners={scanners}
scannerId={state.scanner_id}
changeTask={change_task}
onScanConfigChange={onScanConfigChange}
onScannerChange={onScannerChange}
onChange={handleScannerChange}
/>
</div>
{use_openvas_scan_config && (
Expand All @@ -489,7 +489,10 @@ const TaskDialog = ({
disabled={!change_task}
items={openvas_scan_config_items}
value={openvas_config_id}
onChange={onScanConfigChange}
onChange={value => {
onScanConfigChange(value);
setPrevConfigType(configType);
}}
/>
</div>
</FormGroup>
Expand Down Expand Up @@ -557,7 +560,10 @@ const TaskDialog = ({
name="config_id"
items={osp_scan_config_items}
value={osp_config_id}
onChange={onScanConfigChange}
onChange={value => {
onScanConfigChange(value);
setPrevConfigType(configType);
}}
/>
</FormGroup>
)}
Expand Down

0 comments on commit 80b2985

Please sign in to comment.