Skip to content

Commit

Permalink
feat(App): Add Capabilities
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
tobiasKaminsky authored and provokateurin committed Jan 7, 2025
1 parent 3ee463a commit abcd329
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace OCA\Recommendations\AppInfo;

use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Recommendations\Capabilities;
use OCA\Recommendations\Dashboard\RecommendationWidget;
use OCA\Recommendations\Listeners\FilesLoadAdditionalScriptsListener;
use OCP\AppFramework\App;
Expand All @@ -27,6 +28,7 @@ public function __construct(array $urlParams = []) {
public function register(IRegistrationContext $context): void {
$context->registerEventListener(LoadAdditionalScriptsEvent::class, FilesLoadAdditionalScriptsListener::class);
$context->registerDashboardWidget(RecommendationWidget::class);
$context->registerCapability(Capabilities::class);
}

public function boot(IBootContext $context): void {
Expand Down
45 changes: 45 additions & 0 deletions lib/Capabilities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Recommendations;

use OCA\Recommendations\AppInfo\Application;
use OCP\Capabilities\ICapability;
use OCP\IConfig;
use OCP\IUserSession;

class Capabilities implements ICapability {
/** @psalm-suppress PossiblyUnusedMethod */
public function __construct(
private IUserSession $userSession,
private IConfig $config,
) {
}

/**
* @return array{
* recommendations?: array{
* enabled: bool,
* },
* }
*/
public function getCapabilities(): array {
$user = $this->userSession->getUser();
if ($user === null) {
return [];
}

$enabled = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'enabled', 'true') === 'true';
return [
'recommendations' => [
'enabled' => $enabled,
],
];
}
}
16 changes: 16 additions & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@
}
},
"schemas": {
"Capabilities": {
"type": "object",
"properties": {
"recommendations": {
"type": "object",
"required": [
"enabled"
],
"properties": {
"enabled": {
"type": "boolean"
}
}
}
}
},
"OCSMeta": {
"type": "object",
"required": [
Expand Down

0 comments on commit abcd329

Please sign in to comment.