Skip to content

Commit 3093ecc

Browse files
tobiasKaminskyprovokateurin
authored andcommitted
feat(App): Add Capabilities
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent 5f2d62b commit 3093ecc

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace OCA\Recommendations\AppInfo;
1111

1212
use OCA\Files\Event\LoadAdditionalScriptsEvent;
13+
use OCA\Recommendations\Capabilities;
1314
use OCA\Recommendations\Dashboard\RecommendationWidget;
1415
use OCA\Recommendations\Listeners\FilesLoadAdditionalScriptsListener;
1516
use OCP\AppFramework\App;
@@ -27,6 +28,7 @@ public function __construct(array $urlParams = []) {
2728
public function register(IRegistrationContext $context): void {
2829
$context->registerEventListener(LoadAdditionalScriptsEvent::class, FilesLoadAdditionalScriptsListener::class);
2930
$context->registerDashboardWidget(RecommendationWidget::class);
31+
$context->registerCapability(Capabilities::class);
3032
}
3133

3234
public function boot(IBootContext $context): void {

lib/Capabilities.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Recommendations;
11+
12+
use OCA\Recommendations\AppInfo\Application;
13+
use OCP\Capabilities\ICapability;
14+
use OCP\IConfig;
15+
use OCP\IUserSession;
16+
17+
class Capabilities implements ICapability {
18+
/** @psalm-suppress PossiblyUnusedMethod */
19+
public function __construct(
20+
private IUserSession $userSession,
21+
private IConfig $config,
22+
) {
23+
}
24+
25+
/**
26+
* @return array{
27+
* recommendations?: array{
28+
* enabled: bool,
29+
* },
30+
* }
31+
*/
32+
public function getCapabilities(): array {
33+
$user = $this->userSession->getUser();
34+
if ($user === null) {
35+
return [];
36+
}
37+
38+
$enabled = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'enabled', 'true') === 'true';
39+
return [
40+
'recommendations' => [
41+
'enabled' => $enabled,
42+
],
43+
];
44+
}
45+
}

openapi.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@
2020
}
2121
},
2222
"schemas": {
23+
"Capabilities": {
24+
"type": "object",
25+
"properties": {
26+
"recommendations": {
27+
"type": "object",
28+
"required": [
29+
"enabled"
30+
],
31+
"properties": {
32+
"enabled": {
33+
"type": "boolean"
34+
}
35+
}
36+
}
37+
}
38+
},
2339
"OCSMeta": {
2440
"type": "object",
2541
"required": [

0 commit comments

Comments
 (0)