| 1 |
<?php |
| 2 |
|
| 3 |
namespace IvyForms\Controllers\GoogleSheets; |
| 4 |
|
| 5 |
use IvyForms\Common\Exceptions\ForbiddenException; |
| 6 |
use IvyForms\Common\Sanitizer\Sanitizer; |
| 7 |
use IvyForms\Controllers\Controller; |
| 8 |
use IvyForms\Services\GoogleSheets\GoogleSheetsService; |
| 9 |
use WP_REST_Request; |
| 10 |
use WP_REST_Response; |
| 11 |
|
| 12 |
/** |
| 13 |
* Legacy spreadsheet list. The form builder selects a spreadsheet through the |
| 14 |
* Google Picker and no longer calls this route. A drive.file token cannot list |
| 15 |
* the user's spreadsheets, so the response is often empty. |
| 16 |
* |
| 17 |
* @deprecated Prefer the picker-config endpoint and the Picker UI. |
| 18 |
*/ |
| 19 |
class GoogleSheetsListSpreadsheetsController extends Controller |
| 20 |
{ |
| 21 |
private GoogleSheetsService $googleSheetsService; |
| 22 |
|
| 23 |
public function __construct(GoogleSheetsService $googleSheetsService) |
| 24 |
{ |
| 25 |
$this->googleSheetsService = $googleSheetsService; |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* @throws ForbiddenException |
| 30 |
*/ |
| 31 |
protected function handle(WP_REST_Request $data): WP_REST_Response |
| 32 |
{ |
| 33 |
Sanitizer::verifyNonce($data->get_header('X-WP-Nonce')); |
| 34 |
|
| 35 |
return new WP_REST_Response([ |
| 36 |
'spreadsheets' => $this->googleSheetsService->listSpreadsheets(), |
| 37 |
], 200); |
| 38 |
} |
| 39 |
} |
| 40 |
|