Skip to content

Commit d02223b

Browse files
Merge pull request #53599 from nextcloud/backport/53569/stable31
2 parents 60b4a3d + 237e01c commit d02223b

File tree

7 files changed

+170
-2
lines changed

7 files changed

+170
-2
lines changed

apps/provisioning_api/appinfo/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
['root' => '/cloud', 'name' => 'Users#getCurrentUser', 'url' => '/user', 'verb' => 'GET'],
3636
['root' => '/cloud', 'name' => 'Users#getEditableFields', 'url' => '/user/fields', 'verb' => 'GET'],
3737
['root' => '/cloud', 'name' => 'Users#getEditableFieldsForUser', 'url' => '/user/fields/{userId}', 'verb' => 'GET'],
38+
['root' => '/cloud', 'name' => 'Users#getEnabledApps', 'url' => '/user/apps', 'verb' => 'GET'],
3839
['root' => '/cloud', 'name' => 'Users#editUser', 'url' => '/users/{userId}', 'verb' => 'PUT'],
3940
['root' => '/cloud', 'name' => 'Users#editUserMultiValue', 'url' => '/users/{userId}/{collectionName}', 'verb' => 'PUT', 'requirements' => ['collectionName' => '^(?!enable$|disable$)[a-zA-Z0-9_]*$']],
4041
['root' => '/cloud', 'name' => 'Users#wipeUserDevices', 'url' => '/users/{userId}/wipe', 'verb' => 'POST'],

apps/provisioning_api/lib/Controller/UsersController.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use OCP\Accounts\IAccountManager;
2222
use OCP\Accounts\IAccountProperty;
2323
use OCP\Accounts\PropertyDoesNotExistException;
24+
use OCP\App\IAppManager;
2425
use OCP\AppFramework\Http;
2526
use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting;
2627
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
@@ -79,6 +80,7 @@ public function __construct(
7980
private KnownUserService $knownUserService,
8081
private IEventDispatcher $eventDispatcher,
8182
private IPhoneNumberUtil $phoneNumberUtil,
83+
private IAppManager $appManager,
8284
) {
8385
parent::__construct(
8486
$appName,
@@ -709,6 +711,19 @@ public function getEditableFields(): DataResponse {
709711
return $this->getEditableFieldsForUser($currentLoggedInUser->getUID());
710712
}
711713

714+
/**
715+
* Get a list of enabled apps for the current user
716+
*
717+
* @return DataResponse<Http::STATUS_OK, array{apps: list<string>}, array{}>
718+
*
719+
* 200: Enabled apps returned
720+
*/
721+
#[NoAdminRequired]
722+
public function getEnabledApps(): DataResponse {
723+
$currentLoggedInUser = $this->userSession->getUser();
724+
return new DataResponse(['apps' => $this->appManager->getEnabledAppsForUser($currentLoggedInUser)]);
725+
}
726+
712727
/**
713728
* @NoSubAdminRequired
714729
*

apps/provisioning_api/openapi-full.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3059,6 +3059,78 @@
30593059
}
30603060
}
30613061
},
3062+
"/ocs/v2.php/cloud/user/apps": {
3063+
"get": {
3064+
"operationId": "users-get-enabled-apps",
3065+
"summary": "Get a list of enabled apps for the current user",
3066+
"tags": [
3067+
"users"
3068+
],
3069+
"security": [
3070+
{
3071+
"bearer_auth": []
3072+
},
3073+
{
3074+
"basic_auth": []
3075+
}
3076+
],
3077+
"parameters": [
3078+
{
3079+
"name": "OCS-APIRequest",
3080+
"in": "header",
3081+
"description": "Required to be true for the API request to pass",
3082+
"required": true,
3083+
"schema": {
3084+
"type": "boolean",
3085+
"default": true
3086+
}
3087+
}
3088+
],
3089+
"responses": {
3090+
"200": {
3091+
"description": "Enabled apps returned",
3092+
"content": {
3093+
"application/json": {
3094+
"schema": {
3095+
"type": "object",
3096+
"required": [
3097+
"ocs"
3098+
],
3099+
"properties": {
3100+
"ocs": {
3101+
"type": "object",
3102+
"required": [
3103+
"meta",
3104+
"data"
3105+
],
3106+
"properties": {
3107+
"meta": {
3108+
"$ref": "#/components/schemas/OCSMeta"
3109+
},
3110+
"data": {
3111+
"type": "object",
3112+
"required": [
3113+
"apps"
3114+
],
3115+
"properties": {
3116+
"apps": {
3117+
"type": "array",
3118+
"items": {
3119+
"type": "string"
3120+
}
3121+
}
3122+
}
3123+
}
3124+
}
3125+
}
3126+
}
3127+
}
3128+
}
3129+
}
3130+
}
3131+
}
3132+
}
3133+
},
30623134
"/ocs/v2.php/cloud/users/{userId}/{collectionName}": {
30633135
"put": {
30643136
"operationId": "users-edit-user-multi-value",

apps/provisioning_api/openapi.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,6 +1996,78 @@
19961996
}
19971997
}
19981998
},
1999+
"/ocs/v2.php/cloud/user/apps": {
2000+
"get": {
2001+
"operationId": "users-get-enabled-apps",
2002+
"summary": "Get a list of enabled apps for the current user",
2003+
"tags": [
2004+
"users"
2005+
],
2006+
"security": [
2007+
{
2008+
"bearer_auth": []
2009+
},
2010+
{
2011+
"basic_auth": []
2012+
}
2013+
],
2014+
"parameters": [
2015+
{
2016+
"name": "OCS-APIRequest",
2017+
"in": "header",
2018+
"description": "Required to be true for the API request to pass",
2019+
"required": true,
2020+
"schema": {
2021+
"type": "boolean",
2022+
"default": true
2023+
}
2024+
}
2025+
],
2026+
"responses": {
2027+
"200": {
2028+
"description": "Enabled apps returned",
2029+
"content": {
2030+
"application/json": {
2031+
"schema": {
2032+
"type": "object",
2033+
"required": [
2034+
"ocs"
2035+
],
2036+
"properties": {
2037+
"ocs": {
2038+
"type": "object",
2039+
"required": [
2040+
"meta",
2041+
"data"
2042+
],
2043+
"properties": {
2044+
"meta": {
2045+
"$ref": "#/components/schemas/OCSMeta"
2046+
},
2047+
"data": {
2048+
"type": "object",
2049+
"required": [
2050+
"apps"
2051+
],
2052+
"properties": {
2053+
"apps": {
2054+
"type": "array",
2055+
"items": {
2056+
"type": "string"
2057+
}
2058+
}
2059+
}
2060+
}
2061+
}
2062+
}
2063+
}
2064+
}
2065+
}
2066+
}
2067+
}
2068+
}
2069+
}
2070+
},
19992071
"/ocs/v2.php/cloud/users/{userId}/{collectionName}": {
20002072
"put": {
20012073
"operationId": "users-edit-user-multi-value",

apps/provisioning_api/tests/Controller/UsersControllerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use OCP\Accounts\IAccountManager;
2121
use OCP\Accounts\IAccountProperty;
2222
use OCP\Accounts\IAccountPropertyCollection;
23+
use OCP\App\IAppManager;
2324
use OCP\AppFramework\Http\DataResponse;
2425
use OCP\AppFramework\OCS\OCSException;
2526
use OCP\EventDispatcher\IEventDispatcher;
@@ -81,6 +82,8 @@ class UsersControllerTest extends TestCase {
8182
private IRootFolder $rootFolder;
8283
/** @var IPhoneNumberUtil */
8384
private $phoneNumberUtil;
85+
/** @var IAppManager|MockObject */
86+
protected $appManager;
8487

8588
protected function setUp(): void {
8689
parent::setUp();
@@ -101,6 +104,7 @@ protected function setUp(): void {
101104
$this->knownUserService = $this->createMock(KnownUserService::class);
102105
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
103106
$this->phoneNumberUtil = new PhoneNumberUtil();
107+
$this->appManager = $this->createMock(IAppManager::class);
104108
$this->rootFolder = $this->createMock(IRootFolder::class);
105109

106110
$l10n = $this->createMock(IL10N::class);
@@ -127,6 +131,7 @@ protected function setUp(): void {
127131
$this->knownUserService,
128132
$this->eventDispatcher,
129133
$this->phoneNumberUtil,
134+
$this->appManager,
130135
])
131136
->onlyMethods(['fillStorageInfo'])
132137
->getMock();
@@ -522,6 +527,7 @@ public function testAddUserSuccessfulWithDisplayName(): void {
522527
$this->knownUserService,
523528
$this->eventDispatcher,
524529
$this->phoneNumberUtil,
530+
$this->appManager,
525531
])
526532
->onlyMethods(['editUser'])
527533
->getMock();
@@ -3825,6 +3831,7 @@ public function testGetCurrentUserLoggedIn(): void {
38253831
$this->knownUserService,
38263832
$this->eventDispatcher,
38273833
$this->phoneNumberUtil,
3834+
$this->appManager,
38283835
])
38293836
->onlyMethods(['getUserData'])
38303837
->getMock();
@@ -3916,6 +3923,7 @@ public function testGetUser(): void {
39163923
$this->knownUserService,
39173924
$this->eventDispatcher,
39183925
$this->phoneNumberUtil,
3926+
$this->appManager,
39193927
])
39203928
->onlyMethods(['getUserData'])
39213929
->getMock();

lib/private/App/AppManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function getAllAppsInAppsFolders(): array {
192192
* List all apps enabled for a user
193193
*
194194
* @param \OCP\IUser $user
195-
* @return string[]
195+
* @return list<string>
196196
*/
197197
public function getEnabledAppsForUser(IUser $user) {
198198
$apps = $this->getInstalledAppsValues();

lib/public/App/IAppManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function getAppWebPath(string $appId): string;
168168
* List all apps enabled for a user
169169
*
170170
* @param \OCP\IUser $user
171-
* @return string[]
171+
* @return list<string>
172172
* @since 8.1.0
173173
*/
174174
public function getEnabledAppsForUser(IUser $user);

0 commit comments

Comments
 (0)