Skip to content

Commit faff52d

Browse files
tanyakaprintminion-co
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 5852eaa commit faff52d

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

apps/files_external/lib/Controller/AjaxController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use OCA\Files_External\Settings\Admin;
1414
use OCP\AppFramework\Controller;
1515
use OCP\AppFramework\Http;
16+
use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting;
1617
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
1718
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
1819
use OCP\AppFramework\Http\JSONResponse;
@@ -54,6 +55,7 @@ public function __construct(
5455
* @param int|null $offset The offset from which to start returning results
5556
* @return JSONResponse
5657
*/
58+
#[AuthorizedAdminSetting(settings: Admin::class)]
5759
public function getApplicableEntities(string $pattern = '', ?int $limit = null, ?int $offset = null): JSONResponse {
5860
$groups = [];
5961
foreach ($this->groupManager->search($pattern, $limit, $offset) as $group) {

apps/files_external/tests/Controller/AjaxControllerTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use OCA\Files_External\Lib\Auth\PublicKey\RSA;
1414
use OCA\Files_External\Settings\Admin;
1515
use OCP\AppFramework\Http\JSONResponse;
16+
use OCP\IGroup;
1617
use OCP\IGroupManager;
1718
use OCP\IL10N;
1819
use OCP\IRequest;
@@ -67,6 +68,50 @@ protected function setUp(): void {
6768
parent::setUp();
6869
}
6970

71+
public function testGetApplicableEntitiesReturnsGroupsAndUsers(): void {
72+
$group = $this->createMock(IGroup::class);
73+
$group->method('getGID')->willReturn('group1');
74+
$group->method('getDisplayName')->willReturn('Group One');
75+
76+
$user = $this->createMock(IUser::class);
77+
$user->method('getUID')->willReturn('user1');
78+
$user->method('getDisplayName')->willReturn('User One');
79+
80+
$this->groupManager
81+
->expects($this->once())
82+
->method('search')
83+
->with('test', 10, 0)
84+
->willReturn([$group]);
85+
$this->userManager
86+
->expects($this->once())
87+
->method('searchDisplayName')
88+
->with('test', 10, 0)
89+
->willReturn([$user]);
90+
91+
$response = $this->ajaxController->getApplicableEntities('test', 10, 0);
92+
$this->assertSame(200, $response->getStatus());
93+
$this->assertSame(['group1' => 'Group One'], $response->getData()['groups']);
94+
$this->assertSame(['user1' => 'User One'], $response->getData()['users']);
95+
}
96+
97+
public function testGetApplicableEntitiesWithNoResults(): void {
98+
$this->groupManager
99+
->expects($this->once())
100+
->method('search')
101+
->with('', null, null)
102+
->willReturn([]);
103+
$this->userManager
104+
->expects($this->once())
105+
->method('searchDisplayName')
106+
->with('', null, null)
107+
->willReturn([]);
108+
109+
$response = $this->ajaxController->getApplicableEntities();
110+
$this->assertSame(200, $response->getStatus());
111+
$this->assertSame([], $response->getData()['groups']);
112+
$this->assertSame([], $response->getData()['users']);
113+
}
114+
70115
public function testGetSshKeys(): void {
71116
$this->rsa
72117
->expects($this->once())

0 commit comments

Comments
 (0)