Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alert content composer #1280

Merged
merged 6 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ $ cd gsa && git checkout gsa-8.0 && git log

## gsa 8.0.1 (unreleased)

* Fix opening alert report composer #1280 #1276
* Remove fifth from schedule #1279
* Fix showing authentication methods in user dialog #1278
* Fix Result details page #1275
Expand Down
41 changes: 10 additions & 31 deletions gsa/src/web/pages/alerts/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ class AlertComponent extends React.Component {
this.handleOpenContentComposerDialog = this.handleOpenContentComposerDialog.bind(
this,
);
this.openContentComposerDialog = this.openContentComposerDialog.bind(this);
this.closeContentComposerDialog = this.closeContentComposerDialog.bind(
this,
);
Expand Down Expand Up @@ -242,31 +241,21 @@ class AlertComponent extends React.Component {
}

handleOpenContentComposerDialog() {
const {gmp} = this.props;
const {composerFilterId = NO_VALUE} = this.state;
gmp.filter.get({id: composerFilterId}).then(response => {
this.setState({
composerFilterString: isDefined(response.data)
? response.data.toFilterCriteriaString()
: undefined,
});
this.openContentComposerDialog();
this.handleInteraction();
});
this.openContentComposerDialog();

this.handleInteraction();
}

closeContentComposerDialog() {
const {
method_data_composer_include_notes,
method_data_composer_include_overrides,
filter_id,
filter_string,
} = this.state;
this.setState({
composerIncludeNotes: method_data_composer_include_notes,
composerIncludeOverrides: method_data_composer_include_overrides,
composerFilterId: filter_id,
composerFilterString: filter_string,
composerStoreAsDefault: NO_VALUE,
contentComposerDialogVisible: false,
});
Expand All @@ -276,22 +265,20 @@ class AlertComponent extends React.Component {
includeNotes,
includeOverrides,
filterId,
filterString,
storeAsDefault,
}) {
if (storeAsDefault) {
const {reportComposerDefaults} = this.props;
const defaults = {
...reportComposerDefaults,
reportResultFilterId: filterId,
reportResultFilterId: filterId === UNSET_VALUE ? undefined : filterId,
includeNotes,
includeOverrides,
};
this.props.saveReportComposerDefaults(defaults);
}
this.setState({
filter_id: filterId,
filter_string: filterString,
method_data_composer_include_notes: includeNotes,
method_data_composer_include_overrides: includeOverrides,
composerStoreAsDefault: NO_VALUE,
Expand Down Expand Up @@ -455,10 +442,10 @@ class AlertComponent extends React.Component {
name: alert.name,
comment: alert.comment,
filters,
filter_id: isDefined(alert.filter) ? alert.filter.id : NO_VALUE,
filter_id: isDefined(alert.filter) ? alert.filter.id : undefined,
composerFilterId: isDefined(alert.filter)
? alert.filter.id
: NO_VALUE,
: undefined,
composerIncludeNotes: getValue(method.data.composer_include_notes),
composerIncludeOverrides: getValue(
method.data.composer_include_overrides,
Expand Down Expand Up @@ -691,7 +678,7 @@ class AlertComponent extends React.Component {
reportComposerDefaults.reportResultFilterId,
)
? reportComposerDefaults.reportResultFilterId
: UNSET_VALUE;
: undefined;

this.setState({
active: undefined,
Expand Down Expand Up @@ -901,16 +888,10 @@ class AlertComponent extends React.Component {
}

handleFilterIdChange(value) {
const {gmp} = this.props;
gmp.filter.get({id: value}).then(response => {
const composerFilterString = isDefined(response.data)
? response.data.toFilterCriteriaString()
: undefined;
this.setState({
composerFilterId: value,
composerFilterString,
});
this.setState({
composerFilterId: value === UNSET_VALUE ? undefined : value,
});

this.handleInteraction();
}

Expand Down Expand Up @@ -946,7 +927,6 @@ class AlertComponent extends React.Component {
filters,
filter_id,
composerFilterId,
composerFilterString,
composerIncludeNotes,
composerIncludeOverrides,
credentials,
Expand Down Expand Up @@ -1205,7 +1185,6 @@ class AlertComponent extends React.Component {
includeOverrides={parseYesNo(composerIncludeOverrides)}
filterId={composerFilterId}
filters={result_filters}
filterString={composerFilterString}
storeAsDefault={parseYesNo(composerStoreAsDefault)}
title={_('Compose Content for Scan Report')}
onChange={this.handleValueChange}
Expand Down
14 changes: 6 additions & 8 deletions gsa/src/web/pages/alerts/contentcomposerdialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ const StyledDiv = styled.div`
`;

const ContentComposerDialog = ({
filterId,
filters,
filterString = '',
filterId = UNSET_VALUE,
filters = [],
includeNotes = COMPOSER_CONTENT_DEFAULTS.includeNotes,
includeOverrides = COMPOSER_CONTENT_DEFAULTS.includeOverrides,
storeAsDefault,
Expand All @@ -57,12 +56,11 @@ const ContentComposerDialog = ({
onSave,
onChange,
}) => {
filterId =
filterId === NO_VALUE || !isDefined(filterId) ? UNSET_VALUE : filterId;
const filter =
filterId === UNSET_VALUE ? undefined : filters.find(f => f.id === filterId);

const controlledValues = {
filterId,
filterString,
includeNotes,
includeOverrides,
storeAsDefault,
Expand All @@ -81,7 +79,7 @@ const ContentComposerDialog = ({
<FormGroup title={_('Report Result Filter')} titleSize="3">
<Select
name="filterId"
value={values.filterId}
value={filterId}
items={renderSelectItems(filters, UNSET_VALUE)}
onChange={onFilterIdChange}
/>
Expand All @@ -91,7 +89,7 @@ const ContentComposerDialog = ({
'To change the filter, please select a filter' +
' from the dropdown menu.',
)}
filterString={values.filterString}
filterString={isDefined(filter) ? filter.toFilterString() : ''}
includeNotes={values.includeNotes}
includeOverrides={values.includeOverrides}
onValueChange={onChange}
Expand Down
4 changes: 2 additions & 2 deletions gsad/src/gsad_gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -5718,7 +5718,6 @@ create_alert_gmp (gvm_connection_t *connection, credentials_t *credentials,
CHECK_VARIABLE_INVALID (condition, "Create Alert");
CHECK_VARIABLE_INVALID (event, "Create Alert");
CHECK_VARIABLE_INVALID (method, "Create Alert");
CHECK_VARIABLE_INVALID (filter_id, "Create Alert");

/* Create the alert. */

Expand Down Expand Up @@ -5752,7 +5751,8 @@ create_alert_gmp (gvm_connection_t *connection, credentials_t *credentials,
"<active>%s</active>"
"<comment>%s</comment>"
"<event>%s",
name, filter_id, active, comment ? comment : "", event);
name, filter_id ? filter_id : "", active,
comment ? comment : "", event);

append_alert_event_data (xml, event_data, event);

Expand Down