Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions apps/files_external/ajax/applicable.php

This file was deleted.

13 changes: 0 additions & 13 deletions apps/files_external/ajax/oauth2.php

This file was deleted.

18 changes: 10 additions & 8 deletions apps/files_external/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,27 @@
* 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'],
'user_storages' => ['url' => '/userstorages'],
'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',
Expand Down
35 changes: 35 additions & 0 deletions apps/files_external/lib/Controller/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IUserSession;

class AjaxController extends Controller {
Expand All @@ -35,11 +36,45 @@ public function __construct(
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
Expand Down
33 changes: 14 additions & 19 deletions apps/files_external/src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions apps/files_external/tests/Controller/AjaxControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use OCP\IL10N;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
Expand All @@ -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;

Expand All @@ -34,6 +36,7 @@ protected function setUp(): void {
$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(
Expand All @@ -43,6 +46,7 @@ protected function setUp(): void {
$this->globalAuth,
$this->userSession,
$this->groupManager,
$this->userManager,
$this->l10n,
);

Expand Down
21 changes: 0 additions & 21 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1339,27 +1339,6 @@
<code><![CDATA[isReadyForUser]]></code>
</UndefinedInterfaceMethod>
</file>
<file src="apps/files_external/ajax/applicable.php">
<DeprecatedMethod>
<code><![CDATA[\OC_JSON::callCheck()]]></code>
<code><![CDATA[\OC_JSON::checkAdminUser()]]></code>
<code><![CDATA[\OC_JSON::checkAppEnabled('files_external')]]></code>
<code><![CDATA[\OC_JSON::success($results)]]></code>
</DeprecatedMethod>
</file>
<file src="apps/files_external/ajax/oauth2.php">
<DeprecatedMethod>
<code><![CDATA[\OC_JSON::callCheck()]]></code>
<code><![CDATA[\OC_JSON::checkAppEnabled('files_external')]]></code>
<code><![CDATA[\OC_JSON::checkLoggedIn()]]></code>
<code><![CDATA[getL10N]]></code>
</DeprecatedMethod>
</file>
<file src="apps/files_external/appinfo/routes.php">
<InvalidScope>
<code><![CDATA[$this]]></code>
</InvalidScope>
</file>
<file src="apps/files_external/lib/Command/Notify.php">
<DeprecatedClass>
<code><![CDATA[\OC_Util::normalizeUnicode($parent)]]></code>
Expand Down
4 changes: 2 additions & 2 deletions dist/files_external-settings.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files_external-settings.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions tests/lib/UrlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,16 @@ public static function provideRoutes(): array {

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'],
];
}
Expand Down
Loading