-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: Add pages for new Report Config type
This adds list and details pages and a edit/create dialog for the new Report Config type. This will later allow users to configure predefined report formats when exporting reports or setting up alerts.
- Loading branch information
1 parent
98f6e32
commit fbbe5b9
Showing
51 changed files
with
13,450 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
/* Copyright (C) 2024 Greenbone AG | ||
* | ||
* 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 { | ||
createHttp, | ||
createEntityResponse, | ||
createActionResultResponse, | ||
} from '../testing'; | ||
import {ReportConfigCommand} from '../reportconfigs'; | ||
|
||
describe('ReportConfigCommand tests', () => { | ||
test('should return single report config', () => { | ||
const response = createEntityResponse('report_config', { | ||
_id: 'foo', | ||
}); | ||
|
||
const fakeHttp = createHttp(response); | ||
|
||
expect.hasAssertions(); | ||
|
||
const cmd = new ReportConfigCommand(fakeHttp); | ||
return cmd.get({id: 'foo'}).then(resp => { | ||
expect(fakeHttp.request).toHaveBeenCalledWith('get', { | ||
args: { | ||
cmd: 'get_report_config', | ||
report_config_id: 'foo', | ||
}, | ||
}); | ||
const {data} = resp; | ||
expect(data.id).toEqual('foo'); | ||
}); | ||
}); | ||
|
||
test('should create report config', () => { | ||
const response = createActionResultResponse(); | ||
|
||
const fakeHttp = createHttp(response); | ||
|
||
expect.hasAssertions(); | ||
|
||
const cmd = new ReportConfigCommand(fakeHttp); | ||
return cmd | ||
.create({ | ||
name: 'foo', | ||
comment: 'bar', | ||
report_format_id: 'baz', | ||
params: { | ||
'param 1': 'value 1', | ||
'param 2': 'value 2', | ||
'param 3': ['report-format-1', 'report-format-2'], | ||
}, | ||
params_using_default: { | ||
'param 1': false, | ||
'param 2': true, | ||
'param 3': false, | ||
}, | ||
}) | ||
.then(resp => { | ||
expect(fakeHttp.request).toHaveBeenCalledWith('post', { | ||
data: { | ||
cmd: 'create_report_config', | ||
name: 'foo', | ||
comment: 'bar', | ||
report_format_id: 'baz', | ||
'param:param 1': 'value 1', | ||
'param:param 2': 'value 2', | ||
'param:param 3': 'report-format-1,report-format-2', | ||
'param_using_default:param 2': 1, | ||
}, | ||
}); | ||
const {data} = resp; | ||
expect(data.id).toEqual('foo'); | ||
}); | ||
}); | ||
|
||
test('should save report config', () => { | ||
const response = createActionResultResponse(); | ||
|
||
const fakeHttp = createHttp(response); | ||
|
||
expect.hasAssertions(); | ||
|
||
const cmd = new ReportConfigCommand(fakeHttp); | ||
return cmd | ||
.save({ | ||
name: 'foo', | ||
comment: 'bar', | ||
report_format_id: 'should-be-ignored-in-save', | ||
params: { | ||
'param 1': 'value A', | ||
'param 2': 'value B', | ||
'param 3': ['report-format-A', 'report-format-B'], | ||
}, | ||
params_using_default: { | ||
'param 1': true, | ||
'param 2': false, | ||
'param 3': false, | ||
}, | ||
}) | ||
.then(resp => { | ||
expect(fakeHttp.request).toHaveBeenCalledWith('post', { | ||
data: { | ||
cmd: 'save_report_config', | ||
name: 'foo', | ||
comment: 'bar', | ||
'param:param 1': 'value A', | ||
'param:param 2': 'value B', | ||
'param:param 3': 'report-format-A,report-format-B', | ||
'param_using_default:param 1': 1, | ||
}, | ||
}); | ||
const {data} = resp; | ||
expect(data.id).toEqual('foo'); | ||
}); | ||
}); | ||
|
||
test('should delete report config', () => { | ||
const response = createActionResultResponse(); | ||
|
||
const fakeHttp = createHttp(response); | ||
|
||
expect.hasAssertions(); | ||
|
||
const cmd = new ReportConfigCommand(fakeHttp); | ||
return cmd | ||
.delete({ | ||
id: 'foo', | ||
}) | ||
.then(resp => { | ||
expect(fakeHttp.request).toHaveBeenCalledWith('post', { | ||
data: { | ||
cmd: 'delete_report_config', | ||
report_config_id: 'foo', | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* Copyright (C) 2024 Greenbone AG | ||
* | ||
* 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 {createHttp, createEntitiesResponse} from '../testing'; | ||
import {ReportConfigsCommand} from '../reportconfigs'; | ||
import {ALL_FILTER} from 'gmp/models/filter'; | ||
|
||
describe('ReportConfigsCommand tests', () => { | ||
test('should return all report configs', () => { | ||
const response = createEntitiesResponse('report_config', [ | ||
{ | ||
_id: '1', | ||
}, | ||
{ | ||
_id: '2', | ||
}, | ||
]); | ||
|
||
const fakeHttp = createHttp(response); | ||
|
||
expect.hasAssertions(); | ||
|
||
const cmd = new ReportConfigsCommand(fakeHttp); | ||
return cmd.getAll().then(resp => { | ||
expect(fakeHttp.request).toHaveBeenCalledWith('get', { | ||
args: { | ||
cmd: 'get_report_configs', | ||
filter: ALL_FILTER.toFilterString(), | ||
}, | ||
}); | ||
const {data} = resp; | ||
expect(data.length).toEqual(2); | ||
}); | ||
}); | ||
|
||
test('should return report configs', () => { | ||
const response = createEntitiesResponse('report_config', [ | ||
{ | ||
_id: '1', | ||
}, | ||
{ | ||
_id: '2', | ||
}, | ||
]); | ||
|
||
const fakeHttp = createHttp(response); | ||
|
||
expect.hasAssertions(); | ||
|
||
const cmd = new ReportConfigsCommand(fakeHttp); | ||
return cmd.get().then(resp => { | ||
expect(fakeHttp.request).toHaveBeenCalledWith('get', { | ||
args: { | ||
cmd: 'get_report_configs', | ||
}, | ||
}); | ||
const {data} = resp; | ||
expect(data.length).toEqual(2); | ||
}); | ||
}); | ||
|
||
test('should return filtered report configs', () => { | ||
const response = createEntitiesResponse('report_config', [ | ||
{ | ||
_id: '1', | ||
}, | ||
{ | ||
_id: '2', | ||
}, | ||
]); | ||
|
||
const fakeHttp = createHttp(response); | ||
|
||
expect.hasAssertions(); | ||
|
||
const cmd = new ReportConfigsCommand(fakeHttp); | ||
return cmd.get({filter: 'test filter'}).then(resp => { | ||
expect(fakeHttp.request).toHaveBeenCalledWith('get', { | ||
args: { | ||
cmd: 'get_report_configs', | ||
filter: 'test filter', | ||
}, | ||
}); | ||
const {data} = resp; | ||
expect(data.length).toEqual(2); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* Copyright (C) 2024 Greenbone AG | ||
* | ||
* 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 logger from 'gmp/log'; | ||
|
||
import registerCommand from 'gmp/command'; | ||
|
||
import ReportConfig from 'gmp/models/reportconfig'; | ||
|
||
import {isArray} from 'gmp/utils/identity'; | ||
|
||
import EntitiesCommand from './entities'; | ||
import EntityCommand from './entity'; | ||
import {convertBoolean} from 'gmp/commands/convert'; | ||
|
||
const log = logger.getLogger('gmp.commands.reportconfigs'); | ||
|
||
export class ReportConfigCommand extends EntityCommand { | ||
constructor(http) { | ||
super(http, 'report_config', ReportConfig); | ||
} | ||
|
||
create(args) { | ||
const { | ||
comment, | ||
name, | ||
report_format_id, | ||
params = {}, | ||
params_using_default = {}, | ||
} = args; | ||
|
||
const data = { | ||
cmd: 'create_report_config', | ||
name, | ||
comment, | ||
report_format_id, | ||
}; | ||
|
||
for (const prefname in params) { | ||
let value = params[prefname]; | ||
if (isArray(params[prefname])) { | ||
value = params[prefname].join(','); | ||
} | ||
data['param:' + prefname] = value; | ||
} | ||
|
||
for (const param_name in params_using_default) { | ||
if (params_using_default[param_name]) { | ||
data['param_using_default:' + param_name] = convertBoolean( | ||
params_using_default[param_name], | ||
); | ||
} | ||
} | ||
|
||
log.debug('Creating new report config', args); | ||
return this.action(data); | ||
} | ||
|
||
save(args) { | ||
const {id, comment, name, params = {}, params_using_default = {}} = args; | ||
|
||
const data = { | ||
cmd: 'save_report_config', | ||
id, | ||
name, | ||
comment, | ||
}; | ||
|
||
for (const param_name in params_using_default) { | ||
if (params_using_default[param_name]) { | ||
data['param_using_default:' + param_name] = convertBoolean( | ||
params_using_default[param_name], | ||
); | ||
} | ||
} | ||
|
||
for (const prefname in params) { | ||
let value = params[prefname]; | ||
if (isArray(params[prefname])) { | ||
value = params[prefname].join(','); | ||
} | ||
data['param:' + prefname] = value; | ||
} | ||
|
||
log.debug('Saving report config', args, data); | ||
return this.action(data); | ||
} | ||
|
||
getElementFromRoot(root) { | ||
return root.get_report_config.get_report_configs_response.report_config; | ||
} | ||
} | ||
|
||
export class ReportConfigsCommand extends EntitiesCommand { | ||
constructor(http) { | ||
super(http, 'report_config', ReportConfig); | ||
} | ||
|
||
getEntitiesResponse(root) { | ||
return root.get_report_configs.get_report_configs_response; | ||
} | ||
} | ||
|
||
registerCommand('reportconfig', ReportConfigCommand); | ||
registerCommand('reportconfigs', ReportConfigsCommand); | ||
|
||
// vim: set ts=2 sw=2 tw=80: |
Oops, something went wrong.