From 6083c8731dd8d1d9c21ddd2f20e57097e56e7b2b Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 13 Oct 2016 20:29:36 -0300 Subject: [PATCH] Ivan - Add delete custom response [skip ci] --- server/controllers/ticket.php | 2 ++ .../ticket/delete-custom-response.php | 26 +++++++++++++++++++ server/models/DataStore.php | 4 +++ tests/ticket/custom-response.rb | 14 ++++++++++ 4 files changed, 46 insertions(+) create mode 100644 server/controllers/ticket/delete-custom-response.php diff --git a/server/controllers/ticket.php b/server/controllers/ticket.php index 5a93e7bc..c7908497 100644 --- a/server/controllers/ticket.php +++ b/server/controllers/ticket.php @@ -3,6 +3,7 @@ include 'ticket/create.php'; include 'ticket/comment.php'; include 'ticket/get.php'; include 'ticket/add-custom-response.php'; +include 'ticket/delete-custom-response.php'; include 'ticket/edit-custom-response.php'; include 'ticket/get-custom-responses.php'; @@ -13,6 +14,7 @@ $ticketControllers->addController(new CreateController); $ticketControllers->addController(new CommentController); $ticketControllers->addController(new TicketGetController); $ticketControllers->addController(new AddCustomResponseController); +$ticketControllers->addController(new DeleteCustomResponseController); $ticketControllers->addController(new EditCustomResponseController); $ticketControllers->addController(new GetCustomResponsesController); diff --git a/server/controllers/ticket/delete-custom-response.php b/server/controllers/ticket/delete-custom-response.php new file mode 100644 index 00000000..087c3b4d --- /dev/null +++ b/server/controllers/ticket/delete-custom-response.php @@ -0,0 +1,26 @@ + 'staff_2', + 'requestData' => [ + 'id' => [ + 'validation' => DataValidator::dataStoreId('customresponse'), + 'error' => ERRORS::INVALID_NAME + ] + ] + ]; + } + + public function handler() { + $customResponse = CustomResponse::getDataStore(Controller::request('id')); + $customResponse->trash(); + + Response::respondSuccess(); + } +} \ No newline at end of file diff --git a/server/models/DataStore.php b/server/models/DataStore.php index 614c9b5e..2df06b88 100644 --- a/server/models/DataStore.php +++ b/server/models/DataStore.php @@ -120,6 +120,10 @@ abstract class DataStore { return RedBean::store($this->getBeanInstance()); } + public function trash() { + RedBean::trash($this->getBeanInstance()); + } + public function delete() { RedBean::trash($this->getBeanInstance()); unset($this); diff --git a/tests/ticket/custom-response.rb b/tests/ticket/custom-response.rb index b3c645c2..9321565e 100644 --- a/tests/ticket/custom-response.rb +++ b/tests/ticket/custom-response.rb @@ -53,4 +53,18 @@ describe 'CustomResponses' do (result['data'][0]['language']).should.equal('en') end end + + describe '/ticket/delete-custom-responses/' do + it 'should delete custom response' do + result = request('/ticket/delete-custom-response', { + csrf_userid: $csrf_userid, + csrf_token: $csrf_token, + id: 1 + }) + + (result['status']).should.equal('success') + customResponse = $database.getRow('customresponse', 1) + (customResponse).should.equal(nil) + end + end end \ No newline at end of file