-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Hoang Pham <[email protected]>
- Loading branch information
Showing
24 changed files
with
2,030 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Whiteboard\Consts; | ||
|
||
final class ExAppConsts { | ||
public const APP_API_ID = 'app_api'; | ||
public const WHITEBOARD_EX_APP_ID = 'whiteboard_websocket'; | ||
public const WHITEBOARD_EX_APP_ENABLED_KEY = 'isWhiteboardWebsocketEnabled'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Whiteboard\Controller; | ||
|
||
use Exception; | ||
use OCA\AppAPI\Attribute\AppAPIAuth; | ||
use OCA\Whiteboard\Service\ConfigService; | ||
use OCA\Whiteboard\Service\ExceptionService; | ||
use OCP\AppFramework\Controller; | ||
use OCP\AppFramework\Http\Attribute\NoCSRFRequired; | ||
use OCP\AppFramework\Http\Attribute\PublicPage; | ||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\IRequest; | ||
|
||
/** | ||
* @psalm-suppress UndefinedClass | ||
* @psalm-suppress MissingDependency | ||
*/ | ||
final class ExAppController extends Controller { | ||
public function __construct( | ||
IRequest $request, | ||
private ExceptionService $exceptionService, | ||
private ConfigService $configService, | ||
) { | ||
parent::__construct('whiteboard', $request); | ||
} | ||
|
||
#[NoCSRFRequired] | ||
#[PublicPage] | ||
#[AppAPIAuth] | ||
Check failure on line 37 in lib/Controller/ExAppController.php GitHub Actions / static-psalm-analysisUndefinedAttributeClass
|
||
public function updateSettings(): DataResponse { | ||
try { | ||
$serverUrl = $this->request->getParam('serverUrl'); | ||
$secret = $this->request->getParam('secret'); | ||
|
||
if ($serverUrl !== null) { | ||
$this->configService->setCollabBackendUrl($serverUrl); | ||
} | ||
|
||
if ($secret !== null) { | ||
$this->configService->setWhiteboardSharedSecret($secret); | ||
} | ||
|
||
return new DataResponse([ | ||
'message' => 'Settings updated', | ||
]); | ||
} catch (Exception $e) { | ||
return $this->exceptionService->handleException($e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Whiteboard\Service; | ||
|
||
use OCA\AppAPI\Service\ExAppService as AppAPIService; | ||
use OCA\Whiteboard\Consts\ExAppConsts; | ||
use OCP\App\IAppManager; | ||
use OCP\AppFramework\Services\IInitialState; | ||
use Psr\Container\ContainerInterface; | ||
use Psr\Log\LoggerInterface; | ||
use Throwable; | ||
|
||
final class ExAppService { | ||
private ?AppAPIService $appAPIService = null; | ||
Check failure on line 21 in lib/Service/ExAppService.php GitHub Actions / static-psalm-analysisUndefinedClass
|
||
|
||
public function __construct( | ||
private IAppManager $appManager, | ||
private ContainerInterface $container, | ||
private IInitialState $initialState, | ||
private LoggerInterface $logger | ||
) { | ||
$this->initAppAPIService(); | ||
} | ||
|
||
private function initAppAPIService(): void { | ||
$isAppAPIEnabled = $this->isAppAPIEnabled(); | ||
|
||
if (class_exists(AppAPIService::class) && $isAppAPIEnabled) { | ||
try { | ||
$this->appAPIService = $this->container->get(AppAPIService::class); | ||
Check failure on line 37 in lib/Service/ExAppService.php GitHub Actions / static-psalm-analysisUndefinedClass
|
||
} catch (Throwable $e) { | ||
$this->logger->error('exApp', [$e->getMessage()]); | ||
} | ||
} | ||
} | ||
|
||
private function isAppAPIEnabled(): bool { | ||
return $this->appManager->isEnabledForUser(ExAppConsts::APP_API_ID); | ||
} | ||
|
||
public function isExAppEnabled(string $appId): bool { | ||
if ($this->appAPIService === null) { | ||
return false; | ||
} | ||
|
||
return $this->appAPIService->getExApp($appId)?->getEnabled() === 1; | ||
Check failure on line 53 in lib/Service/ExAppService.php GitHub Actions / static-psalm-analysisUndefinedClass
|
||
} | ||
|
||
public function isWhiteboardWebsocketEnabled(): bool { | ||
return $this->isExAppEnabled(ExAppConsts::WHITEBOARD_EX_APP_ID); | ||
} | ||
|
||
public function initFrontendState(): void { | ||
$this->initialState->provideInitialState( | ||
ExAppConsts::WHITEBOARD_EX_APP_ENABLED_KEY, | ||
$this->isWhiteboardWebsocketEnabled() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.