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 16, 2024
1 parent 2596273 commit b776c4b
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'),
);
}

Check warning on line 199 in src/gmp/commands/alerts.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/alerts.js#L194-L199

Added lines #L194 - L199 were not covered by tests
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;
}

Check warning on line 238 in src/gmp/commands/alerts.js

View check run for this annotation

Codecov / codecov/patch

src/gmp/commands/alerts.js#L232-L238

Added lines #L232 - L238 were not covered by tests

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}

Check warning on line 720 in src/web/pages/alerts/dialog.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/alerts/dialog.jsx#L720

Added line #L720 was not covered by tests
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}

Check warning on line 740 in src/web/pages/alerts/dialog.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/alerts/dialog.jsx#L740

Added line #L740 was not covered by tests
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}

Check warning on line 763 in src/web/pages/alerts/dialog.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/alerts/dialog.jsx#L763

Added line #L763 was not covered by tests
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}

Check warning on line 807 in src/web/pages/alerts/dialog.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/alerts/dialog.jsx#L807

Added line #L807 was not covered by tests
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}
/>
</>
}

Check warning on line 215 in src/web/pages/alerts/emailmethodpart.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/alerts/emailmethodpart.jsx#L202-L215

Added lines #L202 - L215 were not covered by tests
</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}
/>
</>
}

Check warning on line 271 in src/web/pages/alerts/emailmethodpart.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/alerts/emailmethodpart.jsx#L258-L271

Added lines #L258 - L271 were not covered by tests
</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,

Check warning on line 34 in src/web/pages/alerts/scpmethodpart.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/alerts/scpmethodpart.jsx#L34

Added line #L34 was not covered by tests
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}
/>
</>
}

Check warning on line 152 in src/web/pages/alerts/scpmethodpart.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/alerts/scpmethodpart.jsx#L140-L152

Added lines #L140 - L152 were not covered by tests
</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,

Check warning on line 24 in src/web/pages/alerts/sendmethodpart.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/alerts/sendmethodpart.jsx#L24

Added line #L24 was not covered by tests
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}
/>
</>
}

Check warning on line 95 in src/web/pages/alerts/sendmethodpart.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/alerts/sendmethodpart.jsx#L83-L95

Added lines #L83 - L95 were not covered by tests
</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,

Check warning on line 40 in src/web/pages/alerts/smbmethodpart.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/alerts/smbmethodpart.jsx#L40

Added line #L40 was not covered by tests
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}
/>
</>
}

Check warning on line 145 in src/web/pages/alerts/smbmethodpart.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/alerts/smbmethodpart.jsx#L133-L145

Added lines #L133 - L145 were not covered by tests
</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,

Check warning on line 30 in src/web/pages/alerts/verinicemethodpart.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/alerts/verinicemethodpart.jsx#L30

Added line #L30 was not covered by tests
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}
/>
</>
}

Check warning on line 118 in src/web/pages/alerts/verinicemethodpart.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/alerts/verinicemethodpart.jsx#L106-L118

Added lines #L106 - L118 were not covered by tests
</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 @@ -96,9 +96,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,
)
: [];

Check warning on line 103 in src/web/pages/reports/downloadreportdialog.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/reports/downloadreportdialog.jsx#L99-L103

Added lines #L99 - L103 were not covered by tests

return (
<Layout flex="column">
Expand All @@ -119,17 +121,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>
}

Check warning on line 137 in src/web/pages/reports/downloadreportdialog.jsx

View check run for this annotation

Codecov / codecov/patch

src/web/pages/reports/downloadreportdialog.jsx#L124-L137

Added lines #L124 - L137 were not covered by tests
<StyledDiv>
<CheckBox
name="storeAsDefault"
Expand Down

0 comments on commit b776c4b

Please sign in to comment.