diff --git a/apps/files_external/ajax/applicable.php b/apps/files_external/ajax/applicable.php deleted file mode 100644 index ece913ffc06..00000000000 --- a/apps/files_external/ajax/applicable.php +++ /dev/null @@ -1,42 +0,0 @@ -search($pattern, $limit, $offset) as $group) { - $groups[$group->getGID()] = $group->getDisplayName(); -} - -$users = []; -foreach (Server::get(IUserManager::class)->searchDisplayName($pattern, $limit, $offset) as $user) { - $users[$user->getUID()] = $user->getDisplayName(); -} - -$results = ['groups' => $groups, 'users' => $users]; - -\OC_JSON::success($results); diff --git a/apps/files_external/ajax/oauth2.php b/apps/files_external/ajax/oauth2.php deleted file mode 100644 index d961d41ea6b..00000000000 --- a/apps/files_external/ajax/oauth2.php +++ /dev/null @@ -1,13 +0,0 @@ -getL10N('files_external'); - -// TODO: implement redirect to which storage backend requested this diff --git a/apps/files_external/appinfo/routes.php b/apps/files_external/appinfo/routes.php index 5602e1c0d11..fb695eafefe 100644 --- a/apps/files_external/appinfo/routes.php +++ b/apps/files_external/appinfo/routes.php @@ -6,13 +6,6 @@ * SPDX-License-Identifier: AGPL-3.0-only */ - -$this->create('files_external_oauth2', 'apps/files_external/ajax/oauth2.php') - ->actionInclude('files_external/ajax/oauth2.php'); - -$this->create('files_external_list_applicable', '/apps/files_external/applicable') - ->actionInclude('files_external/ajax/applicable.php'); - return [ 'resources' => [ 'global_storages' => ['url' => '/globalstorages'], @@ -20,11 +13,20 @@ return [ 'user_global_storages' => ['url' => '/userglobalstorages'], ], 'routes' => [ + [ + 'name' => 'Ajax#getApplicableEntities', + 'url' => '/ajax/applicable', + 'verb' => 'GET', + ], + [ + 'name' => 'Ajax#oauth2Callback', + 'url' => '/ajax/oauth2.php', + 'verb' => 'GET', + ], [ 'name' => 'Ajax#getSshKeys', 'url' => '/ajax/public_key.php', 'verb' => 'POST', - 'requirements' => [], ], [ 'name' => 'Ajax#saveGlobalCredentials', diff --git a/apps/files_external/lib/Controller/AjaxController.php b/apps/files_external/lib/Controller/AjaxController.php index 5cee6422530..2953ae8a056 100644 --- a/apps/files_external/lib/Controller/AjaxController.php +++ b/apps/files_external/lib/Controller/AjaxController.php @@ -17,6 +17,7 @@ use OCP\AppFramework\Http\JSONResponse; use OCP\IGroupManager; use OCP\IL10N; use OCP\IRequest; +use OCP\IUserManager; use OCP\IUserSession; class AjaxController extends Controller { @@ -35,11 +36,45 @@ class AjaxController extends Controller { private GlobalAuth $globalAuth, private IUserSession $userSession, private IGroupManager $groupManager, + private IUserManager $userManager, private IL10N $l10n, ) { parent::__construct($appName, $request); } + + /** + * Legacy endpoint for oauth2 callback + */ + #[NoAdminRequired()] + public function oauth2Callback(): JSONResponse { + return new JSONResponse(['status' => 'success']); + } + + /** + * Returns a list of users and groups that match the given pattern. + * Used for user and group picker in the admin settings. + * + * @param string $pattern The search pattern + * @param int|null $limit The maximum number of results to return + * @param int|null $offset The offset from which to start returning results + * @return JSONResponse + */ + public function getApplicableEntities(string $pattern = '', ?int $limit = null, ?int $offset = null): JSONResponse { + $groups = []; + foreach ($this->groupManager->search($pattern, $limit, $offset) as $group) { + $groups[$group->getGID()] = $group->getDisplayName(); + } + + $users = []; + foreach ($this->userManager->searchDisplayName($pattern, $limit, $offset) as $user) { + $users[$user->getUID()] = $user->getDisplayName(); + } + + $results = ['groups' => $groups, 'users' => $users]; + return new JSONResponse($results); + } + /** * @param int $keyLength * @return array diff --git a/apps/files_external/src/settings.js b/apps/files_external/src/settings.js index 574dad35a3c..08543fbc6a9 100644 --- a/apps/files_external/src/settings.js +++ b/apps/files_external/src/settings.js @@ -120,7 +120,7 @@ function initApplicableUsersMultiselect($elements, userListLimit) { dropdownCssClass: 'files-external-select2', // minimumInputLength: 1, ajax: { - url: OC.generateUrl('apps/files_external/applicable'), + url: OC.generateUrl('apps/files_external/ajax/applicable'), dataType: 'json', quietMillis: 100, data(term, page) { // page is the one-based page number tracked by Select2 @@ -131,26 +131,21 @@ function initApplicableUsersMultiselect($elements, userListLimit) { } }, results(data) { - if (data.status === 'success') { - - const results = [] - let userCount = 0 // users is an object + const results = [] + let userCount = 0 // users is an object - // add groups - $.each(data.groups, function(gid, group) { - results.push({ name: gid + '(group)', displayname: group, type: 'group' }) - }) - // add users - $.each(data.users, function(id, user) { - userCount++ - results.push({ name: id, displayname: user, type: 'user' }) - }) + // add groups + $.each(data.groups, function(gid, group) { + results.push({ name: gid + '(group)', displayname: group, type: 'group' }) + }) + // add users + $.each(data.users, function(id, user) { + userCount++ + results.push({ name: id, displayname: user, type: 'user' }) + }) - const more = (userCount >= userListLimit) || (data.groups.length >= userListLimit) - return { results, more } - } else { - // FIXME add error handling - } + const more = (userCount >= userListLimit) || (data.groups.length >= userListLimit) + return { results, more } }, }, initSelection(element, callback) { diff --git a/apps/files_external/tests/Controller/AjaxControllerTest.php b/apps/files_external/tests/Controller/AjaxControllerTest.php index b1ea7a2b1b1..144564df61d 100644 --- a/apps/files_external/tests/Controller/AjaxControllerTest.php +++ b/apps/files_external/tests/Controller/AjaxControllerTest.php @@ -15,6 +15,7 @@ use OCP\IGroupManager; use OCP\IL10N; use OCP\IRequest; use OCP\IUser; +use OCP\IUserManager; use OCP\IUserSession; use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; @@ -25,6 +26,7 @@ class AjaxControllerTest extends TestCase { private GlobalAuth&MockObject $globalAuth; private IUserSession&MockObject $userSession; private IGroupManager&MockObject $groupManager; + private IUserManager&MockObject $userManager; private IL10N&MockObject $l10n; private AjaxController $ajaxController; @@ -34,6 +36,7 @@ class AjaxControllerTest extends TestCase { $this->globalAuth = $this->createMock(GlobalAuth::class); $this->userSession = $this->createMock(IUserSession::class); $this->groupManager = $this->createMock(IGroupManager::class); + $this->userManager = $this->createMock(IUserManager::class); $this->l10n = $this->createMock(IL10N::class); $this->ajaxController = new AjaxController( @@ -43,6 +46,7 @@ class AjaxControllerTest extends TestCase { $this->globalAuth, $this->userSession, $this->groupManager, + $this->userManager, $this->l10n, ); diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 58bcde00400..032fcd92a8e 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -1339,27 +1339,6 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/tests/lib/UrlGeneratorTest.php b/tests/lib/UrlGeneratorTest.php index 4320efc4190..e8f88d8f35b 100644 --- a/tests/lib/UrlGeneratorTest.php +++ b/tests/lib/UrlGeneratorTest.php @@ -116,16 +116,16 @@ class UrlGeneratorTest extends \Test\TestCase { public static function provideDocRootAppUrlParts(): array { return [ - ['files_external', 'ajax/oauth2.php', [], '/index.php/apps/files_external/ajax/oauth2.php'], - ['files_external', 'ajax/oauth2.php', ['trut' => 'trat', 'dut' => 'dat'], '/index.php/apps/files_external/ajax/oauth2.php?trut=trat&dut=dat'], + ['user_ldap', 'ajax/wizard.php', [], '/index.php/apps/user_ldap/ajax/wizard.php'], + ['user_ldap', 'ajax/wizard.php', ['trut' => 'trat', 'dut' => 'dat'], '/index.php/apps/user_ldap/ajax/wizard.php?trut=trat&dut=dat'], ['', 'index.php', ['trut' => 'trat', 'dut' => 'dat'], '/index.php?trut=trat&dut=dat'], ]; } public static function provideSubDirAppUrlParts(): array { return [ - ['files_external', 'ajax/oauth2.php', [], '/nextcloud/index.php/apps/files_external/ajax/oauth2.php'], - ['files_external', 'ajax/oauth2.php', ['trut' => 'trat', 'dut' => 'dat'], '/nextcloud/index.php/apps/files_external/ajax/oauth2.php?trut=trat&dut=dat'], + ['user_ldap', 'ajax/wizard.php', [], '/nextcloud/index.php/apps/user_ldap/ajax/wizard.php'], + ['user_ldap', 'ajax/wizard.php', ['trut' => 'trat', 'dut' => 'dat'], '/nextcloud/index.php/apps/user_ldap/ajax/wizard.php?trut=trat&dut=dat'], ['', 'index.php', ['trut' => 'trat', 'dut' => 'dat'], '/nextcloud/index.php?trut=trat&dut=dat'], ]; }