Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 42 additions & 2 deletions controllers/ExtendedTicketApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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']);
}
}
}
}
Expand Down Expand Up @@ -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;

Expand Down
12 changes: 12 additions & 0 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
74 changes: 74 additions & 0 deletions tests/Integration/UpdateTicketFeedbackFlagTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

use PHPUnit\Framework\TestCase;

/**
* `feedback` on PATCH tickets-update: passed to the Feedback plugin as
* $_POST['feedback_ask'] while the status changes, and only then.
*/
class UpdateTicketFeedbackFlagTest extends TestCase {

protected function setUp(): void {
Ticket::$mockData = [];
Ticket::$mockDataByNumber = [];
API::$mockData = [];
TicketStatus::$mockData = [];
Ticket::$feedbackAskSeen = 'unset';
unset($_POST['feedback_ask']);

TicketStatus::$mockData[1] = new TicketStatus(['id' => 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]];
}
}
4 changes: 4 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading