Merge pull request #53599 from nextcloud/backport/53569/stable31

This commit is contained in:
Kate 2025-06-20 11:22:47 +02:00 committed by GitHub
commit d02223b6cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 170 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

@ -3059,6 +3059,78 @@
}
}
},
"/ocs/v2.php/cloud/user/apps": {
"get": {
"operationId": "users-get-enabled-apps",
"summary": "Get a list of enabled apps for the current user",
"tags": [
"users"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"parameters": [
{
"name": "OCS-APIRequest",
"in": "header",
"description": "Required to be true for the API request to pass",
"required": true,
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
"200": {
"description": "Enabled apps returned",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "object",
"required": [
"apps"
],
"properties": {
"apps": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
}
},
"/ocs/v2.php/cloud/users/{userId}/{collectionName}": {
"put": {
"operationId": "users-edit-user-multi-value",

View file

@ -1996,6 +1996,78 @@
}
}
},
"/ocs/v2.php/cloud/user/apps": {
"get": {
"operationId": "users-get-enabled-apps",
"summary": "Get a list of enabled apps for the current user",
"tags": [
"users"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"parameters": [
{
"name": "OCS-APIRequest",
"in": "header",
"description": "Required to be true for the API request to pass",
"required": true,
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
"200": {
"description": "Enabled apps returned",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "object",
"required": [
"apps"
],
"properties": {
"apps": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
}
},
"/ocs/v2.php/cloud/users/{userId}/{collectionName}": {
"put": {
"operationId": "users-edit-user-multi-value",

View file

@ -20,6 +20,7 @@ use OCP\Accounts\IAccount;
use OCP\Accounts\IAccountManager;
use OCP\Accounts\IAccountProperty;
use OCP\Accounts\IAccountPropertyCollection;
use OCP\App\IAppManager;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSException;
use OCP\EventDispatcher\IEventDispatcher;
@ -81,6 +82,8 @@ class UsersControllerTest extends TestCase {
private IRootFolder $rootFolder;
/** @var IPhoneNumberUtil */
private $phoneNumberUtil;
/** @var IAppManager|MockObject */
protected $appManager;
protected function setUp(): void {
parent::setUp();
@ -101,6 +104,7 @@ class UsersControllerTest extends TestCase {
$this->knownUserService = $this->createMock(KnownUserService::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->phoneNumberUtil = new PhoneNumberUtil();
$this->appManager = $this->createMock(IAppManager::class);
$this->rootFolder = $this->createMock(IRootFolder::class);
$l10n = $this->createMock(IL10N::class);
@ -127,6 +131,7 @@ class UsersControllerTest extends TestCase {
$this->knownUserService,
$this->eventDispatcher,
$this->phoneNumberUtil,
$this->appManager,
])
->onlyMethods(['fillStorageInfo'])
->getMock();
@ -522,6 +527,7 @@ class UsersControllerTest extends TestCase {
$this->knownUserService,
$this->eventDispatcher,
$this->phoneNumberUtil,
$this->appManager,
])
->onlyMethods(['editUser'])
->getMock();
@ -3825,6 +3831,7 @@ class UsersControllerTest extends TestCase {
$this->knownUserService,
$this->eventDispatcher,
$this->phoneNumberUtil,
$this->appManager,
])
->onlyMethods(['getUserData'])
->getMock();
@ -3916,6 +3923,7 @@ class UsersControllerTest extends TestCase {
$this->knownUserService,
$this->eventDispatcher,
$this->phoneNumberUtil,
$this->appManager,
])
->onlyMethods(['getUserData'])
->getMock();

View file

@ -192,7 +192,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->getInstalledAppsValues();

View file

@ -168,7 +168,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);