Skip to content

Commit f05f79a

Browse files
Merge pull request #53569 from nextcloud/feat/add-user-enabled-apps-ocs
2 parents da7a902 + 6f1e441 commit f05f79a

File tree

8 files changed

+241
-2
lines changed

8 files changed

+241
-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
@@ -3573,6 +3573,78 @@
35733573
}
35743574
}
35753575
},
3576+
"/ocs/v2.php/cloud/user/apps": {
3577+
"get": {
3578+
"operationId": "users-get-enabled-apps",
3579+
"summary": "Get a list of enabled apps for the current user",
3580+
"tags": [
3581+
"users"
3582+
],
3583+
"security": [
3584+
{
3585+
"bearer_auth": []
3586+
},
3587+
{
3588+
"basic_auth": []
3589+
}
3590+
],
3591+
"parameters": [
3592+
{
3593+
"name": "OCS-APIRequest",
3594+
"in": "header",
3595+
"description": "Required to be true for the API request to pass",
3596+
"required": true,
3597+
"schema": {
3598+
"type": "boolean",
3599+
"default": true
3600+
}
3601+
}
3602+
],
3603+
"responses": {
3604+
"200": {
3605+
"description": "Enabled apps returned",
3606+
"content": {
3607+
"application/json": {
3608+
"schema": {
3609+
"type": "object",
3610+
"required": [
3611+
"ocs"
3612+
],
3613+
"properties": {
3614+
"ocs": {
3615+
"type": "object",
3616+
"required": [
3617+
"meta",
3618+
"data"
3619+
],
3620+
"properties": {
3621+
"meta": {
3622+
"$ref": "#/components/schemas/OCSMeta"
3623+
},
3624+
"data": {
3625+
"type": "object",
3626+
"required": [
3627+
"apps"
3628+
],
3629+
"properties": {
3630+
"apps": {
3631+
"type": "array",
3632+
"items": {
3633+
"type": "string"
3634+
}
3635+
}
3636+
}
3637+
}
3638+
}
3639+
}
3640+
}
3641+
}
3642+
}
3643+
}
3644+
}
3645+
}
3646+
}
3647+
},
35763648
"/ocs/v2.php/cloud/users/{userId}/{collectionName}": {
35773649
"put": {
35783650
"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
@@ -2003,6 +2003,78 @@
20032003
}
20042004
}
20052005
},
2006+
"/ocs/v2.php/cloud/user/apps": {
2007+
"get": {
2008+
"operationId": "users-get-enabled-apps",
2009+
"summary": "Get a list of enabled apps for the current user",
2010+
"tags": [
2011+
"users"
2012+
],
2013+
"security": [
2014+
{
2015+
"bearer_auth": []
2016+
},
2017+
{
2018+
"basic_auth": []
2019+
}
2020+
],
2021+
"parameters": [
2022+
{
2023+
"name": "OCS-APIRequest",
2024+
"in": "header",
2025+
"description": "Required to be true for the API request to pass",
2026+
"required": true,
2027+
"schema": {
2028+
"type": "boolean",
2029+
"default": true
2030+
}
2031+
}
2032+
],
2033+
"responses": {
2034+
"200": {
2035+
"description": "Enabled apps returned",
2036+
"content": {
2037+
"application/json": {
2038+
"schema": {
2039+
"type": "object",
2040+
"required": [
2041+
"ocs"
2042+
],
2043+
"properties": {
2044+
"ocs": {
2045+
"type": "object",
2046+
"required": [
2047+
"meta",
2048+
"data"
2049+
],
2050+
"properties": {
2051+
"meta": {
2052+
"$ref": "#/components/schemas/OCSMeta"
2053+
},
2054+
"data": {
2055+
"type": "object",
2056+
"required": [
2057+
"apps"
2058+
],
2059+
"properties": {
2060+
"apps": {
2061+
"type": "array",
2062+
"items": {
2063+
"type": "string"
2064+
}
2065+
}
2066+
}
2067+
}
2068+
}
2069+
}
2070+
}
2071+
}
2072+
}
2073+
}
2074+
}
2075+
}
2076+
}
2077+
},
20062078
"/ocs/v2.php/cloud/users/{userId}/{collectionName}": {
20072079
"put": {
20082080
"operationId": "users-edit-user-multi-value",

apps/provisioning_api/tests/Controller/UsersControllerTest.php

Lines changed: 7 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;
@@ -64,6 +65,7 @@ class UsersControllerTest extends TestCase {
6465
private IEventDispatcher&MockObject $eventDispatcher;
6566
private IRootFolder $rootFolder;
6667
private IPhoneNumberUtil $phoneNumberUtil;
68+
private IAppManager $appManager;
6769

6870
protected function setUp(): void {
6971
parent::setUp();
@@ -84,6 +86,7 @@ protected function setUp(): void {
8486
$this->knownUserService = $this->createMock(KnownUserService::class);
8587
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
8688
$this->phoneNumberUtil = new PhoneNumberUtil();
89+
$this->appManager = $this->createMock(IAppManager::class);
8790
$this->rootFolder = $this->createMock(IRootFolder::class);
8891

8992
$l10n = $this->createMock(IL10N::class);
@@ -110,6 +113,7 @@ protected function setUp(): void {
110113
$this->knownUserService,
111114
$this->eventDispatcher,
112115
$this->phoneNumberUtil,
116+
$this->appManager,
113117
])
114118
->onlyMethods(['fillStorageInfo'])
115119
->getMock();
@@ -501,6 +505,7 @@ public function testAddUserSuccessfulWithDisplayName(): void {
501505
$this->knownUserService,
502506
$this->eventDispatcher,
503507
$this->phoneNumberUtil,
508+
$this->appManager,
504509
])
505510
->onlyMethods(['editUser'])
506511
->getMock();
@@ -3796,6 +3801,7 @@ public function testGetCurrentUserLoggedIn(): void {
37963801
$this->knownUserService,
37973802
$this->eventDispatcher,
37983803
$this->phoneNumberUtil,
3804+
$this->appManager,
37993805
])
38003806
->onlyMethods(['getUserData'])
38013807
->getMock();
@@ -3887,6 +3893,7 @@ public function testGetUser(): void {
38873893
$this->knownUserService,
38883894
$this->eventDispatcher,
38893895
$this->phoneNumberUtil,
3896+
$this->appManager,
38903897
])
38913898
->onlyMethods(['getUserData'])
38923899
->getMock();

lib/private/App/AppManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function getAllAppsInAppsFolders(): array {
204204
* List all apps enabled for a user
205205
*
206206
* @param \OCP\IUser $user
207-
* @return string[]
207+
* @return list<string>
208208
*/
209209
public function getEnabledAppsForUser(IUser $user) {
210210
$apps = $this->getEnabledAppsValues();

lib/public/App/IAppManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public function getAppWebPath(string $appId): string;
184184
* List all apps enabled for a user
185185
*
186186
* @param \OCP\IUser $user
187-
* @return string[]
187+
* @return list<string>
188188
* @since 8.1.0
189189
*/
190190
public function getEnabledAppsForUser(IUser $user);

openapi.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25983,6 +25983,78 @@
2598325983
}
2598425984
}
2598525985
},
25986+
"/ocs/v2.php/cloud/user/apps": {
25987+
"get": {
25988+
"operationId": "provisioning_api-users-get-enabled-apps",
25989+
"summary": "Get a list of enabled apps for the current user",
25990+
"tags": [
25991+
"provisioning_api/users"
25992+
],
25993+
"security": [
25994+
{
25995+
"bearer_auth": []
25996+
},
25997+
{
25998+
"basic_auth": []
25999+
}
26000+
],
26001+
"parameters": [
26002+
{
26003+
"name": "OCS-APIRequest",
26004+
"in": "header",
26005+
"description": "Required to be true for the API request to pass",
26006+
"required": true,
26007+
"schema": {
26008+
"type": "boolean",
26009+
"default": true
26010+
}
26011+
}
26012+
],
26013+
"responses": {
26014+
"200": {
26015+
"description": "Enabled apps returned",
26016+
"content": {
26017+
"application/json": {
26018+
"schema": {
26019+
"type": "object",
26020+
"required": [
26021+
"ocs"
26022+
],
26023+
"properties": {
26024+
"ocs": {
26025+
"type": "object",
26026+
"required": [
26027+
"meta",
26028+
"data"
26029+
],
26030+
"properties": {
26031+
"meta": {
26032+
"$ref": "#/components/schemas/OCSMeta"
26033+
},
26034+
"data": {
26035+
"type": "object",
26036+
"required": [
26037+
"apps"
26038+
],
26039+
"properties": {
26040+
"apps": {
26041+
"type": "array",
26042+
"items": {
26043+
"type": "string"
26044+
}
26045+
}
26046+
}
26047+
}
26048+
}
26049+
}
26050+
}
26051+
}
26052+
}
26053+
}
26054+
}
26055+
}
26056+
}
26057+
},
2598626058
"/ocs/v2.php/cloud/users/{userId}/{collectionName}": {
2598726059
"put": {
2598826060
"operationId": "provisioning_api-users-edit-user-multi-value",

0 commit comments

Comments
 (0)