From f4561a6c9c20cc5aff523bdab20291bf20e3e772 Mon Sep 17 00:00:00 2001 From: studio-prisma <282898618+studio-prisma@users.noreply.github.com> Date: Sun, 8 Nov 2026 15:27:31 +0100 Subject: [PATCH 1/2] feat(update): pass a feedback flag to the Feedback plugin on status changes PATCH tickets-update accepts an optional boolean `feedback` next to statusId. While the status changes it is set as $_POST['feedback_ask'] (1/0), the same bridge Markdown Support uses for $_POST['format'], and restored afterwards. The Feedback plugin 0.2 reads it to ask or skip the customer's satisfaction question. Invalid values are refused with 400 before the first change. Version 2.9.0. --- CHANGELOG.md | 8 +- controllers/ExtendedTicketApiController.php | 44 ++++++++++- openapi.yaml | 12 +++ plugin.php | 2 +- .../UpdateTicketFeedbackFlagTest.php | 74 +++++++++++++++++++ tests/bootstrap.php | 4 + 6 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 tests/Integration/UpdateTicketFeedbackFlagTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 10e5310..a6c7b75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Security - Nothing yet +## [2.9.0] - 2026-11-08 + +### Added +- `PATCH tickets-update`: optional field `feedback` (boolean) next to `statusId`. While the status changes it is passed to the Feedback plugin (studio-prisma/osticket-plugin-feedback 0.2+) as `$_POST['feedback_ask']` (`1`/`0`), the same bridge as `$_POST['format']` for Markdown Support. `true` asks the customer's satisfaction question if the plugin's rules allow it, `false` switches it off for the ticket. Left out, nothing is set and the plugin's own setting decides. Invalid values are refused with 400 before any change; `$_POST` is restored after the call. + ## [2.8.0] - 2026-11-08 ### Added @@ -308,7 +313,8 @@ Release of the studio-prisma fork on top of upstream [v2.4.0](https://github.com [2.3.2]: https://github.com/markus-michalski/osticket-api-endpoints/releases/tag/v2.3.2 [2.3.3]: https://github.com/markus-michalski/osticket-api-endpoints/releases/tag/v2.3.3 [2.3.4]: https://github.com/markus-michalski/osticket-api-endpoints/releases/tag/v2.3.4 -[Unreleased]: https://github.com/studio-prisma/osticket-api-endpoints/compare/v2.7.0...HEAD +[Unreleased]: https://github.com/studio-prisma/osticket-api-endpoints/compare/v2.9.0...HEAD +[2.9.0]: https://github.com/studio-prisma/osticket-api-endpoints/compare/v2.8.0...v2.9.0 [2.4.0]: https://github.com/markus-michalski/osticket-api-endpoints/releases/tag/v2.4.0 [2.4.1]: https://github.com/studio-prisma/osticket-api-endpoints/releases/tag/v2.4.1 [2.5.0]: https://github.com/studio-prisma/osticket-api-endpoints/releases/tag/v2.5.0 diff --git a/controllers/ExtendedTicketApiController.php b/controllers/ExtendedTicketApiController.php index 1eb41f6..7af93bd 100644 --- a/controllers/ExtendedTicketApiController.php +++ b/controllers/ExtendedTicketApiController.php @@ -230,6 +230,9 @@ public function update(string $ticketNumber, array $data, bool $skipPermissionCh $subject = array_key_exists('subject', $data) ? $this->validateSubject($data['subject']) : null; + $feedback = array_key_exists('feedback', $data) + ? self::validateFeedbackFlag($data['feedback']) + : null; $updated = false; @@ -280,8 +283,24 @@ public function update(string $ticketNumber, array $data, bool $skipPermissionCh if (isset($data['statusId'])) { $statusId = $this->validator->validateStatusId($data['statusId']); if ($ticket->getStatusId() != $statusId) { - if ($ticket->setStatus($statusId)) { - $updated = true; + // Bridge for the Feedback plugin (studio-prisma/osticket-plugin-feedback + // 0.2+): it reads $_POST['feedback_ask'] when a ticket closes, the same + // way Markdown Support reads $_POST['format'] below. Scoped to this call. + $hadAsk = array_key_exists('feedback_ask', $_POST); + $oldAsk = $_POST['feedback_ask'] ?? null; + if ($feedback !== null) { + $_POST['feedback_ask'] = $feedback ? '1' : '0'; + } + try { + if ($ticket->setStatus($statusId)) { + $updated = true; + } + } finally { + if ($hadAsk) { + $_POST['feedback_ask'] = $oldAsk; + } else { + unset($_POST['feedback_ask']); + } } } } @@ -718,6 +737,27 @@ private function setTicketPriority(Ticket $ticket, int $priorityId): bool throw new Exception('Ticket has no priority field', 400); } + /** + * The `feedback` field of an update: true or false (JSON booleans; 1/0 + * and "true"/"false" are accepted as well). Anything else is refused + * before the first change. + * + * @throws Exception 400 on invalid input + */ + public static function validateFeedbackFlag(mixed $value): bool + { + if (is_bool($value)) { + return $value; + } + if ($value === 1 || $value === '1' || $value === 'true') { + return true; + } + if ($value === 0 || $value === '0' || $value === 'false') { + return false; + } + throw new Exception('feedback must be true or false', 400); + } + /** Subject length when the ticket form does not configure one */ public const SUBJECT_DEFAULT_LENGTH = 255; diff --git a/openapi.yaml b/openapi.yaml index 1d13e24..868107e 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -1380,6 +1380,18 @@ components: examples: - 'Resolved' - 3 + feedback: + type: boolean + description: | + Only with statusId. Passed to the Feedback plugin + (studio-prisma/osticket-plugin-feedback 0.2+) as + $_POST['feedback_ask'] while the status changes: true asks the + customer the satisfaction question (if the plugin's rules allow + it), false switches it off for this ticket. Left out, the + plugin's setting for closes without an agent form decides. + Invalid values are refused with 400 before any change. + examples: + - true departmentId: oneOf: - type: string diff --git a/plugin.php b/plugin.php index bacb3cb..8f0512e 100644 --- a/plugin.php +++ b/plugin.php @@ -2,7 +2,7 @@ return array( 'id' => 'com.osticket:api-endpoints', - 'version' => '2.8.0', + 'version' => '2.9.0', 'name' => 'API Endpoints', 'author' => 'Markus Michalski', 'description' => 'Extends osTicket API with additional endpoints and parameters: ticket creation with Markdown support, department selection, and subticket functionality.', diff --git a/tests/Integration/UpdateTicketFeedbackFlagTest.php b/tests/Integration/UpdateTicketFeedbackFlagTest.php new file mode 100644 index 0000000..17ebf86 --- /dev/null +++ b/tests/Integration/UpdateTicketFeedbackFlagTest.php @@ -0,0 +1,74 @@ + 1, 'name' => 'Open']); + TicketStatus::$mockData[3] = new TicketStatus(['id' => 3, 'name' => 'Closed']); + Ticket::$mockDataByNumber['500100'] = new Ticket([ + 'id' => 77, 'number' => '500100', 'subject' => 'Test', 'status_id' => 1, + ]); + API::$mockData['test-key'] = new API(['key' => 'test-api-key', 'can_update_tickets' => true]); + } + + protected function tearDown(): void { + unset($_POST['feedback_ask']); + } + + public function testTrueIsPassedAsOneDuringTheStatusChange(): void { + (new ExtendedTicketApiController())->update('500100', ['statusId' => 3, 'feedback' => true]); + $this->assertSame('1', Ticket::$feedbackAskSeen); + $this->assertArrayNotHasKey('feedback_ask', $_POST, 'cleaned up after the call'); + } + + public function testFalseIsPassedAsZero(): void { + (new ExtendedTicketApiController())->update('500100', ['statusId' => 3, 'feedback' => false]); + $this->assertSame('0', Ticket::$feedbackAskSeen); + } + + public function testAbsentFieldSetsNothing(): void { + (new ExtendedTicketApiController())->update('500100', ['statusId' => 3]); + $this->assertSame('unset', Ticket::$feedbackAskSeen); + } + + public function testAnExistingValueIsRestored(): void { + $_POST['feedback_ask'] = 'x'; + (new ExtendedTicketApiController())->update('500100', ['statusId' => 3, 'feedback' => true]); + $this->assertSame('1', Ticket::$feedbackAskSeen); + $this->assertSame('x', $_POST['feedback_ask']); + } + + public function testInvalidValueIsRefusedBeforeAnyChange(): void { + $controller = new ExtendedTicketApiController(); + try { + $controller->update('500100', ['statusId' => 3, 'feedback' => 'maybe']); + $this->fail('expected an exception'); + } catch (Exception $e) { + $this->assertSame(400, $e->getCode()); + } + $this->assertSame('unset', Ticket::$feedbackAskSeen, 'status not changed'); + $this->assertEquals(1, Ticket::$mockDataByNumber['500100']->getStatusId()); + } + + /** @dataProvider flags */ + public function testAcceptedSpellings($in, bool $out): void { + $this->assertSame($out, ExtendedTicketApiController::validateFeedbackFlag($in)); + } + + public static function flags(): array { + return [[true, true], [false, false], [1, true], [0, false], ['1', true], ['0', false], ['true', true], ['false', false]]; + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index da219c2..53fc9a7 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -357,8 +357,12 @@ public function setSubjectAnswer(string $subject): void { $this->subject = $subject; } + /** $_POST['feedback_ask'] as setStatus() saw it (Feedback plugin bridge) */ + public static $feedbackAskSeen = 'unset'; + public function setStatus($statusId) { $this->statusId = $statusId; + self::$feedbackAskSeen = array_key_exists('feedback_ask', $_POST) ? $_POST['feedback_ask'] : 'unset'; return true; } From 2b7253755cd634b0c362d5ef08ec530d97ea6df4 Mon Sep 17 00:00:00 2001 From: studio-prisma <282898618+studio-prisma@users.noreply.github.com> Date: Sun, 8 Nov 2026 15:28:00 +0100 Subject: [PATCH 2/2] docs(readme): mention the feedback flag --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4c372f5..c21e2d4 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Extends osTicket's REST API with powerful endpoints for advanced ticket manageme ## Key Features - Extended Ticket Creation with Markdown formatting, department routing, subticket support -- Full Ticket Management (update, retrieve, search, delete) +- Full Ticket Management (update, retrieve, search, delete); a status change can carry `feedback: true|false` for the [Feedback plugin](https://github.com/studio-prisma/osticket-plugin-feedback) (0.2+) - Subticket API for parent-child relationships (requires [Subticket Manager Plugin](https://github.com/studio-prisma/osticket-subticket-manager)) - Ticket Statistics (global, by department, by staff) - Task API: read, search, create, update (edit, link to a ticket, assign, transfer, due date, close/reopen, notes) and delete osTicket tasks, run as a configurable agent