Properly handle tickets that need validation. Added comments for next steps
This commit is contained in:
parent
c1638aeb98
commit
4c7449ea3e
14
api/BusinessLogic/Tickets/StageTicket.php
Normal file
14
api/BusinessLogic/Tickets/StageTicket.php
Normal 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
|
||||
}
|
||||
@ -33,12 +33,18 @@ class TicketCreator {
|
||||
*/
|
||||
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->trackingIdGenerator = $trackingIdGenerator;
|
||||
$this->autoassigner = $autoassigner;
|
||||
$this->statusGateway = $statusGateway;
|
||||
$this->ticketGateway = $ticketGateway;
|
||||
$this->verifiedEmailChecker = $verifiedEmailChecker;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,8 +67,15 @@ class TicketCreator {
|
||||
throw new ValidationException($validationModel);
|
||||
}
|
||||
|
||||
$emailVerified = true;
|
||||
if ($modsForHeskSettings['customer_email_verification_required']) {
|
||||
$emailVerified = $this->verifiedEmailChecker->isEmailVerified($ticketRequest->email, $heskSettings);
|
||||
}
|
||||
|
||||
// Create the ticket
|
||||
$ticket = new Ticket();
|
||||
$ticket = $emailVerified
|
||||
? new Ticket()
|
||||
: new StageTicket();
|
||||
$ticket->trackingId = $this->trackingIdGenerator->generateTrackingId($heskSettings);
|
||||
|
||||
if ($heskSettings['autoassign']) {
|
||||
@ -92,7 +105,7 @@ class TicketCreator {
|
||||
}
|
||||
$ticket->statusId = $status->id;
|
||||
|
||||
$ticketGatewayGeneratedFields = $this->ticketGateway->createTicket($ticket, $heskSettings);
|
||||
$ticketGatewayGeneratedFields = $this->ticketGateway->createTicket($ticket, $emailVerified, $heskSettings);
|
||||
|
||||
$ticket->dateCreated = $ticketGatewayGeneratedFields->dateCreated;
|
||||
$ticket->lastChanged = $ticketGatewayGeneratedFields->dateModified;
|
||||
|
||||
@ -29,6 +29,10 @@ class TicketController {
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
|
||||
@ -86,12 +86,11 @@ class TicketGateway extends CommonDao {
|
||||
|
||||
/**
|
||||
* @param $ticket Ticket
|
||||
* @param $isEmailVerified
|
||||
* @param $heskSettings
|
||||
* @return TicketGatewayGeneratedFields
|
||||
*/
|
||||
function createTicket($ticket, $heskSettings) {
|
||||
global $hesklang;
|
||||
|
||||
function createTicket($ticket, $isEmailVerified, $heskSettings) {
|
||||
$this->init();
|
||||
|
||||
$dueDate = $ticket->dueDate ? "'{$ticket->dueDate}'" : "NULL";
|
||||
@ -127,7 +126,9 @@ class TicketGateway extends CommonDao {
|
||||
$ipAddress = $ticket->ipAddress !== null
|
||||
&& $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`,
|
||||
`name`,
|
||||
@ -190,7 +191,7 @@ class TicketGateway extends CommonDao {
|
||||
hesk_dbQuery($sql);
|
||||
$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);
|
||||
|
||||
$generatedFields = new TicketGatewayGeneratedFields();
|
||||
|
||||
@ -12,6 +12,7 @@ use BusinessLogic\Tickets\NewTicketValidator;
|
||||
use BusinessLogic\Tickets\TicketCreator;
|
||||
use BusinessLogic\Tickets\TicketGatewayGeneratedFields;
|
||||
use BusinessLogic\Tickets\TrackingIdGenerator;
|
||||
use BusinessLogic\Tickets\VerifiedEmailChecker;
|
||||
use BusinessLogic\ValidationModel;
|
||||
use Core\Constants\Priority;
|
||||
use DataAccess\Statuses\StatusGateway;
|
||||
@ -75,15 +76,21 @@ class CreateTicketTest extends TestCase {
|
||||
*/
|
||||
private $ticketGatewayGeneratedFields;
|
||||
|
||||
/**
|
||||
* @var $verifiedEmailChecker \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $verifiedEmailChecker;
|
||||
|
||||
protected function setUp() {
|
||||
$this->ticketGateway = $this->createMock(TicketGateway::class);
|
||||
$this->newTicketValidator = $this->createMock(NewTicketValidator::class);
|
||||
$this->trackingIdGenerator = $this->createMock(TrackingIdGenerator::class);
|
||||
$this->autoassigner = $this->createMock(Autoassigner::class);
|
||||
$this->statusGateway = $this->createMock(StatusGateway::class);
|
||||
$this->verifiedEmailChecker = $this->createMock(VerifiedEmailChecker::class);
|
||||
|
||||
$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->name = 'Name';
|
||||
@ -101,7 +108,9 @@ class CreateTicketTest extends TestCase {
|
||||
'custom_fields' => array(),
|
||||
'autoassign' => 0,
|
||||
);
|
||||
$this->modsForHeskSettings = array();
|
||||
$this->modsForHeskSettings = array(
|
||||
'customer_email_verification_required' => false
|
||||
);
|
||||
$this->userContext = new UserContext();
|
||||
|
||||
$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->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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user