|
14 | 14 | use OCA\Richdocuments\Service\DiscoveryService; |
15 | 15 | use OCA\Richdocuments\Service\FontService; |
16 | 16 | use OCA\Richdocuments\UploadException; |
| 17 | +use OCA\Richdocuments\Db\WopiMapper; |
17 | 18 | use OCP\App\IAppManager; |
| 19 | +use OCP\IGroupManager; |
18 | 20 | use OCP\AppFramework\Controller; |
19 | 21 | use OCP\AppFramework\Http; |
20 | 22 | use OCP\AppFramework\Http\Attribute\NoAdminRequired; |
@@ -58,6 +60,9 @@ public function __construct( |
58 | 60 | private FontService $fontService, |
59 | 61 | private SettingsService $settingsService, |
60 | 62 | private LoggerInterface $logger, |
| 63 | + private IGroupManager $groupManager, |
| 64 | + private IURLGenerator $urlGenerator, |
| 65 | + private WopiMapper $wopiMapper, |
61 | 66 | private ?string $userId, |
62 | 67 | ) { |
63 | 68 | parent::__construct($appName, $request); |
@@ -411,6 +416,32 @@ public function getFontFileOverview(string $name): DataDisplayResponse { |
411 | 416 | } |
412 | 417 | } |
413 | 418 |
|
| 419 | + /** |
| 420 | + * @NoAdminRequired |
| 421 | + * @PublicPage |
| 422 | + * @NoCSRFRequired |
| 423 | + * |
| 424 | + * @param string $type - Type is 'admin' or 'user' |
| 425 | + * @return DataDisplayResponse |
| 426 | + */ |
| 427 | + public function generateIframeToken(string $type) : DataResponse { |
| 428 | + $userId = $this->userId; |
| 429 | + if ($type === 'admin' && !$this->groupManager->isAdmin($userId)) { |
| 430 | + return new DataResponse([ |
| 431 | + 'message' => 'Permission denied' |
| 432 | + ], Http::STATUS_FORBIDDEN); |
| 433 | + } |
| 434 | + $serverHost = $this->urlGenerator->getAbsoluteURL('/'); |
| 435 | + $version = $this->capabilitiesService->getProductVersion(); |
| 436 | + |
| 437 | + $wopi = $this->wopiMapper->generateUserSettingsToken(-1, $userId, $version, $serverHost); |
| 438 | + |
| 439 | + return new DataResponse([ |
| 440 | + 'token' => $wopi->getToken(), |
| 441 | + 'token_ttl' => $wopi->getExpiry(), |
| 442 | + ]); |
| 443 | + } |
| 444 | + |
414 | 445 | /** |
415 | 446 | * @param string $name |
416 | 447 | * @return DataResponse |
|
0 commit comments