Skip to content

Commit

Permalink
Merge pull request #1512 from swaterkamp/FilenameTemplates
Browse files Browse the repository at this point in the history
Fix using filename templates
  • Loading branch information
bjoernricks authored Jul 24, 2019
2 parents a2bd887 + ff348a9 commit 44c0452
Show file tree
Hide file tree
Showing 11 changed files with 528 additions and 38 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
logged in [#1508](https://github.com/greenbone/gsa/pull/1508)

### Fixed
- Fix using filename templates from usersettings [#1512](https://github.com/greenbone/gsa/pull/1512)
- Allow to use additional options for starting gsad via systemd
[#1514](https://github.com/greenbone/gsa/pull/1514)

Expand Down
2 changes: 1 addition & 1 deletion gsa/src/gmp/locale/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const ensureDate = date => {
return date;
};

const dateFormat = (date, format, tz) => {
export const dateFormat = (date, format, tz) => {
date = ensureDate(date);
if (!isDefined(date)) {
return undefined;
Expand Down
50 changes: 46 additions & 4 deletions gsa/src/web/entities/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import 'core-js/fn/set';

import React from 'react';

import {connect} from 'react-redux';

import _ from 'gmp/locale';

import logger from 'gmp/log';
Expand All @@ -39,8 +41,16 @@ import Filter, {RESET_FILTER} from 'gmp/models/filter';

import {YES_VALUE} from 'gmp/parser';

import {renewSessionTimeout} from 'web/store/usersettings/actions';
import {loadUserSettingDefaults} from 'web/store/usersettings/defaults/actions';
import {getUserSettingsDefaults} from 'web/store/usersettings/defaults/selectors';
import {getUsername} from 'web/store/usersettings/selectors';

import compose from 'web/utils/compose';

import {LOAD_TIME_FACTOR} from 'web/utils/constants';
import PropTypes from 'web/utils/proptypes';
import {generateFilename} from 'web/utils/render';
import SelectionType from 'web/utils/selectiontype';

import SortBy from 'web/components/sortby/sortby';
Expand Down Expand Up @@ -132,6 +142,8 @@ class EntitiesContainer extends React.Component {
this.isRunning = true;
const {filter} = this.props.location.query;

this.props.loadSettings();

if (isDefined(filter)) {
// use filter from url
this.load(Filter.fromString(filter));
Expand Down Expand Up @@ -283,10 +295,10 @@ class EntitiesContainer extends React.Component {
this.handleInteraction();
}

handleDownloadBulk(filename = 'export.xml') {
handleDownloadBulk() {
const {entitiesCommand} = this;
const {loadedFilter, selected, selectionType} = this.state;
const {onDownload} = this.props;
const {entities = [], loadedFilter, selected, selectionType} = this.state;
const {listExportFileName, username, onDownload} = this.props;

let promise;

Expand All @@ -301,6 +313,11 @@ class EntitiesContainer extends React.Component {
this.handleInteraction();

promise.then(response => {
const filename = generateFilename({
fileNameFormat: listExportFileName,
resourceType: pluralizeType(getEntityType(entities[0])),
username,
});
const {data} = response;
onDownload({filename, data});
}, this.handleError);
Expand Down Expand Up @@ -679,18 +696,43 @@ EntitiesContainer.propTypes = {
gmpname: PropTypes.string.isRequired,
history: PropTypes.object.isRequired,
isLoading: PropTypes.bool.isRequired,
listExportFileName: PropTypes.object,
loadEntities: PropTypes.func.isRequired,
loadSettings: PropTypes.func.isRequired,
loadedFilter: PropTypes.filter,
notify: PropTypes.func.isRequired,
reloadInterval: PropTypes.func,
showError: PropTypes.func.isRequired,
showErrorMessage: PropTypes.func.isRequired,
showSuccessMessage: PropTypes.func.isRequired,
updateFilter: PropTypes.func.isRequired,
username: PropTypes.string,
onDownload: PropTypes.func.isRequired,
onInteraction: PropTypes.func.isRequired,
};

export default EntitiesContainer;
const mapStateToProps = rootState => {
const userDefaultsSelector = getUserSettingsDefaults(rootState);
const username = getUsername(rootState);
const listExportFileName = userDefaultsSelector.getValueByName(
'listexportfilename',
);
return {
listExportFileName,
username,
};
};

const mapDispatchToProps = (dispatch, {gmp}) => ({
loadSettings: () => dispatch(loadUserSettingDefaults(gmp)()),
onInteraction: () => dispatch(renewSessionTimeout(gmp)()),
});

export default compose(
connect(
mapStateToProps,
mapDispatchToProps,
),
)(EntitiesContainer);

// vim: set ts=2 sw=2 tw=80:
67 changes: 62 additions & 5 deletions gsa/src/web/entity/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@
*/
import React from 'react';

import {connect} from 'react-redux';

import {isDefined} from 'gmp/utils/identity';

import PropTypes from '../utils/proptypes.js';
import {renewSessionTimeout} from 'web/store/usersettings/actions';
import {loadUserSettingDefaults} from 'web/store/usersettings/defaults/actions';
import {getUserSettingsDefaults} from 'web/store/usersettings/defaults/selectors';
import {getUsername} from 'web/store/usersettings/selectors';

import compose from 'web/utils/compose';

import PropTypes from 'web/utils/proptypes';

import withGmp from '../utils/withGmp.js';
import {generateFilename} from 'web/utils/render';

import withGmp from 'web/utils/withGmp';

export const goto_details = (type, props) => ({data}) => {
const {history} = props;
Expand All @@ -44,6 +55,10 @@ class EntityComponent extends React.Component {
this.handleEntitySave = this.handleEntitySave.bind(this);
}

componentDidMount() {
this.props.loadSettings();
}

handleEntityDelete(entity) {
const {onDeleted, onDeleteError, gmp, name} = this.props;
const cmd = gmp[name];
Expand Down Expand Up @@ -78,13 +93,29 @@ class EntityComponent extends React.Component {
}

handleEntityDownload(entity) {
const {onDownloaded, onDownloadError, gmp, name} = this.props;
const {
detailsExportFileName,
username,
gmp,
name,
onDownloaded,
onDownloadError,
} = this.props;
const cmd = gmp[name];

this.handleInteraction();

const promise = cmd.export(entity).then(response => {
const filename = name + '-' + entity.id + '.xml';
const filename = generateFilename({
creationTime: entity.creationTime,
fileNameFormat: detailsExportFileName,
id: entity.id,
modificationTime: entity.modificationTime,
resourceName: entity.name,
resourceType: name,
username,
});

return {filename, data: response.data};
});

Expand Down Expand Up @@ -113,8 +144,11 @@ class EntityComponent extends React.Component {

EntityComponent.propTypes = {
children: PropTypes.func.isRequired,
detailsExportFileName: PropTypes.object,
gmp: PropTypes.gmp.isRequired,
loadSettings: PropTypes.func.isRequired,
name: PropTypes.string.isRequired,
username: PropTypes.string,
onCloneError: PropTypes.func,
onCloned: PropTypes.func,
onCreateError: PropTypes.func,
Expand All @@ -128,6 +162,29 @@ EntityComponent.propTypes = {
onSaved: PropTypes.func,
};

export default withGmp(EntityComponent);
const mapStateToProps = rootState => {
const userDefaultsSelector = getUserSettingsDefaults(rootState);
const username = getUsername(rootState);
const detailsExportFileName = userDefaultsSelector.getValueByName(
'detailsexportfilename',
);
return {
detailsExportFileName,
username,
};
};

const mapDispatchToProps = (dispatch, {gmp}) => ({
loadSettings: () => dispatch(loadUserSettingDefaults(gmp)()),
onInteraction: () => dispatch(renewSessionTimeout(gmp)()),
});

export default compose(
withGmp,
connect(
mapStateToProps,
mapDispatchToProps,
),
)(EntityComponent);

// vim: set ts=2 sw=2 tw=80:
56 changes: 52 additions & 4 deletions gsa/src/web/pages/agents/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,21 @@

import React from 'react';

import {connect} from 'react-redux';

import _ from 'gmp/locale';

import {renewSessionTimeout} from 'web/store/usersettings/actions';
import {loadUserSettingDefaults} from 'web/store/usersettings/defaults/actions';
import {getUserSettingsDefaults} from 'web/store/usersettings/defaults/selectors';
import {getUsername} from 'web/store/usersettings/selectors';

import {isDefined} from 'gmp/utils/identity';
import {shorten} from 'gmp/utils/string';

import compose from 'web/utils/compose';
import PropTypes from 'web/utils/proptypes';
import {generateFilename} from 'web/utils/render';
import withGmp from 'web/utils/withGmp';

import EntityComponent from 'web/entity/component';
Expand Down Expand Up @@ -52,15 +61,29 @@ class AgentComponent extends React.Component {
}

handleDownloadInstaller(agent) {
const {gmp, onInstallerDownloadError, onInstallerDownloaded} = this.props;
const {id, name} = agent;
const {
detailsExportFileName,
gmp,
username,
onInstallerDownloadError,
onInstallerDownloaded,
} = this.props;
const {creationTime, entityType, id, modificationTime, name} = agent;

this.handleInteraction();

return gmp.agent
.downloadInstaller(agent)
.then(response => {
const filename = 'agent-' + name + '-' + id + '-installer';
const filename = generateFilename({
creationTime: creationTime,
fileNameFormat: detailsExportFileName,
id: id,
modificationTime,
resourceName: name,
resourceType: entityType,
username,
});
return {filename, data: response.data};
})
.then(onInstallerDownloaded, onInstallerDownloadError);
Expand Down Expand Up @@ -162,7 +185,9 @@ class AgentComponent extends React.Component {

AgentComponent.propTypes = {
children: PropTypes.func.isRequired,
detailsExportFileName: PropTypes.object,
gmp: PropTypes.gmp.isRequired,
username: PropTypes.string,
onCloneError: PropTypes.func,
onCloned: PropTypes.func,
onCreateError: PropTypes.func,
Expand All @@ -180,6 +205,29 @@ AgentComponent.propTypes = {
onVerifyError: PropTypes.func,
};

export default withGmp(AgentComponent);
const mapStateToProps = rootState => {
const userDefaultsSelector = getUserSettingsDefaults(rootState);
const username = getUsername(rootState);
const detailsExportFileName = userDefaultsSelector.getValueByName(
'detailsexportfilename',
);
return {
detailsExportFileName,
username,
};
};

const mapDispatchToProps = (dispatch, {gmp}) => ({
loadSettings: () => dispatch(loadUserSettingDefaults(gmp)()),
onInteraction: () => dispatch(renewSessionTimeout(gmp)()),
});

export default compose(
withGmp,
connect(
mapStateToProps,
mapDispatchToProps,
),
)(AgentComponent);

// vim: set ts=2 sw=2 tw=80:
Loading

0 comments on commit 44c0452

Please sign in to comment.