Ivan - Fix enabling user system [skip ci]

This commit is contained in:
Ivan Diaz 2017-03-04 02:57:51 -03:00
parent 6bff8e1493
commit 484bfd4e99
8 changed files with 40 additions and 35 deletions

View File

@ -63,10 +63,10 @@
"localStorage": "^1.0.3",
"lodash": "^3.10.0",
"messageformat": "^0.2.2",
"react": "^15.0.1",
"react": "^15.4.2",
"react-chartjs-2": "^2.0.0",
"react-document-title": "^1.0.2",
"react-dom": "^15.0.1",
"react-dom": "^15.4.2",
"react-draft-wysiwyg": "^1.7.6",
"react-google-recaptcha": "^0.5.2",
"react-motion": "^0.4.7",

View File

@ -179,7 +179,7 @@ class TicketViewer extends React.Component {
renderTicketEvent(options, index) {
return (
<TicketEvent {...options} author={(options.author.length) ? options.author : this.props.ticket.author} key={index} />
<TicketEvent {...options} author={(!_.isEmpty(options.author)) ? options.author : this.props.ticket.author} key={index} />
);
}

View File

@ -2,7 +2,6 @@ import React from 'react';
import _ from 'lodash';
import { browserHistory } from 'react-router';
import {EditorState, convertToRaw} from 'draft-js';
import { mdToDraftjs, draftjsToMd } from 'draftjs-md-converter';
import i18n from 'lib-app/i18n';
import API from 'lib-app/api-call';
@ -138,7 +137,7 @@ class CreateTicketForm extends React.Component {
store.dispatch(SessionActions.getUserData());
setTimeout(() => {browserHistory.push('/dashboard')}, 2000);
} else {
setTimeout(() => {browserHistory.push('/check-ticket/' + email + '/' + result.data.ticketNumber)}, 2000);
setTimeout(() => {browserHistory.push('/check-ticket/' + result.data.ticketNumber + '/' + email)}, 1000);
}
}
@ -150,4 +149,4 @@ class CreateTicketForm extends React.Component {
}
}
export default CreateTicketForm;
export default CreateTicketForm;

View File

@ -1,4 +1,5 @@
<?php
use RedBeanPHP\Facade as RedBean;
use Respect\Validation\Validator as DataValidator;
class GetNewTicketsStaffController extends Controller {
@ -18,10 +19,16 @@ class GetNewTicketsStaffController extends Controller {
$query .= 'department_id=' . $department->id . ' OR ';
}
$query = substr($query,0,-3);
$query .= ') AND owner_id IS NULL';
$ownerExists = RedBean::exec('SHOW COLUMNS FROM ticket LIKE \'owner_id\'');
if($ownerExists != 0) {
$query .= ') AND owner_id IS NULL';
} else {
$query .= ')';
}
$ticketList = Ticket::find($query);
Response::respondSuccess($ticketList->toArray());
}
}
}

View File

@ -12,7 +12,7 @@ require_once 'system/recover-mail-template.php';
require_once 'system/disable-registration.php';
require_once 'system/enable-registration.php';
require_once 'system/disable-user-system.php';
require_once 'system/enabled-user-system.php';
require_once 'system/enable-user-system.php';
require_once 'system/add-api-key.php';
require_once 'system/delete-api-key.php';
require_once 'system/get-api-keys.php';
@ -46,6 +46,6 @@ $systemControllerGroup->addController(new BackupDatabaseController);
$systemControllerGroup->addController(new DownloadController);
$systemControllerGroup->addController(new CSVImportController);
$systemControllerGroup->addController(new DisableUserSystemController);
$systemControllerGroup->addController(new EnabledUserSystemController);
$systemControllerGroup->addController(new EnableUserSystemController);
$systemControllerGroup->finalize();
$systemControllerGroup->finalize();

View File

@ -1,7 +1,7 @@
<?php
class EnabledUserSystemController extends Controller {
const PATH = '/enabled-user-system';
class EnableUserSystemController extends Controller {
const PATH = '/enable-user-system';
const METHOD = 'POST';
public function validations() {
@ -31,19 +31,17 @@ class EnabledUserSystemController extends Controller {
foreach($ticketList as $ticket) {
$userRow = User::getDataStore($ticket->authorEmail, 'email');
$userInstance = User::getDataStore($ticket->authorEmail, 'email');
if($userRow->isNull()) {
$this->createUser($ticket->authorEmail,$ticket->authorName);
} else {
$userRow->tickets = $userRow->tickets + 1;
$userRow->sharedTicketList->add($ticket);
$userRow->store();
if($userInstance->isNull()) {
$userInstance = $this->createUser($ticket->authorEmail, $ticket->authorName);
}
$actualUserRow = User::getDataStore($ticket->authorEmail,'email');
$ticket->author = $actualUserRow;
$userInstance->tickets = $userInstance->tickets + 1;
$userInstance->sharedTicketList->add($ticket);
$userInstance->store();
$ticket->author = $userInstance;
$ticket->authorName = null;
$ticket->authorEmail = null;
$ticket->store();
@ -75,5 +73,6 @@ class EnabledUserSystemController extends Controller {
]);
$mailSender->send();
return $userInstance;
}
}
}

View File

@ -29,7 +29,7 @@ class Ticket extends DataStore {
public static function getTicket($value, $property = 'id') {
return parent::getDataStore($value, $property);
}
public static function getByTicketNumber($value) {
return Ticket::getTicket($value, 'ticketNumber');
}
@ -50,19 +50,19 @@ class Ticket extends DataStore {
public function generateUniqueTicketNumber() {
$linearCongruentialGenerator = new LinearCongruentialGenerator();
$ticketQuantity = Ticket::count();
if ($ticketQuantity === 0) {
$ticketNumber = $linearCongruentialGenerator->generateFirst();
} else {
$linearCongruentialGenerator->setGap(Setting::getSetting('ticket-gap')->value);
$linearCongruentialGenerator->setFirst(Ticket::getTicket(1)->ticketNumber);
$ticketNumber = $linearCongruentialGenerator->generate($ticketQuantity);
}
return $ticketNumber;
}
public function toArray() {
return [
'ticketNumber' => $this->ticketNumber,
@ -144,7 +144,7 @@ class Ticket extends DataStore {
return $events;
}
public function addEvent(Ticketevent $event) {
$this->ownTicketeventList->add($event);
}

View File

@ -55,8 +55,8 @@ describe'system/disable-user-system' do
(result['message']).should.equal('SYSTEM_USER_IS_ALREADY_DISABLED')
end
it 'should enabled the user system' do
result = request('/system/enabled-user-system', {
it 'should enable the user system' do
result = request('/system/enable-user-system', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
password:$staff[:password]
@ -73,8 +73,8 @@ describe'system/disable-user-system' do
end
it 'should not enabled the user system' do
result = request('/system/enabled-user-system', {
it 'should not enable the user system' do
result = request('/system/enable-user-system', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
password:$staff[:password]