Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(core): provide capabilities of the current user
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Aug 18, 2025
commit c40350d2e46a1e720da161b4c415871ab8c4ac19
2 changes: 2 additions & 0 deletions core/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public function register(IRegistrationContext $context): void {

// config lexicon
$context->registerConfigLexicon(ConfigLexicon::class);

$context->registerCapability(Capabilities::class);
}

public function boot(IBootContext $context): void {
Expand Down
49 changes: 49 additions & 0 deletions core/AppInfo/Capabilities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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;
use OCP\IDateTimeZone;
use OCP\IGroupManager;
use OCP\IUserSession;

class Capabilities implements ICapability {

public function __construct(
private IUserSession $session,
private IUserConfig $userConfig,
private IGroupManager $groupManager,
) {
}

/**
* Return the core capabilities
*
* @return array{core: array{'user'?: array{language: string, locale: string, timezone: string} } }
*/
public function getCapabilities(): array {
$capabilities = [];

$user = $this->session->getUser();
if ($user !== null) {
$timezone = \OCP\Server::get(IDateTimeZone::class)->getTimeZone();

$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(),
];
}

return [
'core' => $capabilities,
];
}
}
7 changes: 6 additions & 1 deletion core/AppInfo/ConfigLexicon.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class ConfigLexicon implements ILexicon {
public const SHARE_LINK_PASSWORD_ENFORCED = 'shareapi_enforce_links_password';

public const USER_LANGUAGE = 'lang';
public const USER_LOCALE = 'locale';
public const USER_TIMEZONE = 'timezone';

public const LASTCRON_TIMESTAMP = 'lastcron';

public function getStrictness(): Strictness {
Expand Down Expand Up @@ -68,7 +71,9 @@ public function getAppConfigs(): array {

public function getUserConfigs(): array {
return [
new Entry(self::USER_LANGUAGE, ValueType::STRING, null, 'language'),
new Entry(self::USER_LANGUAGE, ValueType::STRING, definition: 'language'),
new Entry(self::USER_LOCALE, ValueType::STRING, definition: 'locale'),
new Entry(self::USER_TIMEZONE, ValueType::STRING, definition: 'timezone'),
];
}
}
23 changes: 22 additions & 1 deletion core/openapi-administration.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"webdav-root",
"reference-api",
"reference-regex",
"mod-rewrite-working"
"mod-rewrite-working",
"user"
],
"properties": {
"pollinterval": {
Expand All @@ -51,6 +52,26 @@
},
"mod-rewrite-working": {
"type": "boolean"
},
"user": {
"type": "object",
"nullable": true,
"required": [
"language",
"locale",
"timezone"
],
"properties": {
"language": {
"type": "string"
},
"locale": {
"type": "string"
},
"timezone": {
"type": "string"
}
}
}
}
}
Expand Down
23 changes: 22 additions & 1 deletion core/openapi-ex_app.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"webdav-root",
"reference-api",
"reference-regex",
"mod-rewrite-working"
"mod-rewrite-working",
"user"
],
"properties": {
"pollinterval": {
Expand All @@ -51,6 +52,26 @@
},
"mod-rewrite-working": {
"type": "boolean"
},
"user": {
"type": "object",
"nullable": true,
"required": [
"language",
"locale",
"timezone"
],
"properties": {
"language": {
"type": "string"
},
"locale": {
"type": "string"
},
"timezone": {
"type": "string"
}
}
}
}
}
Expand Down
23 changes: 22 additions & 1 deletion core/openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
"webdav-root",
"reference-api",
"reference-regex",
"mod-rewrite-working"
"mod-rewrite-working",
"user"
],
"properties": {
"pollinterval": {
Expand All @@ -117,6 +118,26 @@
},
"mod-rewrite-working": {
"type": "boolean"
},
"user": {
"type": "object",
"nullable": true,
"required": [
"language",
"locale",
"timezone"
],
"properties": {
"language": {
"type": "string"
},
"locale": {
"type": "string"
},
"timezone": {
"type": "string"
}
}
}
}
}
Expand Down
23 changes: 22 additions & 1 deletion core/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@
"webdav-root",
"reference-api",
"reference-regex",
"mod-rewrite-working"
"mod-rewrite-working",
"user"
],
"properties": {
"pollinterval": {
Expand All @@ -117,6 +118,26 @@
},
"mod-rewrite-working": {
"type": "boolean"
},
"user": {
"type": "object",
"nullable": true,
"required": [
"language",
"locale",
"timezone"
],
"properties": {
"language": {
"type": "string"
},
"locale": {
"type": "string"
},
"timezone": {
"type": "string"
}
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,7 @@
'OC\\Contacts\\ContactsMenu\\Providers\\ProfileProvider' => $baseDir . '/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php',
'OC\\ContextChat\\ContentManager' => $baseDir . '/lib/private/ContextChat/ContentManager.php',
'OC\\Core\\AppInfo\\Application' => $baseDir . '/core/AppInfo/Application.php',
'OC\\Core\\AppInfo\\Capabilities' => $baseDir . '/core/AppInfo/Capabilities.php',
'OC\\Core\\AppInfo\\ConfigLexicon' => $baseDir . '/core/AppInfo/ConfigLexicon.php',
'OC\\Core\\BackgroundJobs\\BackgroundCleanupUpdaterBackupsJob' => $baseDir . '/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php',
'OC\\Core\\BackgroundJobs\\CheckForUserCertificates' => $baseDir . '/core/BackgroundJobs/CheckForUserCertificates.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Contacts\\ContactsMenu\\Providers\\ProfileProvider' => __DIR__ . '/../../..' . '/lib/private/Contacts/ContactsMenu/Providers/ProfileProvider.php',
'OC\\ContextChat\\ContentManager' => __DIR__ . '/../../..' . '/lib/private/ContextChat/ContentManager.php',
'OC\\Core\\AppInfo\\Application' => __DIR__ . '/../../..' . '/core/AppInfo/Application.php',
'OC\\Core\\AppInfo\\Capabilities' => __DIR__ . '/../../..' . '/core/AppInfo/Capabilities.php',
'OC\\Core\\AppInfo\\ConfigLexicon' => __DIR__ . '/../../..' . '/core/AppInfo/ConfigLexicon.php',
'OC\\Core\\BackgroundJobs\\BackgroundCleanupUpdaterBackupsJob' => __DIR__ . '/../../..' . '/core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php',
'OC\\Core\\BackgroundJobs\\CheckForUserCertificates' => __DIR__ . '/../../..' . '/core/BackgroundJobs/CheckForUserCertificates.php',
Expand Down
23 changes: 22 additions & 1 deletion openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@
"webdav-root",
"reference-api",
"reference-regex",
"mod-rewrite-working"
"mod-rewrite-working",
"user"
],
"properties": {
"pollinterval": {
Expand All @@ -155,6 +156,26 @@
},
"mod-rewrite-working": {
"type": "boolean"
},
"user": {
"type": "object",
"nullable": true,
"required": [
"language",
"locale",
"timezone"
],
"properties": {
"language": {
"type": "string"
},
"locale": {
"type": "string"
},
"timezone": {
"type": "string"
}
}
}
}
}
Expand Down