Skip to content

Commit

Permalink
Fix: Make report configs optional in alerts and reports
Browse files Browse the repository at this point in the history
If the report configs are not available, the report export and alert
dialogs will hide the report config fields.

This will make the dialogs work as expected if the report config
commands are disabled.
  • Loading branch information
timopollmeier committed Jul 22, 2024
1 parent a11f731 commit 158aaf7
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 74 deletions.
23 changes: 14 additions & 9 deletions src/gmp/commands/alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {map} from 'gmp/utils/array';

import registerCommand from 'gmp/command';
import {parseModelFromElement} from 'gmp/model';
import {isDefined} from 'gmp/utils/identity';

import Alert from 'gmp/models/alert';
import Credential from 'gmp/models/credential';
Expand Down Expand Up @@ -190,10 +191,12 @@ class AlertCommand extends EntityCommand {
new_alert.get_report_formats_response.report_format,
format => parseModelFromElement(format, 'reportformat'),
);
new_alert.report_configs = map(
new_alert.get_report_configs_response.report_config,
config => parseModelFromElement(config, 'reportconfig'),
);
if (isDefined(new_alert.get_report_configs_response)) {
new_alert.report_configs = map(
new_alert.get_report_configs_response.report_config,
config => parseModelFromElement(config, 'reportconfig'),
);
}
new_alert.credentials = map(
new_alert.get_credentials_response.credential,
credential => Credential.fromElement(credential),
Expand Down Expand Up @@ -226,11 +229,13 @@ class AlertCommand extends EntityCommand {
);
delete edit_alert.get_report_formats_response;

edit_alert.report_configs = map(
edit_alert.get_report_configs_response.report_config,
config => parseModelFromElement(config, 'reportconfig'),
);
delete edit_alert.get_report_configs_response;
if (isDefined(edit_alert.get_report_configs_response)) {
edit_alert.report_configs = map(
edit_alert.get_report_configs_response.report_config,
config => parseModelFromElement(config, 'reportconfig'),
);
delete edit_alert.get_report_configs_response;
}

edit_alert.credentials = map(
edit_alert.get_credentials_response.credential,
Expand Down
4 changes: 4 additions & 0 deletions src/web/pages/alerts/dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ class AlertDialog extends React.Component {
{values.method === METHOD_TYPE_SCP && (
<ScpMethodPart
prefix="method_data"
capabilities={capabilities}
credentials={credentials}
reportConfigs={report_configs}
reportFormats={report_formats}
Expand All @@ -736,6 +737,7 @@ class AlertDialog extends React.Component {
{values.method === METHOD_TYPE_SEND && (
<SendMethodPart
prefix="method_data"
capabilities={capabilities}
sendHost={values.method_data_send_host}
sendPort={values.method_data_send_port}
sendReportConfig={values.method_data_send_report_config}
Expand All @@ -758,6 +760,7 @@ class AlertDialog extends React.Component {
{values.method === METHOD_TYPE_SMB && (
<SmbMethodPart
prefix="method_data"
capabilities={capabilities}
credentials={credentials}
reportConfigs={report_configs}
reportFormats={report_formats}
Expand Down Expand Up @@ -801,6 +804,7 @@ class AlertDialog extends React.Component {
{values.method === METHOD_TYPE_VERINICE && (
<VeriniceMethodPart
prefix="method_data"
capabilities={capabilities}
credentials={credentials}
reportConfigs={report_configs}
reportFormats={report_formats}
Expand Down
47 changes: 28 additions & 19 deletions src/web/pages/alerts/emailmethodpart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,20 @@ const EmailMethodPart = ({
onChange={handleReportFormatIdChange}
/>
)}

<label htmlFor="report-config-select">Report Config</label>
<Select
disabled={notice !== EMAIL_NOTICE_INCLUDE}
name={prefix + 'notice_report_config'}
id="report-config-select"
value={reportConfigIdInState}
items={reportConfigItems}
onChange={handleReportConfigIdChange}
/>
{
capabilities.mayOp("get_report_configs") &&
<>
<label htmlFor="report-config-select">Report Config</label>
<Select
disabled={notice !== EMAIL_NOTICE_INCLUDE}
name={prefix + 'notice_report_config'}
id="report-config-select"
value={reportConfigIdInState}
items={reportConfigItems}
onChange={handleReportConfigIdChange}
/>
</>
}
</Divider>

<TextArea
Expand Down Expand Up @@ -251,15 +255,20 @@ const EmailMethodPart = ({
onChange={handleAttachFormatIdChange}
/>
)}
<label htmlFor="attach-config-select">Report Config</label>
<Select
disabled={notice !== EMAIL_NOTICE_ATTACH}
name={prefix + 'notice_attach_config'}
id="attach-config-select"
value={attachConfigIdInState}
items={attachConfigItems}
onChange={handleAttachConfigIdChange}
/>
{
capabilities.mayOp('get_report_configs') &&
<>
<label htmlFor="attach-config-select">Report Config</label>
<Select
disabled={notice !== EMAIL_NOTICE_ATTACH}
name={prefix + 'notice_attach_config'}
id="attach-config-select"
value={attachConfigIdInState}
items={attachConfigItems}
onChange={handleAttachConfigIdChange}
/>
</>
}
</Divider>
</Layout>
<TextArea
Expand Down
23 changes: 15 additions & 8 deletions src/web/pages/alerts/scpmethodpart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import NewIcon from 'web/components/icon/newicon';

const ScpMethodPart = ({
prefix,
capabilities,
credentials = [],
reportFormats,
reportConfigs,
Expand Down Expand Up @@ -136,20 +137,26 @@ const ScpMethodPart = ({
items={renderSelectItems(reportFormats)}
onChange={handleReportFormatIdChange}
/>
<label htmlFor="report-config-select">&nbsp; Report Config &nbsp; </label>
<Select
name={prefix + 'scp_report_config'}
id="report-config-select"
value={scpConfigIdInState}
items={reportConfigItems}
onChange={handleReportConfigIdChange}
/>
{
capabilities.mayOp('get_report_configs') &&
<>
<label htmlFor="report-config-select">&nbsp; Report Config &nbsp; </label>
<Select
name={prefix + 'scp_report_config'}
id="report-config-select"
value={scpConfigIdInState}
items={reportConfigItems}
onChange={handleReportConfigIdChange}
/>
</>
}
</FormGroup>
</Layout>
);
};

ScpMethodPart.propTypes = {
capabilities: PropTypes.capabilities.isRequired,
credentials: PropTypes.array,
prefix: PropTypes.string,
reportConfigs: PropTypes.array,
Expand Down
23 changes: 15 additions & 8 deletions src/web/pages/alerts/sendmethodpart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import TextField from 'web/components/form/textfield';

const SendMethodPart = ({
prefix,
capabilities,
reportConfigs,
reportFormats,
sendHost,
Expand Down Expand Up @@ -79,20 +80,26 @@ const SendMethodPart = ({
items={renderSelectItems(reportFormats)}
onChange={handleReportFormatIdChange}
/>
<label htmlFor="report-config-select">&nbsp; Report Config &nbsp; </label>
<Select
name={prefix + 'send_report_config'}
id="report-config-select"
value={sendConfigIdInState}
items={reportConfigItems}
onChange={handleReportConfigIdChange}
/>
{
capabilities.mayOp('get_report_configs') &&
<>
<label htmlFor="report-config-select">&nbsp; Report Config &nbsp; </label>
<Select
name={prefix + 'send_report_config'}
id="report-config-select"
value={sendConfigIdInState}
items={reportConfigItems}
onChange={handleReportConfigIdChange}
/>
</>
}
</FormGroup>
</Layout>
);
};

SendMethodPart.propTypes = {
capabilities: PropTypes.capabilities.isRequired,
prefix: PropTypes.string,
reportConfigs: PropTypes.array,
reportFormats: PropTypes.array,
Expand Down
23 changes: 15 additions & 8 deletions src/web/pages/alerts/smbmethodpart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const smbMaxProtocolItems = [

const SmbMethodPart = ({
prefix,
capabilities,
credentials = [],
reportConfigs,
reportFormats,
Expand Down Expand Up @@ -129,14 +130,19 @@ const SmbMethodPart = ({
value={reportFormatIdInState}
onChange={handleReportFormatIdChange}
/>
<label htmlFor="report-config-select">&nbsp; Report Config &nbsp; </label>
<Select
name={prefix + 'smb_report_config'}
id="report-config-select"
value={smbConfigIdInState}
items={reportConfigItems}
onChange={handleReportConfigIdChange}
/>
{
capabilities.mayOp('get_report_configs') &&
<>
<label htmlFor="report-config-select">&nbsp; Report Config &nbsp; </label>
<Select
name={prefix + 'smb_report_config'}
id="report-config-select"
value={smbConfigIdInState}
items={reportConfigItems}
onChange={handleReportConfigIdChange}
/>
</>
}
</FormGroup>

<FormGroup title={_('Max Protocol')}>
Expand All @@ -152,6 +158,7 @@ const SmbMethodPart = ({
};

SmbMethodPart.propTypes = {
capabilities: PropTypes.capabilities.isRequired,
credentials: PropTypes.array,
prefix: PropTypes.string,
reportConfigs: PropTypes.array,
Expand Down
23 changes: 15 additions & 8 deletions src/web/pages/alerts/verinicemethodpart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const VERINICE_CREDENTIAL_TYPES = [USERNAME_PASSWORD_CREDENTIAL_TYPE];

const VeriniceMethodPart = ({
prefix,
capabilities,
veriniceServerUrl,
veriniceServerCredential,
veriniceServerReportConfig,
Expand Down Expand Up @@ -102,20 +103,26 @@ const VeriniceMethodPart = ({
value={reportFormatIdInState}
onChange={handleReportFormatIdChange}
/>
<label htmlFor="report-config-select">&nbsp; Report Config &nbsp; </label>
<Select
name={prefix + 'verinice_server_report_config'}
id="report-config-select"
value={veriniceServerConfigIdInState}
items={reportConfigItems}
onChange={handleReportConfigIdChange}
/>
{
capabilities.mayOp('get_report_configs') &&
<>
<label htmlFor="report-config-select">&nbsp; Report Config &nbsp; </label>
<Select
name={prefix + 'verinice_server_report_config'}
id="report-config-select"
value={veriniceServerConfigIdInState}
items={reportConfigItems}
onChange={handleReportConfigIdChange}
/>
</>
}
</FormGroup>
</Layout>
);
};

VeriniceMethodPart.propTypes = {
capabilities: PropTypes.capabilities,
credentials: PropTypes.array,
prefix: PropTypes.string,
reportConfigs: PropTypes.array,
Expand Down
33 changes: 19 additions & 14 deletions src/web/pages/reports/downloadreportdialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ const DownloadReportDialog = ({
onSave={handleSave}
>
{({values, onValueChange}) => {
const filteredReportConfigs = reportConfigs.filter(
config => config.report_format.id === reportFormatIdInState,
);
const filteredReportConfigs = isDefined(reportConfigs)
? reportConfigs.filter(
config => config.report_format.id === reportFormatIdInState,
)
: [];

return (
<Layout flex="column">
Expand All @@ -118,17 +120,20 @@ const DownloadReportDialog = ({
/>
</Divider>
</FormGroup>
<FormGroup title={_('Report Config')} titleSize="3">
<Divider flex="column">
<Select
name="reportConfigId"
value={reportConfigIdInState}
items={renderSelectItems(filteredReportConfigs, '')}
width="auto"
onChange={handleReportConfigIdChange}
/>
</Divider>
</FormGroup>
{
isDefined(reportConfigs) &&
<FormGroup title={_('Report Config')} titleSize="3">
<Divider flex="column">
<Select
name="reportConfigId"
value={reportConfigIdInState}
items={renderSelectItems(filteredReportConfigs, '')}
width="auto"
onChange={handleReportConfigIdChange}
/>
</Divider>
</FormGroup>
}
<StyledDiv>
<CheckBox
name="storeAsDefault"
Expand Down

0 comments on commit 158aaf7

Please sign in to comment.