From 5112a6a13bdae0f84dcc14c7e4038d5b3df31490 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Wed, 22 Mar 2017 12:54:43 -0400 Subject: [PATCH] Make the endpoint only for ticket message attachments, not replies --- .../Attachments/AttachmentHandler.php | 6 +----- .../CreateAttachmentForTicketModel.php | 3 --- .../StaffTicketAttachmentsController.php | 9 ++++----- .../Attachments/AttachmentHandlerTest.php | 18 +++--------------- api/index.php | 2 +- 5 files changed, 9 insertions(+), 29 deletions(-) diff --git a/api/BusinessLogic/Attachments/AttachmentHandler.php b/api/BusinessLogic/Attachments/AttachmentHandler.php index 60c32cf0..a05291d4 100644 --- a/api/BusinessLogic/Attachments/AttachmentHandler.php +++ b/api/BusinessLogic/Attachments/AttachmentHandler.php @@ -47,7 +47,7 @@ class AttachmentHandler { $cleanedFileName, $fileParts['extension']); $ticketAttachment->displayName = $cleanedFileName; $ticketAttachment->ticketTrackingId = $ticket->trackingId; - $ticketAttachment->type = $createAttachmentModel->type; + $ticketAttachment->type = 0; $ticketAttachment->downloadCount = 0; $ticketAttachment->fileSize = @@ -88,10 +88,6 @@ class AttachmentHandler { $errorKeys[] = 'TICKET_ID_MISSING'; } - if (!in_array($createAttachmentModel->type, array(AttachmentType::MESSAGE, AttachmentType::REPLY))) { - $errorKeys[] = 'INVALID_ATTACHMENT_TYPE'; - } - $fileParts = pathinfo($createAttachmentModel->displayName); if (!isset($fileParts['extension']) || !in_array(".{$fileParts['extension']}", $heskSettings['attachments']['allowed_types'])) { $errorKeys[] = 'EXTENSION_NOT_PERMITTED'; diff --git a/api/BusinessLogic/Attachments/CreateAttachmentForTicketModel.php b/api/BusinessLogic/Attachments/CreateAttachmentForTicketModel.php index 04336133..7fb6f7ff 100644 --- a/api/BusinessLogic/Attachments/CreateAttachmentForTicketModel.php +++ b/api/BusinessLogic/Attachments/CreateAttachmentForTicketModel.php @@ -6,7 +6,4 @@ namespace BusinessLogic\Attachments; class CreateAttachmentForTicketModel extends CreateAttachmentModel { /* @var $ticketId int */ public $ticketId; - - /* @var $type int [use AttachmentTypeget[AttachmentHandler::class]; - $createAttachmentForTicketModel = $this->createModel(JsonRetriever::getJsonData()); + $createAttachmentForTicketModel = $this->createModel(JsonRetriever::getJsonData(), $ticketId); $createdAttachment = $attachmentHandler->createAttachmentForTicket($createAttachmentForTicketModel, $hesk_settings); return output($createdAttachment, 201); } - private function createModel($json) { + private function createModel($json, $ticketId) { $model = new CreateAttachmentForTicketModel(); $model->attachmentContents = Helpers::safeArrayGet($json, 'data'); $model->displayName = Helpers::safeArrayGet($json, 'displayName'); - $model->ticketId = Helpers::safeArrayGet($json, 'ticketId'); - $model->type = Helpers::safeArrayGet($json, 'type'); + $model->ticketId = $ticketId; return $model; } diff --git a/api/Tests/BusinessLogic/Attachments/AttachmentHandlerTest.php b/api/Tests/BusinessLogic/Attachments/AttachmentHandlerTest.php index 0a6feddc..a67bd7e6 100644 --- a/api/Tests/BusinessLogic/Attachments/AttachmentHandlerTest.php +++ b/api/Tests/BusinessLogic/Attachments/AttachmentHandlerTest.php @@ -135,18 +135,6 @@ class AttachmentHandlerTest extends TestCase { $this->attachmentHandler->createAttachmentForTicket($this->createAttachmentForTicketModel, $this->heskSettings); } - function testThatValidateThrowsAnExceptionWhenTheAttachmentTypeIsNeitherMessageNorReply() { - //-- Arrange - $this->createAttachmentForTicketModel->type = 5; - - //-- Assert - $this->expectException(ValidationException::class); - $this->expectExceptionMessageRegExp('/INVALID_ATTACHMENT_TYPE/'); - - //-- Act - $this->attachmentHandler->createAttachmentForTicket($this->createAttachmentForTicketModel, $this->heskSettings); - } - function testThatValidateThrowsAnExceptionWhenTheFileExtensionIsNotPermitted() { //-- Arrange $this->heskSettings['attachments']['allowed_types'] = array('.gif'); @@ -183,7 +171,7 @@ class AttachmentHandlerTest extends TestCase { $ticketAttachment = new TicketAttachment(); $ticketAttachment->displayName = $this->createAttachmentForTicketModel->displayName; $ticketAttachment->ticketTrackingId = $ticket->trackingId; - $ticketAttachment->type = $this->createAttachmentForTicketModel->type; + $ticketAttachment->type = 0; $ticketAttachment->downloadCount = 0; $ticketAttachment->id = 50; @@ -196,7 +184,7 @@ class AttachmentHandlerTest extends TestCase { //-- Assert self::assertThat($actual->id, self::equalTo(50)); self::assertThat($actual->downloadCount, self::equalTo(0)); - self::assertThat($actual->type, self::equalTo($this->createAttachmentForTicketModel->type)); + self::assertThat($actual->type, self::equalTo(AttachmentType::MESSAGE)); self::assertThat($actual->ticketTrackingId, self::equalTo($ticket->trackingId)); self::assertThat($actual->displayName, self::equalTo($this->createAttachmentForTicketModel->displayName)); } @@ -211,7 +199,7 @@ class AttachmentHandlerTest extends TestCase { $ticketAttachment = new TicketAttachment(); $ticketAttachment->displayName = $this->createAttachmentForTicketModel->displayName; $ticketAttachment->ticketTrackingId = $ticket->trackingId; - $ticketAttachment->type = $this->createAttachmentForTicketModel->type; + $ticketAttachment->type = AttachmentType::MESSAGE; $ticketAttachment->downloadCount = 0; $ticketAttachment->id = 50; diff --git a/api/index.php b/api/index.php index 3a894660..1dea517d 100644 --- a/api/index.php +++ b/api/index.php @@ -154,7 +154,7 @@ Link::all(array( '/v1/tickets' => \Controllers\Tickets\TicketController::class, // Attachments - '/v1/staff/attachments' => \Controllers\Attachments\StaffTicketAttachmentsController::class, + '/v1/staff/tickets/{i}/attachments' => \Controllers\Attachments\StaffTicketAttachmentsController::class, // Any URL that doesn't match goes to the 404 handler '404' => 'handle404'