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

Edit dialog: only send name and comment if config or policy is in use, and add in use notification #2463

Merged
merged 23 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5576521
Remove error message for config in use
saberlynx Sep 22, 2020
e7c4430
If input objects are undefined, append empty object to data
saberlynx Sep 22, 2020
38a5ba6
Send only name, comment and id if config is in use, removeconsole logs
saberlynx Sep 22, 2020
ecd6556
Policy input objects can be undefined
saberlynx Sep 22, 2020
6dca5ff
Send only name and comment if policy is in use
saberlynx Sep 22, 2020
f273d9a
Get rid of no shadow warning
saberlynx Sep 22, 2020
d8f3ff0
Add notification to edit dialog if in use
saberlynx Sep 22, 2020
2de7e7a
Add notification on the bottom of dialog if configIsInUse
saberlynx Sep 22, 2020
91db014
Update snapshot
saberlynx Sep 22, 2020
a742d21
Edit test for edit scan config dialog
saberlynx Sep 22, 2020
8f19d9e
Add test to commands to make sure undefined input objects are not sent
saberlynx Sep 22, 2020
6561e2f
Update CHANGELOG.md
saberlynx Sep 22, 2020
8a2ea4e
Adjust notification text and test
saberlynx Sep 22, 2020
44f874f
Remove snapshot test
saberlynx Sep 22, 2020
9e33443
Extract onSave into own function
saberlynx Sep 23, 2020
c54d049
Add dialoginlinenotification component
saberlynx Sep 23, 2020
d0fa6c3
Use new component in edit dialog
saberlynx Sep 23, 2020
526143b
Give DialogInLineNotification a data-testid and adjust tests
saberlynx Sep 23, 2020
46ef499
Add usageType prop for edit dialog and adjust notification
saberlynx Sep 23, 2020
f6fdcd0
Add usageType to props validation
saberlynx Sep 23, 2020
c819685
Substitute entire sentence instead of entity names
saberlynx Sep 23, 2020
5a06079
Translate notification into German again
saberlynx Sep 23, 2020
290df53
Merge branch 'gsa-20.08' into edit-inuse-config
swaterkamp Sep 25, 2020
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Changed
- Change tooltip of override icon in result details [#2467](https://github.com/greenbone/gsa/pull/2467)
- For edit config/policy dialog, only send name and comment if config or policy is in use, and add in use notification [#2463](https://github.com/greenbone/gsa/pull/2463)
- Changed visual appearance of compliance status bar [#2457](https://github.com/greenbone/gsa/pull/2457)
- Changed delete icons on report format detailspage and schedule detailspage to trashcan icons [#2459](https://github.com/greenbone/gsa/pull/2459)
- Use <predefined> to disable feed object editing and filter creation on feed status page [#2398](https://github.com/greenbone/gsa/pull/2398)
Expand Down
4 changes: 2 additions & 2 deletions gsa/public/locales/gsa-de.json
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,6 @@
"Export Policy as XML": "Richtlinie als XML exportieren",
"Export Port List": "Portliste exportieren",
"Export PortList as XML": "Portliste als XML exportieren",
"Export Report Format": "Berichtformat exportieren",
"Export Report Format as XML": "Berichtformat als XML exportieren",
"Export Result as XML": "Ergebnis als XML exportieren",
"Export Role": "Rolle exportieren",
"Export Role as XML": "Rolle als XML exportieren",
Expand Down Expand Up @@ -1658,9 +1656,11 @@
"The last {{weekday}} every {{interval}} months": "Jeden letzten {{weekday}} jeden {{interval}}. Monat",
"The maximum of {{num}} hosts was exceeded. If there are more hosts associated with this process, they will not be taken into account.": "Das Maximum von {{num}} Hosts wurde überschritten. Sollten weitere Hosts mit diesem Prozess verknüpft sein, werden sie nicht mitberücksichtigt.",
"The name must include at least one alphanumeric character or one of .,-/_# and space.": "Der Name muss mindestens ein alphanumerisches Zeichen oder eines von .,-/_# und Leerzeichen enthalten.",
"The policy is currently in use by one or more audits, therefore only name and comment can be modified.": "Die Richtlinie wird im Moment von Audits verwendet, daher können nur Name und Kommentar bearbeitet werden.",
"The port range needs numerical values for start and end!": "Der Portbereich benötigt numerische Werte für Start und Ende!",
"The report cannot be displayed because no Greenbone Vulnerability Manager report format is available. This could be due to a missing gvmd data feed. Please update the gvmd data feed, check the \"feed import owner\" setting, or contact your system administrator.": "Der Bericht kann nicht angezeigt werden, weil dem Greenbone Vulnerability Manager kein Berichtformat zur Verfügung steht. Dies könnte an einem fehlenden gvmd Data Feed liegen. Bitte aktualisieren Sie den gvmd Data Feed, überprüfen die \"Feed Import Besitzer\"-Einstellungen, oder kontaktieren Ihren Systemadministrator.",
"The report is empty. The filter does not match any of the {{all}} results.": "Der Bericht ist leer. Der Filter passt zu keinem der {{all}} Ergebnisse.",
"The scan config is currently in use by one or more tasks, therefore only name and comment can be modified.": "Die Scan-Konfiguration wird im Moment von Aufgaben verwendet, daher können nur Name und Kommentar bearbeitet werden.",
"The scan did not collect any results": "Der Scan hat keine Ergebnisse gesammelt",
"The scan is still running and no results have arrived yet": "Der Scan läuft noch und es sind noch keine Ergebnisse eingetroffen",
"The scan just started and no results have arrived yet": "Der Scan hat gerade begonnen und es sind noch keine Ergebnisse eingetroffen",
Expand Down
29 changes: 29 additions & 0 deletions gsa/src/gmp/commands/__tests__/policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,35 @@ describe('PolicyCommand tests', () => {
});
});

test('should save an in use policy with undefined input objects', () => {
const response = createActionResultResponse();
const fakeHttp = createHttp(response);

expect.hasAssertions();

const cmd = new PolicyCommand(fakeHttp);
return cmd
.save({
id: 'c1',
name: 'foo',
comment: 'somecomment',
trend: undefined,
select: undefined,
scannerPreferenceValues: undefined,
scannerId: undefined,
})
.then(() => {
expect(fakeHttp.request).toHaveBeenCalledWith('post', {
data: {
cmd: 'save_config',
comment: 'somecomment',
config_id: 'c1',
name: 'foo',
},
});
});
});

test('should return single policy', () => {
const response = createEntityResponse('config', {_id: 'foo'});
const fakeHttp = createHttp(response);
Expand Down
29 changes: 29 additions & 0 deletions gsa/src/gmp/commands/__tests__/scanconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,35 @@ describe('ScanConfigCommand tests', () => {
});
});

test('should save an in use config with undefined input objects', () => {
const response = createActionResultResponse();
const fakeHttp = createHttp(response);

expect.hasAssertions();

const cmd = new ScanConfigCommand(fakeHttp);
return cmd
.save({
id: 'c1',
name: 'foo',
comment: 'somecomment',
trend: undefined,
select: undefined,
scannerPreferenceValues: undefined,
scannerId: undefined,
})
.then(() => {
expect(fakeHttp.request).toHaveBeenCalledWith('post', {
data: {
cmd: 'save_config',
comment: 'somecomment',
config_id: 'c1',
name: 'foo',
},
});
});
});

test('should save a config family', () => {
const response = createActionResultResponse();
const fakeHttp = createHttp(response);
Expand Down
18 changes: 11 additions & 7 deletions gsa/src/gmp/commands/policies.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,18 @@ export class PolicyCommand extends EntityCommand {
}

save({id, name, comment = '', trend, select, scannerPreferenceValues}) {
const trendData = isDefined(trend) ? convert(trend, 'trend:') : {};
const scannerPreferenceData = isDefined(scannerPreferenceValues)
? convert(scannerPreferenceValues, 'preference:scanner:scanner:scanner:')
: {};

const selectData = isDefined(select)
? convertSelect(select, 'select:')
: {};
const data = {
...convert(trend, 'trend:'),
...convert(
scannerPreferenceValues,
'preference:scanner:scanner:scanner:',
),
...convertSelect(select, 'select:'),

...trendData,
...scannerPreferenceData,
...selectData,
cmd: 'save_config',
id,
comment,
Expand Down
18 changes: 11 additions & 7 deletions gsa/src/gmp/commands/scanconfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,18 @@ export class ScanConfigCommand extends EntityCommand {
scannerId,
scannerPreferenceValues,
}) {
const trendData = isDefined(trend) ? convert(trend, 'trend:') : {};
const scannerPreferenceData = isDefined(scannerPreferenceValues)
? convert(scannerPreferenceValues, 'preference:scanner:scanner:scanner:')
: {};

const selectData = isDefined(select)
? convertSelect(select, 'select:')
: {};
const data = {
...convert(trend, 'trend:'),
...convert(
scannerPreferenceValues,
'preference:scanner:scanner:scanner:',
),
...convertSelect(select, 'select:'),

...trendData,
...scannerPreferenceData,
...selectData,
cmd: 'save_config',
id,
comment,
Expand Down
28 changes: 28 additions & 0 deletions gsa/src/web/components/dialog/dialoginlinenotification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Copyright (C) 2020 Greenbone Networks GmbH
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import styled from 'styled-components';

const DialogInlineNotification = styled.div`
font-size: 14px;
margin-bottom: 0px;
display: flex;
justify-content: center;
`;

export default DialogInlineNotification;
21 changes: 17 additions & 4 deletions gsa/src/web/pages/policies/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class PolicyComponent extends React.Component {

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

handleChange(value, name) {
Expand Down Expand Up @@ -192,6 +193,20 @@ class PolicyComponent extends React.Component {
this.handleInteraction();
}

handleSavePolicy(d) {
const {gmp} = this.props;
const {policy} = this.state;

this.handleInteraction();
const {name, comment, id} = d;
let saveData = d;
if (policy.isInUse()) {
saveData = {name, comment, id};
}

return gmp.policy.save(saveData).then(() => this.closeEditPolicyDialog());
}

openCreatePolicyDialog() {
this.loadScanners();

Expand Down Expand Up @@ -761,13 +776,11 @@ class PolicyComponent extends React.Component {
scannerPreferences={policy.preferences.scanner}
scanners={scanners}
title={title}
usageType={'policy'}
onClose={this.handleCloseEditPolicyDialog}
onEditConfigFamilyClick={this.openEditPolicyFamilyDialog}
onEditNvtDetailsClick={this.openEditNvtDetailsDialog}
onSave={d => {
this.handleInteraction();
return save(d).then(() => this.closeEditPolicyDialog());
}}
onSave={this.handleSavePolicy}
/>
)}
</React.Fragment>
Expand Down
Loading