From a9082d3a4690d99621c5639d3f0cb9dae787b7b2 Mon Sep 17 00:00:00 2001 From: Sebastien Marinier Date: Mon, 21 Oct 2024 17:54:44 +0200 Subject: [PATCH] fix: #288 expose app capabilities Signed-off-by: Sebastien Marinier --- lib/AppInfo/Application.php | 2 ++ lib/AppInfo/Capabilities.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 lib/AppInfo/Capabilities.php diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index a9d2589..ad2042b 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -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 { diff --git a/lib/AppInfo/Capabilities.php b/lib/AppInfo/Capabilities.php new file mode 100644 index 0000000..1517557 --- /dev/null +++ b/lib/AppInfo/Capabilities.php @@ -0,0 +1,31 @@ +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) + ]; + } +}