-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathCapabilities.php
46 lines (36 loc) · 1.07 KB
/
Capabilities.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\EndToEndEncryption;
use OCP\Capabilities\ICapability;
use OCP\IUser;
use OCP\IUserSession;
class Capabilities implements ICapability {
private Config $config;
private IUserSession $userSession;
private IKeyStorage $keyStorage;
public function __construct(Config $config, IUserSession $userSession, IKeyStorage $keyStorage) {
$this->config = $config;
$this->userSession = $userSession;
$this->keyStorage = $keyStorage;
}
public function getCapabilities(): array {
$user = $this->userSession->getUser();
if (!($user instanceof IUser) || $this->config->isDisabledForUser($user)) {
return [];
}
$keysExist = $this->keyStorage->publicKeyExists($user->getUID()) &&
$this->keyStorage->privateKeyExists($user->getUID());
$capabilities = ['end-to-end-encryption' =>
[
'enabled' => true,
'api-version' => '2.0',
'keys-exist' => $keysExist,
]
];
return $capabilities;
}
}