Merge pull request #293 from arawa/fix/288/expose_app_capabilities

fix: #288 expose app capabilities
pull/294/head
Thibaut 2024-10-22 11:34:40 +02:00 committed by GitHub
commit 7233d21a85
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 0 deletions

View File

@ -56,6 +56,8 @@ class Application extends App implements IBootstrap {
$context->registerMiddleware(JoinMiddleware::class);
$context->registerMiddleware(HookMiddleware::class);
$context->registerCapability(Capabilities::class);
}
public function boot(IBootContext $context): void {

View File

@ -0,0 +1,31 @@
<?php
namespace OCA\BigBlueButton\AppInfo;
use OCA\BigBlueButton\Permission;
use OCP\App\IAppManager;
use OCP\Capabilities\ICapability;
use OCP\IUserSession;
class Capabilities implements ICapability {
public function __construct(private IUserSession $userSession, private IAppManager $appManager, private Permission $permission) {
}
public function getCapabilities(): array {
$user = $this->userSession->getUser();
if (!$user) {
return [];
}
$restriction = $this->permission->getRestriction($user->getUID());
$capabilities = array_filter($restriction->jsonSerialize(), function ($key) {
return in_array($key, ['maxRooms', 'maxParticipants', 'allowRecording']);
}, ARRAY_FILTER_USE_KEY);
return [
Application::ID => array_merge([
'appVersion' => $this->appManager->getAppVersion(Application::ID),
'isAllowedToCreateRoom' => $this->permission->isAllowedToCreateRoom($user->getUID()),
], $capabilities)
];
}
}