Properly handle tickets that need validation. Added comments for next steps

This commit is contained in:
Mike Koch 2017-02-20 22:07:39 -05:00
parent c1638aeb98
commit 4c7449ea3e
5 changed files with 62 additions and 10 deletions

View File

@ -0,0 +1,14 @@
<?php
/**
* Created by PhpStorm.
* User: mkoch
* Date: 2/20/2017
* Time: 10:03 PM
*/
namespace BusinessLogic\Tickets;
class StageTicket extends Ticket {
//-- Nothing here, just an indicator that it is a StageTicket and not a regular Ticket
}

View File

@ -33,12 +33,18 @@ class TicketCreator {
*/ */
private $ticketGateway; private $ticketGateway;
function __construct($newTicketValidator, $trackingIdGenerator, $autoassigner, $statusGateway, $ticketGateway) { /**
* @var $verifiedEmailChecker VerifiedEmailChecker
*/
private $verifiedEmailChecker;
function __construct($newTicketValidator, $trackingIdGenerator, $autoassigner, $statusGateway, $ticketGateway, $verifiedEmailChecker) {
$this->newTicketValidator = $newTicketValidator; $this->newTicketValidator = $newTicketValidator;
$this->trackingIdGenerator = $trackingIdGenerator; $this->trackingIdGenerator = $trackingIdGenerator;
$this->autoassigner = $autoassigner; $this->autoassigner = $autoassigner;
$this->statusGateway = $statusGateway; $this->statusGateway = $statusGateway;
$this->ticketGateway = $ticketGateway; $this->ticketGateway = $ticketGateway;
$this->verifiedEmailChecker = $verifiedEmailChecker;
} }
/** /**
@ -61,8 +67,15 @@ class TicketCreator {
throw new ValidationException($validationModel); throw new ValidationException($validationModel);
} }
$emailVerified = true;
if ($modsForHeskSettings['customer_email_verification_required']) {
$emailVerified = $this->verifiedEmailChecker->isEmailVerified($ticketRequest->email, $heskSettings);
}
// Create the ticket // Create the ticket
$ticket = new Ticket(); $ticket = $emailVerified
? new Ticket()
: new StageTicket();
$ticket->trackingId = $this->trackingIdGenerator->generateTrackingId($heskSettings); $ticket->trackingId = $this->trackingIdGenerator->generateTrackingId($heskSettings);
if ($heskSettings['autoassign']) { if ($heskSettings['autoassign']) {
@ -92,7 +105,7 @@ class TicketCreator {
} }
$ticket->statusId = $status->id; $ticket->statusId = $status->id;
$ticketGatewayGeneratedFields = $this->ticketGateway->createTicket($ticket, $heskSettings); $ticketGatewayGeneratedFields = $this->ticketGateway->createTicket($ticket, $emailVerified, $heskSettings);
$ticket->dateCreated = $ticketGatewayGeneratedFields->dateCreated; $ticket->dateCreated = $ticketGatewayGeneratedFields->dateCreated;
$ticket->lastChanged = $ticketGatewayGeneratedFields->dateModified; $ticket->lastChanged = $ticketGatewayGeneratedFields->dateModified;

View File

@ -29,6 +29,10 @@ class TicketController {
$ticket = $ticketCreator->createTicketByCustomer($this->buildTicketRequestFromJson($jsonRequest), $hesk_settings, $modsForHeskSettings, $userContext); $ticket = $ticketCreator->createTicketByCustomer($this->buildTicketRequestFromJson($jsonRequest), $hesk_settings, $modsForHeskSettings, $userContext);
//if ticket is a stageTicket, email user
//else if assigned to owner, email new owner
//else email all staff
return output($ticket); return output($ticket);
} }

View File

@ -86,12 +86,11 @@ class TicketGateway extends CommonDao {
/** /**
* @param $ticket Ticket * @param $ticket Ticket
* @param $isEmailVerified
* @param $heskSettings * @param $heskSettings
* @return TicketGatewayGeneratedFields * @return TicketGatewayGeneratedFields
*/ */
function createTicket($ticket, $heskSettings) { function createTicket($ticket, $isEmailVerified, $heskSettings) {
global $hesklang;
$this->init(); $this->init();
$dueDate = $ticket->dueDate ? "'{$ticket->dueDate}'" : "NULL"; $dueDate = $ticket->dueDate ? "'{$ticket->dueDate}'" : "NULL";
@ -127,7 +126,9 @@ class TicketGateway extends CommonDao {
$ipAddress = $ticket->ipAddress !== null $ipAddress = $ticket->ipAddress !== null
&& $ticket->ipAddress !== '' ? $ticket->ipAddress : ''; && $ticket->ipAddress !== '' ? $ticket->ipAddress : '';
$sql = "INSERT INTO `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets` $tableName = $isEmailVerified ? 'tickets' : 'stage_tickets';
$sql = "INSERT INTO `" . hesk_dbEscape($heskSettings['db_pfix']) . $tableName ."`
( (
`trackid`, `trackid`,
`name`, `name`,
@ -190,7 +191,7 @@ class TicketGateway extends CommonDao {
hesk_dbQuery($sql); hesk_dbQuery($sql);
$id = hesk_dbInsertID(); $id = hesk_dbInsertID();
$rs = hesk_dbQuery('SELECT `dt`, `lastchange` FROM `' . hesk_dbEscape($heskSettings['db_pfix']) . 'tickets` WHERE `id` = ' . intval($id)); $rs = hesk_dbQuery('SELECT `dt`, `lastchange` FROM `' . hesk_dbEscape($heskSettings['db_pfix']) . $tableName .'` WHERE `id` = ' . intval($id));
$row = hesk_dbFetchAssoc($rs); $row = hesk_dbFetchAssoc($rs);
$generatedFields = new TicketGatewayGeneratedFields(); $generatedFields = new TicketGatewayGeneratedFields();

View File

@ -12,6 +12,7 @@ use BusinessLogic\Tickets\NewTicketValidator;
use BusinessLogic\Tickets\TicketCreator; use BusinessLogic\Tickets\TicketCreator;
use BusinessLogic\Tickets\TicketGatewayGeneratedFields; use BusinessLogic\Tickets\TicketGatewayGeneratedFields;
use BusinessLogic\Tickets\TrackingIdGenerator; use BusinessLogic\Tickets\TrackingIdGenerator;
use BusinessLogic\Tickets\VerifiedEmailChecker;
use BusinessLogic\ValidationModel; use BusinessLogic\ValidationModel;
use Core\Constants\Priority; use Core\Constants\Priority;
use DataAccess\Statuses\StatusGateway; use DataAccess\Statuses\StatusGateway;
@ -75,15 +76,21 @@ class CreateTicketTest extends TestCase {
*/ */
private $ticketGatewayGeneratedFields; private $ticketGatewayGeneratedFields;
/**
* @var $verifiedEmailChecker \PHPUnit_Framework_MockObject_MockObject
*/
private $verifiedEmailChecker;
protected function setUp() { protected function setUp() {
$this->ticketGateway = $this->createMock(TicketGateway::class); $this->ticketGateway = $this->createMock(TicketGateway::class);
$this->newTicketValidator = $this->createMock(NewTicketValidator::class); $this->newTicketValidator = $this->createMock(NewTicketValidator::class);
$this->trackingIdGenerator = $this->createMock(TrackingIdGenerator::class); $this->trackingIdGenerator = $this->createMock(TrackingIdGenerator::class);
$this->autoassigner = $this->createMock(Autoassigner::class); $this->autoassigner = $this->createMock(Autoassigner::class);
$this->statusGateway = $this->createMock(StatusGateway::class); $this->statusGateway = $this->createMock(StatusGateway::class);
$this->verifiedEmailChecker = $this->createMock(VerifiedEmailChecker::class);
$this->ticketCreator = new TicketCreator($this->newTicketValidator, $this->trackingIdGenerator, $this->ticketCreator = new TicketCreator($this->newTicketValidator, $this->trackingIdGenerator,
$this->autoassigner, $this->statusGateway, $this->ticketGateway); $this->autoassigner, $this->statusGateway, $this->ticketGateway, $this->verifiedEmailChecker);
$this->ticketRequest = new CreateTicketByCustomerModel(); $this->ticketRequest = new CreateTicketByCustomerModel();
$this->ticketRequest->name = 'Name'; $this->ticketRequest->name = 'Name';
@ -101,7 +108,9 @@ class CreateTicketTest extends TestCase {
'custom_fields' => array(), 'custom_fields' => array(),
'autoassign' => 0, 'autoassign' => 0,
); );
$this->modsForHeskSettings = array(); $this->modsForHeskSettings = array(
'customer_email_verification_required' => false
);
$this->userContext = new UserContext(); $this->userContext = new UserContext();
$this->newTicketValidator->method('validateNewTicketForCustomer')->willReturn(new ValidationModel()); $this->newTicketValidator->method('validateNewTicketForCustomer')->willReturn(new ValidationModel());
@ -226,4 +235,15 @@ class CreateTicketTest extends TestCase {
self::assertThat($ticket->timeWorked, self::equalTo('00:00:00')); self::assertThat($ticket->timeWorked, self::equalTo('00:00:00'));
self::assertThat($ticket->lastReplier, self::equalTo(0)); self::assertThat($ticket->lastReplier, self::equalTo(0));
} }
function testItChecksIfTheEmailIsVerified() {
//-- Arrange
$this->modsForHeskSettings['customer_email_verification_required'] = true;
//-- Assert
$this->verifiedEmailChecker->expects($this->once())->method('isEmailVerified');
//-- Act
$this->ticketCreator->createTicketByCustomer($this->ticketRequest, $this->heskSettings, $this->modsForHeskSettings, $this->userContext);
}
} }