Skip to content

Commit b9b29d4

Browse files
tanyakaartonge
authored andcommitted
feat(files_external): allow delegated admins to search applicable users/groups
Signed-off-by: Tatjana Kaschperko Lindt <kaschperko-lindt@strato.de>
1 parent bfdce55 commit b9b29d4

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

apps/files_external/ajax/applicable.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,21 @@
1212
\OC_JSON::checkAppEnabled('files_external');
1313
\OC_JSON::callCheck();
1414

15-
\OC_JSON::checkAdminUser();
15+
// Replaces \OC_JSON::checkAdminUser() to also allow delegated admins access.
16+
$currentUser = \OC::$server->getUserSession()->getUser();
17+
if ($currentUser === null) {
18+
\OC_JSON::error(['message' => 'Not logged in']);
19+
exit();
20+
}
21+
$groupManager = \OC::$server->getGroupManager();
22+
$authorizedGroupMapper = \OC::$server->get(\OC\Settings\AuthorizedGroupMapper::class);
23+
$isAdmin = $groupManager->isAdmin($currentUser->getUID());
24+
// A delegated admin is granted access when their group is authorized for the files_external Admin settings class.
25+
$isDelegated = in_array(\OCA\Files_External\Settings\Admin::class, $authorizedGroupMapper->findAllClassesForUser($currentUser), true);
26+
if (!$isAdmin && !$isDelegated) {
27+
\OC_JSON::error(['message' => 'Not authorized']);
28+
exit();
29+
}
1630

1731
$pattern = '';
1832
$limit = null;

build/psalm-baseline.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,9 +1407,12 @@
14071407
<file src="apps/files_external/ajax/applicable.php">
14081408
<DeprecatedMethod>
14091409
<code><![CDATA[\OC_JSON::callCheck()]]></code>
1410-
<code><![CDATA[\OC_JSON::checkAdminUser()]]></code>
14111410
<code><![CDATA[\OC_JSON::checkAppEnabled('files_external')]]></code>
1411+
<code><![CDATA[\OC_JSON::error(['message' => 'Not authorized'])]]></code>
1412+
<code><![CDATA[\OC_JSON::error(['message' => 'Not logged in'])]]></code>
14121413
<code><![CDATA[\OC_JSON::success($results)]]></code>
1414+
<code><![CDATA[getGroupManager]]></code>
1415+
<code><![CDATA[getUserSession]]></code>
14131416
</DeprecatedMethod>
14141417
</file>
14151418
<file src="apps/files_external/ajax/oauth2.php">

0 commit comments

Comments
 (0)