Ivan - Fix csv import, remove sql import, add i18h keys for advanced settings [skip ci]

This commit is contained in:
ivan 2017-03-04 18:38:49 -03:00
parent 484bfd4e99
commit 8c138b481c
6 changed files with 61 additions and 44 deletions

View File

@ -9,6 +9,7 @@ import AreYouSure from 'app-components/are-you-sure';
import ModalContainer from 'app-components/modal-container';
import Message from 'core-components/message';
import InfoTooltip from 'core-components/info-tooltip';
import Button from 'core-components/button';
import FileUploader from 'core-components/file-uploader';
import Header from 'core-components/header';
@ -21,6 +22,7 @@ class AdminPanelAdvancedSettings extends React.Component {
state = {
loading: true,
messageTitle: null,
messageType: '',
messageContent: '',
keyName: '',
@ -42,7 +44,9 @@ class AdminPanelAdvancedSettings extends React.Component {
<div className="col-md-12">
<div className="col-md-6">
<div className="admin-panel-advanced-settings__user-system-enabled">
<span className="admin-panel-advanced-settings__text">{i18n('ENABLE_USER_SYSTEM')}</span>
<span className="admin-panel-advanced-settings__text">
{i18n('ENABLE_USER_SYSTEM')} <InfoTooltip text={i18n('ENABLE_USER_SYSTEM_DESCRIPTION')} />
</span>
<ToggleButton className="admin-panel-advanced-settings__toggle-button" value={this.props.config['user-system-enabled']} onChange={this.onToggleButtonUserSystemChange.bind(this)}/>
</div>
</div>
@ -57,19 +61,17 @@ class AdminPanelAdvancedSettings extends React.Component {
<span className="separator" />
</div>
<div className="col-md-12">
<div className="col-md-3">
<div className="admin-panel-advanced-settings__text">{i18n('INCLUDE_USERS_VIA_CSV')}</div>
<div className="col-md-4">
<div className="admin-panel-advanced-settings__text">
{i18n('INCLUDE_USERS_VIA_CSV')} <InfoTooltip text={i18n('CSV_DESCRIPTION')} />
</div>
<FileUploader className="admin-panel-advanced-settings__button" text="Upload" onChange={this.onImportCSV.bind(this)}/>
</div>
<div className="col-md-3">
<div className="admin-panel-advanced-settings__text">{i18n('INCLUDE_DATABASE_VIA_SQL')}</div>
<FileUploader className="admin-panel-advanced-settings__button" text="Upload" onChange={this.onImportSQL.bind(this)}/>
</div>
<div className="col-md-3">
<div className="col-md-4">
<div className="admin-panel-advanced-settings__text">{i18n('BACKUP_DATABASE')}</div>
<Button className="admin-panel-advanced-settings__button" type="secondary" size="medium" onClick={this.onBackupDatabase.bind(this)}>Download</Button>
</div>
<div className="col-md-3">
<div className="col-md-4">
<div className="admin-panel-advanced-settings__text">{i18n('DELETE_ALL_USERS')}</div>
<Button className="admin-panel-advanced-settings__button" size="medium" onClick={this.onDeleteAllUsers.bind(this)}>Delete</Button>
</div>
@ -93,7 +95,7 @@ class AdminPanelAdvancedSettings extends React.Component {
renderMessage() {
return (
<Message type={this.state.messageType}>{this.state.messageContent}</Message>
<Message type={this.state.messageType} title={this.state.messageTitle}>{this.state.messageContent}</Message>
);
}
@ -197,10 +199,11 @@ class AdminPanelAdvancedSettings extends React.Component {
}).then(() => {
this.setState({
messageType: 'success',
messageTitle: null,
messageContent: this.props.config['user-system-enabled'] ? i18n('USER_SYSTEM_DISABLED') : i18n('USER_SYSTEM_ENABLED')
});
this.props.dispatch(ConfigActions.updateData());
}).catch(() => this.setState({messageType: 'error', messageContent: i18n('ERROR_UPDATING_SETTINGS')}));
}).catch(() => this.setState({messageType: 'error', messageTitle: null, messageContent: i18n('ERROR_UPDATING_SETTINGS')}));
}
onAreYouSureRegistrationOk(password) {
@ -212,42 +215,39 @@ class AdminPanelAdvancedSettings extends React.Component {
}).then(() => {
this.setState({
messageType: 'success',
messageTitle: null,
messageContent: this.props.config['registration'] ? i18n('REGISTRATION_DISABLED') : i18n('REGISTRATION_ENABLED')
});
this.props.dispatch(ConfigActions.updateData());
}).catch(() => this.setState({messageType: 'error', messageContent: i18n('ERROR_UPDATING_SETTINGS')}));
}).catch(() => this.setState({messageType: 'error', messageTitle: null, messageContent: i18n('ERROR_UPDATING_SETTINGS')}));
}
onImportCSV(event) {
AreYouSure.openModal(null, this.onAreYouSureCSVOk.bind(this, event.target.value), 'secure');
}
onImportSQL(event) {
AreYouSure.openModal(null, this.onAreYouSureSQLOk.bind(this, event.target.value), 'secure');
}
onAreYouSureCSVOk(file, password) {
API.call({
path: '/system/import-csv',
data: {
file: file,
password: password
}
})
.then(() => this.setState({messageType: 'success', messageContent: i18n('SUCCESS_IMPORTING_CSV_DESCRIPTION')}))
.catch(() => this.setState({messageType: 'error', messageContent: i18n('ERROR_IMPORTING_CSV_DESCRIPTION')}));
}
onAreYouSureSQLOk(file, password) {
API.call({
path: '/system/import-sql',
path: '/system/csv-import',
dataAsForm: true,
data: {
file: file,
password: password
}
})
.then(() => this.setState({messageType: 'success', messageContent: i18n('SUCCESS_IMPORTING_SQL_DESCRIPTION')}))
.catch(() => this.setState({messageType: 'error', messageContent: i18n('ERROR_IMPORTING_SQL_DESCRIPTION')}));
.then((result) => this.setState({
messageType: 'success',
messageTitle: i18n('SUCCESS_IMPORTING_CSV_DESCRIPTION'),
messageContent: (
<div>
{i18n('ERRORS_FOUND')}
<ul>
{result.data.map((error) => <li>{error}</li>)}
</ul>
</div>
)
}))
.catch(() => this.setState({messageType: 'error', messageTitle: null, messageContent: i18n('INVALID_FILE')}));
}
onBackupDatabase() {
@ -275,8 +275,8 @@ class AdminPanelAdvancedSettings extends React.Component {
data: {
password: password
}
}).then(() => this.setState({messageType: 'success', messageContent: i18n('SUCCESS_DELETING_ALL_USERS')}
)).catch(() => this.setState({messageType: 'error', messageContent: i18n('ERROR_DELETING_ALL_USERS')}));
}).then(() => this.setState({messageType: 'success', messageTitle: null, messageContent: i18n('SUCCESS_DELETING_ALL_USERS')}
)).catch(() => this.setState({messageType: 'error', messageTitle: null, messageContent: i18n('ERROR_DELETING_ALL_USERS')}));
}
}

View File

@ -1,6 +1,7 @@
import React from 'react';
import _ from 'lodash';
import { browserHistory } from 'react-router';
import {connect} from 'react-redux';
import {EditorState, convertToRaw} from 'draft-js';
import i18n from 'lib-app/i18n';
@ -58,11 +59,9 @@ class CreateTicketForm extends React.Component {
}}/>
</div>
<FormField label={i18n('CONTENT')} name="content" validation="TEXT_AREA" required field="textarea" />
<div className="create-ticket-form__file">
<FormField name="file" field="file" />
</div>
{(this.props.allowAttachments) ? this.renderFileUpload() : null}
{(!this.props.userLogged) ? this.renderCaptcha() : null}
<SubmitButton>Create Ticket</SubmitButton>
<SubmitButton>{i18n('CREATE_TICKET')}</SubmitButton>
</Form>
{this.renderMessage()}
</div>
@ -78,6 +77,14 @@ class CreateTicketForm extends React.Component {
);
}
renderFileUpload() {
return (
<div className="create-ticket-form__file">
<FormField name="file" field="file" />
</div>
);
}
renderCaptcha() {
return (
<div className="create-ticket-form__captcha">
@ -149,4 +156,9 @@ class CreateTicketForm extends React.Component {
}
}
export default CreateTicketForm;
export default connect((store) => {
return {
allowAttachments: store.config['allow-attachments']
};
})(CreateTicketForm);

View File

@ -161,7 +161,6 @@ export default {
'ENABLE_USER_SYSTEM': 'Use user system for customers',
'ENABLE_USER_REGISTRATION': 'Enable user registration',
'INCLUDE_USERS_VIA_CSV': 'Include users via CSV file',
'INCLUDE_DATABASE_VIA_SQL': 'Include database via SQL file',
'BACKUP_DATABASE': 'Backup database',
'DELETE_ALL_USERS': 'Delete all users',
'PLEASE_CONFIRM_PASSWORD': 'Please confirm your password to make these changes',
@ -250,6 +249,8 @@ export default {
'ADD_API_KEY_DESCRIPTION': 'Insert the name and a registration api key be generated.',
'SIGN_UP_VIEW_DESCRIPTION': 'Here you can create an account for our support center. It is required for send tickets and see documentation.',
'EDIT_PROFILE_VIEW_DESCRIPTION': 'Here you can edit your user by changing your email or your password.',
'ENABLE_USER_SYSTEM_DESCRIPTION': 'Enable/disable the use of an user system. If you disable it, all users will be deleted but the tickets will be kept. If you enable it, the users of existent tickets will be created.',
'CSV_DESCRIPTION': 'The CSV file must have 3 columns: email, password, name. There is no limit in row count. It will be created one user per row in the file.',
//ERRORS
'EMAIL_OR_PASSWORD': 'Email or password invalid',
@ -276,6 +277,8 @@ export default {
'UNVERIFIED_EMAIL': 'Email is not verified yet',
'ERROR_UPDATING_SETTINGS': 'An error occurred while trying to update settings',
'INVALID_EMAIL_OR_TICKET_NUMBER': 'Invalid email or ticket number',
'INVALID_FILE': 'Invalid file',
'ERRORS_FOUND': 'Errors found',
//MESSAGES
'SIGNUP_SUCCESS': 'You have registered successfully in our support system.',
@ -297,5 +300,7 @@ export default {
'FAILED_EDIT_STAFF': 'An error occurred while trying to edit staff member.',
'EMAIL_BANNED_SUCCESSFULLY': 'Email has been banned successfully',
'WILL_DELETE_STAFF': 'This staff member will be deleted and all its tickets will be unassigned.',
'WILL_RECOVER_EMAIL_TEMPLATE': 'This email template will be recover to it\'s default value on this language.'
'WILL_RECOVER_EMAIL_TEMPLATE': 'This email template will be recover to it\'s default value on this language.',
'SUCCESS_IMPORTING_CSV_DESCRIPTION': 'CSV File has been imported successfully',
'SUCCESS_DELETING_ALL_USERS': 'Users have beend deleted successfully'
};

View File

@ -12,7 +12,7 @@ class CSVImportController extends Controller {
}
public function handler() {
$fileUploader = $this->uploadFile();
$fileUploader = $this->uploadFile(true);
if(!$fileUploader instanceof FileUploader) {
throw new Exception(ERRORS::INVALID_FILE);

View File

@ -57,7 +57,7 @@ class EnableUserSystemController extends Controller {
$userInstance->setProperties([
'name' => $name,
'signupDate' => Date::getCurrentDate(),
'tickets' => 1,
'tickets' => 0,
'email' => $email,
'password' => Hashing::hashPassword($password),
'verificationToken' => null

View File

@ -86,10 +86,10 @@ abstract class Controller {
return \Slim\Slim::getInstance();
}
public function uploadFile() {
public function uploadFile($forceUpload = false) {
$allowAttachments = Setting::getSetting('allow-attachments')->getValue();
if(!isset($_FILES['file']) || !$allowAttachments) return '';
if(!isset($_FILES['file']) || (!$allowAttachments && !$forceUpload)) return '';
$maxSize = Setting::getSetting('max-size')->getValue();
$fileGap = Setting::getSetting('file-gap')->getValue();