feat: add ocs route to get apps enabled for current user

Signed-off-by: Jana Peper <jana.peper@nextcloud.com>
This commit is contained in:
Jana Peper 2025-06-18 16:03:20 +02:00
parent 98871fe474
commit 50c9852e24
No known key found for this signature in database
GPG key ID: 21BB61ACAFC2C89E
4 changed files with 18 additions and 2 deletions

View file

@ -35,6 +35,7 @@ return [
['root' => '/cloud', 'name' => 'Users#getCurrentUser', 'url' => '/user', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Users#getEditableFields', 'url' => '/user/fields', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Users#getEditableFieldsForUser', 'url' => '/user/fields/{userId}', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Users#getEnabledApps', 'url' => '/user/apps', 'verb' => 'GET'],
['root' => '/cloud', 'name' => 'Users#editUser', 'url' => '/users/{userId}', 'verb' => 'PUT'],
['root' => '/cloud', 'name' => 'Users#editUserMultiValue', 'url' => '/users/{userId}/{collectionName}', 'verb' => 'PUT', 'requirements' => ['collectionName' => '^(?!enable$|disable$)[a-zA-Z0-9_]*$']],
['root' => '/cloud', 'name' => 'Users#wipeUserDevices', 'url' => '/users/{userId}/wipe', 'verb' => 'POST'],

View file

@ -21,6 +21,7 @@ use OCA\Settings\Settings\Admin\Users;
use OCP\Accounts\IAccountManager;
use OCP\Accounts\IAccountProperty;
use OCP\Accounts\PropertyDoesNotExistException;
use OCP\App\IAppManager;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
@ -79,6 +80,7 @@ class UsersController extends AUserDataOCSController {
private KnownUserService $knownUserService,
private IEventDispatcher $eventDispatcher,
private IPhoneNumberUtil $phoneNumberUtil,
private IAppManager $appManager,
) {
parent::__construct(
$appName,
@ -709,6 +711,19 @@ class UsersController extends AUserDataOCSController {
return $this->getEditableFieldsForUser($currentLoggedInUser->getUID());
}
/**
* Get a list of enabled apps for the current user
*
* @return DataResponse<Http::STATUS_OK, array{apps: list<string>}, array{}>
*
* 200: Enabled apps returned
*/
#[NoAdminRequired]
public function getEnabledApps(): DataResponse {
$currentLoggedInUser = $this->userSession->getUser();
return new DataResponse(['apps' => $this->appManager->getEnabledAppsForUser($currentLoggedInUser)]);
}
/**
* @NoSubAdminRequired
*

View file

@ -204,7 +204,7 @@ class AppManager implements IAppManager {
* List all apps enabled for a user
*
* @param \OCP\IUser $user
* @return string[]
* @return list<string>
*/
public function getEnabledAppsForUser(IUser $user) {
$apps = $this->getEnabledAppsValues();

View file

@ -184,7 +184,7 @@ interface IAppManager {
* List all apps enabled for a user
*
* @param \OCP\IUser $user
* @return string[]
* @return list<string>
* @since 8.1.0
*/
public function getEnabledAppsForUser(IUser $user);