2025-08-16 17:43:14 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
/**
|
|
|
|
|
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace OC\Core\AppInfo;
|
|
|
|
|
|
|
|
|
|
use OCP\Capabilities\ICapability;
|
|
|
|
|
use OCP\Config\IUserConfig;
|
2025-11-28 08:28:24 -05:00
|
|
|
use OCP\IConfig;
|
2025-08-16 17:43:14 -04:00
|
|
|
use OCP\IDateTimeZone;
|
|
|
|
|
use OCP\IUserSession;
|
2025-08-26 10:27:26 -04:00
|
|
|
use OCP\Server;
|
2025-08-16 17:43:14 -04:00
|
|
|
|
|
|
|
|
class Capabilities implements ICapability {
|
|
|
|
|
|
|
|
|
|
public function __construct(
|
2025-11-28 08:28:24 -05:00
|
|
|
private IUserSession $userSession,
|
2025-08-16 17:43:14 -04:00
|
|
|
private IUserConfig $userConfig,
|
2025-11-28 08:28:24 -05:00
|
|
|
private IConfig $serverConfig,
|
2025-08-16 17:43:14 -04:00
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the core capabilities
|
|
|
|
|
*
|
2026-01-09 12:02:21 -05:00
|
|
|
* @return array{core: array{'user'?: array{language: string, locale: string, timezone: string}, 'can-create-app-token'?: bool } }
|
2025-08-16 17:43:14 -04:00
|
|
|
*/
|
|
|
|
|
public function getCapabilities(): array {
|
|
|
|
|
$capabilities = [];
|
|
|
|
|
|
2025-11-28 08:28:24 -05:00
|
|
|
$user = $this->userSession->getUser();
|
2025-08-16 17:43:14 -04:00
|
|
|
if ($user !== null) {
|
2025-08-26 10:27:26 -04:00
|
|
|
$timezone = Server::get(IDateTimeZone::class)->getTimeZone();
|
2025-08-16 17:43:14 -04:00
|
|
|
|
|
|
|
|
$capabilities['user'] = [
|
|
|
|
|
'language' => $this->userConfig->getValueString($user->getUID(), Application::APP_ID, ConfigLexicon::USER_LANGUAGE),
|
|
|
|
|
'locale' => $this->userConfig->getValueString($user->getUID(), Application::APP_ID, ConfigLexicon::USER_LOCALE),
|
|
|
|
|
'timezone' => $timezone->getName(),
|
|
|
|
|
];
|
2025-11-28 08:28:24 -05:00
|
|
|
|
|
|
|
|
$capabilities['can-create-app-token'] = $this->userSession->getImpersonatingUserID() === null
|
|
|
|
|
&& $this->serverConfig->getSystemValueBool('auth_can_create_app_token', true);
|
2025-08-16 17:43:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'core' => $capabilities,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|