Merge branch 'master' into OS156-Disable-user-system

Conflicts:
	server/controllers/system.php
	tests/init.rb
This commit is contained in:
AntonyAntonio 2017-01-17 15:03:48 -03:00
commit 35ac87ab88
13 changed files with 141 additions and 26 deletions

View File

@ -86,20 +86,24 @@ class App extends React.Component {
browserHistory.push('/admin/panel');
}
if (this.props.session.userLevel && !this.isPathAvailableForStaff()) {
if (props.session.userLevel && !this.isPathAvailableForStaff(props)) {
browserHistory.push('/admin/panel');
}
if (!props.config.registration && _.includes(props.location.pathname, 'signup')) {
browserHistory.push('/');
}
}
isPathAvailableForStaff() {
let pathForLevel2 = _.findIndex(level2Paths, path => _.includes(this.props.location.pathname, path)) !== -1;
let pathForLevel3 = _.findIndex(level3Paths, path => _.includes(this.props.location.pathname, path)) !== -1;
isPathAvailableForStaff(props) {
let pathForLevel2 = _.findIndex(level2Paths, path => _.includes(props.location.pathname, path)) !== -1;
let pathForLevel3 = _.findIndex(level3Paths, path => _.includes(props.location.pathname, path)) !== -1;
if (this.props.session.userLevel === 1) {
if (props.session.userLevel === 1) {
return !pathForLevel2 && !pathForLevel3;
}
if (this.props.session.userLevel === 2) {
if (props.session.userLevel === 2) {
return !pathForLevel3;
}

View File

@ -32,7 +32,7 @@ class MainLayoutHeader extends React.Component {
result = (
<div className="main-layout-header__login-links">
<Button type="clean" route={{to:'/'}}>{i18n('LOG_IN')}</Button>
<Button type="clean" route={{to:'/signup'}}>{i18n('SIGN_UP')}</Button>
{this.props.config === true ? <Button type="clean" route={{to:'/signup'}}>{i18n('SIGN_UP')}</Button> : null}
</div>
);
}

View File

@ -20,6 +20,7 @@ module.exports = [
'smtp-user': 'Wesa',
'maintenance-mode': false,
'allow-attachments': true,
'registration': true,
'max-size': 500,
'departments': [
{id: 1, name: 'Sales Support', owners: 2},

View File

@ -186,7 +186,7 @@ export default {
'TICKET_LIST_DESCRIPTION': 'Here you can find a list of all tickets you have sent to our support team.',
'TICKETS_DESCRIPTION': 'Send ticket through our support center and get response of your doubts, suggestions and issues.',
'ARTICLES_DESCRIPTION': 'Take a look to our articles about common issues, guides and documentation.',
'ACCOUNT_DESCRIPTION': 'All your tickets are stored in your accounts\'s profile. Keep track off all your tickets you send to our staff team.',
'ACCOUNT_DESCRIPTION': 'All your tickets are stored in your account\'s profile. Keep track of all your tickets you send to our staff team.',
'SUPPORT_CENTER_DESCRIPTION': 'Welcome to our support center. You can contact us through a tickets system. Your tickets will be answered by our staff.',
'CUSTOM_RESPONSES_DESCRIPTION': 'Custom responses are automated responses for common problems',
'MY_TICKETS_DESCRIPTION': 'Here you can view the tickets you are responsible for.',

View File

@ -18,6 +18,7 @@ require_once 'system/delete-api-key.php';
require_once 'system/get-all-keys.php';
require_once 'system/get-stats.php';
require_once 'system/delete-all-users.php';
require_once 'system/csv-import.php';
require_once 'system/backup-database.php';
require_once 'system/download.php';
@ -43,6 +44,7 @@ $systemControllerGroup->addController(new GetAllKeyController);
$systemControllerGroup->addController(new DeleteAllUsersController);
$systemControllerGroup->addController(new BackupDatabaseController);
$systemControllerGroup->addController(new DownloadController);
$systemControllerGroup->addController(new CSVImportController);
$systemControllerGroup->addController(new DisableUserSystemController);
$systemControllerGroup->addController(new EnabledUserSystemController);

View File

@ -0,0 +1,55 @@
<?php
class CSVImportController extends Controller {
const PATH = '/csv-import';
public function validations() {
return [
'permission' => 'staff_3',
'requestData' => []
];
}
public function handler() {
$fileUploader = $this->uploadFile();
if(!$fileUploader instanceof FileUploader) {
throw new Exception(ERRORS::INVALID_FILE);
}
$file = fopen($fileUploader->getFullFilePath(),'r');
$errors = [];
while(!feof($file)) {
$userList = fgetcsv($file);
Controller::setDataRequester(function ($key) use ($userList) {
switch ($key) {
case 'email':
return $userList[0];
case 'password':
return $userList[1];
case 'name':
return $userList[2];
}
return null;
});
$signupController = new SignUpController(true);
try {
$signupController->validate();
$signupController->handler();
} catch (\Exception $exception) {
$errors[] = $exception->getMessage() . ' in email ' . $userList[0];
}
}
fclose($file);
unlink($fileUploader->getFullFilePath());
Response::respondSuccess($errors);
}
}

View File

@ -61,10 +61,12 @@ class CommentController extends Controller {
}
private function storeComment() {
$fileUploader = $this->uploadFile();
$comment = Ticketevent::getEvent(Ticketevent::COMMENT);
$comment->setProperties(array(
'content' => $this->content,
'file' => $this->uploadFile(),
'file' => ($fileUploader instanceof FileUploader) ? $fileUploader->getFileName() : null,
'date' => Date::getCurrentDate()
));

View File

@ -67,6 +67,8 @@ class CreateController extends Controller {
$department = Department::getDataStore($this->departmentId);
$author = Controller::getLoggedUser();
$fileUploader = $this->uploadFile();
$ticket = new Ticket();
$ticket->setProperties(array(
'title' => $this->title,
@ -74,7 +76,7 @@ class CreateController extends Controller {
'language' => $this->language,
'author' => $author,
'department' => $department,
'file' => $this->uploadFile(),
'file' => ($fileUploader instanceof FileUploader) ? $fileUploader->getFileName() : null,
'date' => Date::getCurrentDate(),
'unread' => false,
'unreadStaff' => true,

View File

@ -10,9 +10,14 @@ class SignUpController extends Controller {
private $userName;
private $userPassword;
private $verificationToken;
private $csvImported;
public function __construct($csvImported = false) {
$this->csvImported = $csvImported;
}
public function validations() {
return [
$validations = [
'permission' => 'any',
'requestData' => [
'name' => [
@ -26,13 +31,18 @@ class SignUpController extends Controller {
'password' => [
'validation' => DataValidator::length(5, 200),
'error' => ERRORS::INVALID_PASSWORD
],
'captcha' => [
'validation' => DataValidator::captcha(),
'error' => ERRORS::INVALID_CAPTCHA
]
]
];
if(!$this->csvImported) {
$validations['requestData']['captcha'] = [
'validation' => DataValidator::captcha(),
'error' => ERRORS::INVALID_CAPTCHA
];
}
return $validations;
}
public function handler() {
@ -46,19 +56,16 @@ class SignUpController extends Controller {
$existentUser = User::getUser($this->userEmail, 'email');
if (!$existentUser->isNull()) {
Response::respondError(ERRORS::USER_EXISTS);
return;
throw new Exception(ERRORS::USER_EXISTS);
}
$banRow = Ban::getDataStore($this->userEmail,'email');
if (!$banRow->isNull()) {
Response::respondError(ERRORS::ALREADY_BANNED);
return;
throw new Exception(ERRORS::ALREADY_BANNED);
}
if (!Setting::getSetting('registration')->value && $apiKey->isNull() ) {
Response::respondError(ERRORS::NO_PERMISSION);
return;
if (!Setting::getSetting('registration')->value && $apiKey->isNull() && !$this->csvImported) {
throw new Exception(ERRORS::NO_PERMISSION);
}
$userId = $this->createNewUserAndRetrieveId();

View File

@ -23,6 +23,8 @@ include_once 'libs/FileManager.php';
include_once 'libs/FileDownloader.php';
include_once 'libs/FileUploader.php';
Controller::init();
// LOAD DATA
spl_autoload_register(function ($class) {
$classPath = "data/{$class}.php";

View File

@ -3,6 +3,7 @@ require_once 'libs/Validator.php';
require_once 'models/Session.php';
abstract class Controller {
private static $dataRequester;
/**
* Instance-related stuff
@ -28,10 +29,20 @@ abstract class Controller {
$validator->validate($this->validations());
}
public static function request($key) {
$app = self::getAppInstance();
public static function init() {
self::$dataRequester = function ($key) {
$app = self::getAppInstance();
return $app->request()->post($key);
return $app->request()->post($key);
};
}
public static function setDataRequester($dataRequester) {
self::$dataRequester = $dataRequester;
}
public static function request($key) {
return call_user_func(self::$dataRequester, $key);
}
public static function getLoggedUser() {
@ -77,7 +88,7 @@ abstract class Controller {
$fileQuantity->value++;
$fileQuantity->store();
return $fileUploader->getFileName();
return $fileUploader;
} else {
throw new Exception(ERRORS::INVALID_FILE);
}

View File

@ -58,4 +58,5 @@ require './system/add-api-key.rb'
require './system/delete-api-key.rb'
require './system/get-all-keys.rb'
require './system/file-upload-download.rb'
require './system/csv-import.rb'
require './system/disable-user-system.rb'

View File

@ -0,0 +1,28 @@
describe'system/csv-import' do
request('/user/logout')
Scripts.login($staff[:email], $staff[:password], true)
it 'should create user with csv-import' do
file = File.new('../server/files/test.csv', 'w+')
file.puts('prueba1@hotmail.com, contrasena1,ma')
file.puts('prueba2@hotmail.com,contrasena2,max')
file.puts('prueba3@hotmail.com,contrasena3,maxi')
file.close
result= request('/system/csv-import', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
file: File.open( "../server/files/test.csv")
})
(result['status']).should.equal('success')
row = $database.getRow('user', 'prueba1@hotmail.com', 'email')
(row['name']).should.equal('ma')
row = $database.getRow('user', 'prueba2@hotmail.com', 'email')
(row['name']).should.equal('max')
row = $database.getRow('user', 'prueba3@hotmail.com', 'email')
(row['name']).should.equal('maxi')
end
end