Skip to content

Commit 77e31b8

Browse files
committed
fix: reject conversion of accounts with administrative privileges
- refuse converting members of the admin group and subadmins, both return 409 - add controller tests covering both rejection paths Assisted-by: ClaudeCode:claude-fable-5 Signed-off-by: ernolf <raphael.gradenwitz@googlemail.com>
1 parent 9d8d535 commit 77e31b8

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

lib/Controller/UsersController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ public function convert(string $userId): DataResponse {
286286
], Http::STATUS_CONFLICT);
287287
}
288288

289+
if ($this->groupManager->isAdmin($userId) || $this->subAdmin->isSubAdmin($user)) {
290+
return new DataResponse([
291+
'message' => $this->l10n->t('Accounts with administrative privileges cannot be converted to guests')
292+
], Http::STATUS_CONFLICT);
293+
}
294+
289295
try {
290296
$this->conversionService->convertToGuest($user, $author);
291297
$this->guestManager->setGuestQuota($user);

tests/unit/Controller/UsersControllerTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,41 @@ public function testConvertAlreadyGuest(): void {
803803
$this->assertEquals(Http::STATUS_CONFLICT, $response->getStatus());
804804
}
805805

806+
public function testConvertRejectsAdmin(): void {
807+
$this->userSession->method('getUser')->willReturn($this->createMock(IUser::class));
808+
809+
$user = $this->createMock(IUser::class);
810+
$user->method('getBackendClassName')->willReturn('Database');
811+
$user->method('getLastLogin')->willReturn(0);
812+
813+
$this->userManager->method('get')->with('karl')->willReturn($user);
814+
$this->guestManager->method('isGuest')->with($user)->willReturn(false);
815+
$this->groupManager->method('isAdmin')->with('karl')->willReturn(true);
816+
817+
$this->conversionService->expects($this->never())->method('convertToGuest');
818+
819+
$response = $this->controller->convert('karl');
820+
$this->assertEquals(Http::STATUS_CONFLICT, $response->getStatus());
821+
}
822+
823+
public function testConvertRejectsSubAdmin(): void {
824+
$this->userSession->method('getUser')->willReturn($this->createMock(IUser::class));
825+
826+
$user = $this->createMock(IUser::class);
827+
$user->method('getBackendClassName')->willReturn('Database');
828+
$user->method('getLastLogin')->willReturn(0);
829+
830+
$this->userManager->method('get')->with('karl')->willReturn($user);
831+
$this->guestManager->method('isGuest')->with($user)->willReturn(false);
832+
$this->groupManager->method('isAdmin')->with('karl')->willReturn(false);
833+
$this->subAdmin->method('isSubAdmin')->with($user)->willReturn(true);
834+
835+
$this->conversionService->expects($this->never())->method('convertToGuest');
836+
837+
$response = $this->controller->convert('karl');
838+
$this->assertEquals(Http::STATUS_CONFLICT, $response->getStatus());
839+
}
840+
806841
public function testConvertRejectsAccountThatLoggedIn(): void {
807842
$this->userSession->method('getUser')->willReturn($this->createMock(IUser::class));
808843

0 commit comments

Comments
 (0)