UI: Submit config before exporting

Previously config was not getting submitted before exporting. This could cause a misunderstanding where user exports a different configuration to the one he sees on the screen
This commit is contained in:
vakarisz 2022-06-28 16:14:40 +03:00
parent 69ca2d541d
commit 20c68ff25c
1 changed files with 27 additions and 26 deletions

View File

@ -23,6 +23,10 @@ const CONFIG_URL = '/api/configuration/island';
export const API_PBA_LINUX = '/api/file-upload/PBAlinux'; export const API_PBA_LINUX = '/api/file-upload/PBAlinux';
export const API_PBA_WINDOWS = '/api/file-upload/PBAwindows'; export const API_PBA_WINDOWS = '/api/file-upload/PBAwindows';
const configSubmitAction = 'config-submit';
const configExportAction = 'config-export';
const configSaveAction = 'config-saved';
class ConfigurePageComponent extends AuthComponent { class ConfigurePageComponent extends AuthComponent {
constructor(props) { constructor(props) {
@ -87,14 +91,16 @@ class ConfigurePageComponent extends AuthComponent {
}; };
onUnsafeConfirmationCancelClick = () => { onUnsafeConfirmationCancelClick = () => {
this.setState({showUnsafeOptionsConfirmation: false}); this.setState({showUnsafeOptionsConfirmation: false, lastAction: 'none'});
} }
onUnsafeConfirmationContinueClick = () => { onUnsafeConfirmationContinueClick = () => {
this.setState({showUnsafeOptionsConfirmation: false}); this.setState({showUnsafeOptionsConfirmation: false});
if (this.state.lastAction === configSubmitAction) {
if (this.state.lastAction === 'submit_attempt') {
this.configSubmit(); this.configSubmit();
} else if (this.state.lastAction === configExportAction) {
this.configSubmit();
this.setState({showConfigExportModal: true});
} }
} }
@ -113,37 +119,31 @@ class ConfigurePageComponent extends AuthComponent {
}; };
onSubmit = () => { onSubmit = () => {
this.attemptConfigSubmit(); this.setState({lastAction: configSubmitAction}, this.attemptConfigSubmit)
}; };
canSafelySubmitConfig(config) { canSafelySubmitConfig(config) {
return !isUnsafeOptionSelected(this.state.schema, config); return !isUnsafeOptionSelected(this.state.schema, config);
} }
checkAndShowUnsafeAttackWarning = () => { async attemptConfigSubmit() {
if (isUnsafeOptionSelected(this.state.schema, this.state.configuration)) { await this.updateConfigSection();
this.setState({showUnsafeAttackOptionsWarning: true}); if (this.canSafelySubmitConfig(this.state.configuration)) {
this.configSubmit();
if(this.state.lastAction === configExportAction){
this.setState({showConfigExportModal: true})
}
} else {
this.setState({showUnsafeOptionsConfirmation: true});
} }
} }
attemptConfigSubmit() {
this.updateConfigSection();
this.setState({lastAction: 'submit_attempt'}, () => {
if (this.canSafelySubmitConfig(this.state.configuration)) {
this.configSubmit();
} else {
this.setState({showUnsafeOptionsConfirmation: true});
}
}
);
}
configSubmit() { configSubmit() {
this.sendConfig() return this.sendConfig()
.then(res => res.json()) .then(res => res.json())
.then(res => { .then(res => {
this.setState({ this.setState({
lastAction: 'saved', lastAction: configSaveAction,
schema: res.schema, schema: res.schema,
configuration: res.configuration configuration: res.configuration
}); });
@ -167,11 +167,12 @@ class ConfigurePageComponent extends AuthComponent {
if (Object.keys(this.state.currentFormData).length > 0) { if (Object.keys(this.state.currentFormData).length > 0) {
newConfig[this.currentSection] = this.state.currentFormData; newConfig[this.currentSection] = this.state.currentFormData;
} }
this.setState({configuration: newConfig, lastAction: 'none'}); this.setState({configuration: newConfig});
}; };
renderConfigExportModal = () => { renderConfigExportModal = () => {
return (<ConfigExportModal show={this.state.showConfigExportModal} return (<ConfigExportModal show={this.state.showConfigExportModal}
configuration={this.state.configuration}
onHide={() => { onHide={() => {
this.setState({showConfigExportModal: false}); this.setState({showConfigExportModal: false});
}}/>); }}/>);
@ -307,9 +308,9 @@ class ConfigurePageComponent extends AuthComponent {
this.authFetch(apiEndpoint, request_options); this.authFetch(apiEndpoint, request_options);
} }
exportConfig = () => { exportConfig = async () => {
this.updateConfigSection(); await this.setState({lastAction: configExportAction});
this.setState({showConfigExportModal: true}); await this.attemptConfigSubmit();
}; };
sendConfig() { sendConfig() {
@ -451,7 +452,7 @@ class ConfigurePageComponent extends AuthComponent {
Configuration reset successfully. Configuration reset successfully.
</div> </div>
: ''} : ''}
{this.state.lastAction === 'saved' ? {this.state.lastAction === configSaveAction ?
<div className='alert alert-success'> <div className='alert alert-success'>
<FontAwesomeIcon icon={faCheck} style={{'marginRight': '5px'}}/> <FontAwesomeIcon icon={faCheck} style={{'marginRight': '5px'}}/>
Configuration saved successfully. Configuration saved successfully.