mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
feat(files_external): allow delegated admins to search applicable users/groups
Signed-off-by: Tatjana Kaschperko Lindt <kaschperko-lindt@strato.de>
This commit is contained in:
parent
281f0e7367
commit
f2fdcae494
2 changed files with 47 additions and 0 deletions
|
|
@ -13,6 +13,7 @@ use OCA\Files_External\Lib\Auth\PublicKey\RSA;
|
|||
use OCA\Files_External\Settings\Admin;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting;
|
||||
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
|
||||
use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
|
|
@ -54,6 +55,7 @@ class AjaxController extends Controller {
|
|||
* @param int|null $offset The offset from which to start returning results
|
||||
* @return JSONResponse
|
||||
*/
|
||||
#[AuthorizedAdminSetting(settings: Admin::class)]
|
||||
public function getApplicableEntities(string $pattern = '', ?int $limit = null, ?int $offset = null): JSONResponse {
|
||||
$groups = [];
|
||||
foreach ($this->groupManager->search($pattern, $limit, $offset) as $group) {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
|
|||
use OCA\Files_External\Lib\Auth\PublicKey\RSA;
|
||||
use OCA\Files_External\Settings\Admin;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\IGroup;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
|
|
@ -67,6 +68,50 @@ class AjaxControllerTest extends TestCase {
|
|||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testGetApplicableEntitiesReturnsGroupsAndUsers(): void {
|
||||
$group = $this->createMock(IGroup::class);
|
||||
$group->method('getGID')->willReturn('group1');
|
||||
$group->method('getDisplayName')->willReturn('Group One');
|
||||
|
||||
$user = $this->createMock(IUser::class);
|
||||
$user->method('getUID')->willReturn('user1');
|
||||
$user->method('getDisplayName')->willReturn('User One');
|
||||
|
||||
$this->groupManager
|
||||
->expects($this->once())
|
||||
->method('search')
|
||||
->with('test', 10, 0)
|
||||
->willReturn([$group]);
|
||||
$this->userManager
|
||||
->expects($this->once())
|
||||
->method('searchDisplayName')
|
||||
->with('test', 10, 0)
|
||||
->willReturn([$user]);
|
||||
|
||||
$response = $this->ajaxController->getApplicableEntities('test', 10, 0);
|
||||
$this->assertSame(200, $response->getStatus());
|
||||
$this->assertSame(['group1' => 'Group One'], $response->getData()['groups']);
|
||||
$this->assertSame(['user1' => 'User One'], $response->getData()['users']);
|
||||
}
|
||||
|
||||
public function testGetApplicableEntitiesWithNoResults(): void {
|
||||
$this->groupManager
|
||||
->expects($this->once())
|
||||
->method('search')
|
||||
->with('', null, null)
|
||||
->willReturn([]);
|
||||
$this->userManager
|
||||
->expects($this->once())
|
||||
->method('searchDisplayName')
|
||||
->with('', null, null)
|
||||
->willReturn([]);
|
||||
|
||||
$response = $this->ajaxController->getApplicableEntities();
|
||||
$this->assertSame(200, $response->getStatus());
|
||||
$this->assertSame([], $response->getData()['groups']);
|
||||
$this->assertSame([], $response->getData()['users']);
|
||||
}
|
||||
|
||||
public function testGetSshKeys(): void {
|
||||
$this->rsa
|
||||
->expects($this->once())
|
||||
|
|
|
|||
Loading…
Reference in a new issue