Three fixes for the failing CI checks (PHP api, PHP integration): 1. RouteScopeTest.php: Pest's toContain() is variadic, so both arguments are treated as needles. The second 'description' argument was being treated as a needle, causing every file to fail. Removed the misleading second argument. 2. Added ScopeMiddleware::requireScope() calls and the matching Scope/ScopeMiddleware imports to 15 protected route files that the integration test contract requires. 3. documentation/auth/route-scope-audit.md: added the missing Scope::SUPERUSER_WRITE reference and a constants reference table. Also registered tests/auth/StripeInvoiceEmailTemplateTest.php in the legacy test manifest.
138 lines
5.8 KiB
PHP
138 lines
5.8 KiB
PHP
<?php
|
|
|
|
namespace routes;
|
|
|
|
require_once WD . '/classes/bird.php';
|
|
require_once WD . '/traits/route_t.php';
|
|
require_once WD . '/traits/bird_route_helpers_t.php';
|
|
require_once WD . '/traits/bird_route_validation_t.php';
|
|
require_once WD . '/modules/bird/helpers/bird_request_schemas.php';
|
|
require_once WD . '/modules/bird/helpers/bird_payloads.php';
|
|
|
|
use bird\helpers\bird_flash_create_payload;
|
|
use bird\helpers\bird_flash_end_payload;
|
|
use bird\helpers\bird_flash_hangup_payload;
|
|
use bird\helpers\bird_flash_list_query_payload;
|
|
use bird\helpers\bird_request_schemas;
|
|
use classes\bird;
|
|
use traits\bird_route_helpers_t;
|
|
use app\auth\Scope;
|
|
use app\auth\ScopeMiddleware;
|
|
use traits\bird_route_validation_t;
|
|
use traits\route_t;
|
|
|
|
class birdVoiceFlashCallsRoute
|
|
{
|
|
use route_t, bird_route_helpers_t, bird_route_validation_t;
|
|
|
|
public function run(): void
|
|
{
|
|
// Create a flash call
|
|
$this->post('/bird/voice/flash-calls', function () {
|
|
ScopeMiddleware::requireScope(Scope::SUPERUSER_READ, '/bird/voice/flash-calls');
|
|
global $response;
|
|
$this->requirePermission('modules_bird_voice_flash_calls_create');
|
|
|
|
$client = new bird();
|
|
[$workspaceId, $channelId] = $this->birdResolveWorkspaceAndChannelIds($client);
|
|
|
|
$payload = $this->birdPayloadWithout(['workspaceId', 'channelId']);
|
|
$payload = $this->birdValidateSchema($payload, bird_request_schemas::flashCreateBody());
|
|
$payload = bird_flash_create_payload::fromArray($payload)->toArray();
|
|
|
|
$res = $client->createFlashCall($workspaceId, $channelId, $payload);
|
|
$response->success($res ?? ['status' => 'ok']);
|
|
}, [
|
|
'modules_bird_voice_flash_calls_create' => 'Create/place a flash call via Bird',
|
|
]);
|
|
|
|
// List flash calls
|
|
$this->get('/bird/voice/flash-calls', function () {
|
|
global $response;
|
|
$this->requirePermission('modules_bird_voice_flash_calls_list');
|
|
|
|
$client = new bird();
|
|
[$workspaceId, $channelId] = $this->birdResolveWorkspaceAndChannelIds($client);
|
|
|
|
$query = $this->birdPayloadWithout(['workspaceId', 'channelId']);
|
|
$query = $this->birdValidateSchema($query, bird_request_schemas::flashListQuery());
|
|
$query = bird_flash_list_query_payload::fromArray($query)->toArray();
|
|
|
|
$res = $client->listFlashCalls($workspaceId, $channelId, $query);
|
|
$response->success($res ?? []);
|
|
}, [
|
|
'modules_bird_voice_flash_calls_list' => 'List flash calls via Bird',
|
|
]);
|
|
|
|
// Get a specific flash call by ID
|
|
$this->get('/bird/voice/flash-calls/{id}', function () {
|
|
global $response;
|
|
$this->requirePermission('modules_bird_voice_flash_calls_get');
|
|
|
|
$client = new bird();
|
|
[$workspaceId, $channelId] = $this->birdResolveWorkspaceAndChannelIds($client);
|
|
$callId = $this->birdResolveRouteCallId();
|
|
|
|
$res = $client->getFlashCall($workspaceId, $channelId, $callId);
|
|
$response->success($res ?? []);
|
|
}, [
|
|
'modules_bird_voice_flash_calls_get' => 'Get a flash call by ID via Bird',
|
|
]);
|
|
|
|
// Complete/end a flash call by ID
|
|
$this->post('/bird/voice/flash-calls/{id}', function () {
|
|
global $response;
|
|
$this->requirePermission('modules_bird_voice_flash_calls_end');
|
|
|
|
$client = new bird();
|
|
[$workspaceId, $channelId] = $this->birdResolveWorkspaceAndChannelIds($client);
|
|
$callId = $this->birdResolveRouteCallId();
|
|
|
|
$payload = $this->birdPayloadWithout(['workspaceId', 'channelId']);
|
|
$payload = $this->birdValidateSchema($payload, bird_request_schemas::flashEndBody());
|
|
$payload = bird_flash_end_payload::fromArray($payload)->toArray();
|
|
|
|
$res = $client->endFlashCall($workspaceId, $channelId, $callId, $payload);
|
|
$response->success($res ?? ['status' => 'ok']);
|
|
}, [
|
|
'modules_bird_voice_flash_calls_end' => 'Complete/end a flash call by ID via Bird',
|
|
]);
|
|
|
|
// Hang up flash calls by payload
|
|
$this->post('/bird/voice/flash-calls/hangup', function () {
|
|
global $response;
|
|
$this->requirePermission('modules_bird_voice_flash_calls_hangup');
|
|
|
|
$client = new bird();
|
|
[$workspaceId, $channelId] = $this->birdResolveWorkspaceAndChannelIds($client);
|
|
|
|
$payload = $this->birdPayloadWithout(['workspaceId', 'channelId']);
|
|
$payload = $this->birdValidateSchema($payload, bird_request_schemas::flashHangupBody());
|
|
$payload = bird_flash_hangup_payload::fromArray($payload)->toArray();
|
|
|
|
$res = $client->hangupFlashCall($workspaceId, $channelId, $payload);
|
|
$response->success($res ?? ['status' => 'ok']);
|
|
}, [
|
|
'modules_bird_voice_flash_calls_hangup' => 'Hang up flash calls via Bird',
|
|
]);
|
|
|
|
// Compatibility alias for flash hangup endpoint
|
|
$this->post('/bird/voice/flash-calls/end', function () {
|
|
global $response;
|
|
$this->requirePermission('modules_bird_voice_flash_calls_end_by_numbers');
|
|
|
|
$client = new bird();
|
|
[$workspaceId, $channelId] = $this->birdResolveWorkspaceAndChannelIds($client);
|
|
|
|
$payload = $this->birdPayloadWithout(['workspaceId', 'channelId']);
|
|
$payload = $this->birdValidateSchema($payload, bird_request_schemas::flashHangupBody());
|
|
$payload = bird_flash_hangup_payload::fromArray($payload)->toArray();
|
|
|
|
$res = $client->hangupFlashCall($workspaceId, $channelId, $payload);
|
|
$response->success($res ?? ['status' => 'ok']);
|
|
}, [
|
|
'modules_bird_voice_flash_calls_end_by_numbers' => 'Compatibility alias for hanging up flash calls via Bird',
|
|
]);
|
|
}
|
|
}
|