-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add capability telling if the assistant is enabled for the current user
Signed-off-by: Julien Veyssier <[email protected]>
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\TpAssistant; | ||
|
||
use OCA\TpAssistant\AppInfo\Application; | ||
use OCP\App\IAppManager; | ||
use OCP\Capabilities\IPublicCapability; | ||
use OCP\IConfig; | ||
|
||
class Capabilities implements IPublicCapability { | ||
|
||
public function __construct( | ||
private IAppManager $appManager, | ||
private IConfig $config, | ||
private ?string $userId, | ||
) { | ||
} | ||
|
||
/** | ||
* @return array<string, array<string, bool|string>> | ||
*/ | ||
public function getCapabilities(): array { | ||
$appVersion = $this->appManager->getAppVersion(Application::APP_ID); | ||
$capability = [ | ||
Application::APP_ID => [ | ||
'version' => $appVersion, | ||
], | ||
]; | ||
if ($this->userId !== null) { | ||
$adminAssistantEnabled = $this->config->getAppValue(Application::APP_ID, 'assistant_enabled', '1') === '1'; | ||
$userAssistantEnabled = $this->config->getUserValue($this->userId, Application::APP_ID, 'assistant_enabled', '1') === '1'; | ||
$assistantEnabled = $adminAssistantEnabled && $userAssistantEnabled; | ||
$capability[Application::APP_ID]['enabled'] = $assistantEnabled; | ||
} | ||
return $capability; | ||
} | ||
} |