From 397dbc64968ec36b381c27cb49e5415b1abddef3 Mon Sep 17 00:00:00 2001 From: Tatjana Kaschperko Lindt Date: Mon, 30 Mar 2026 12:25:54 +0200 Subject: [PATCH] feat(files_external): add #[AuthorizedAdminSetting] to GlobalStoragesController Signed-off-by: Tatjana Kaschperko Lindt --- .../Controller/GlobalStoragesController.php | 22 +++++++++++++++++++ .../tests/Settings/AdminTest.php | 18 +++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/apps/files_external/lib/Controller/GlobalStoragesController.php b/apps/files_external/lib/Controller/GlobalStoragesController.php index 11fdc352dcb..22ba7eb669e 100644 --- a/apps/files_external/lib/Controller/GlobalStoragesController.php +++ b/apps/files_external/lib/Controller/GlobalStoragesController.php @@ -10,7 +10,9 @@ namespace OCA\Files_External\Controller; use OCA\Files_External\NotFoundException; use OCA\Files_External\Service\BackendService; use OCA\Files_External\Service\GlobalStoragesService; +use OCA\Files_External\Settings\Admin; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting; use OCP\AppFramework\Http\Attribute\PasswordConfirmationRequired; use OCP\AppFramework\Http\DataResponse; use OCP\IConfig; @@ -74,6 +76,7 @@ class GlobalStoragesController extends StoragesController { * * @return DataResponse */ + #[AuthorizedAdminSetting(settings: Admin::class)] #[PasswordConfirmationRequired(strict: true)] public function create( $mountPoint, @@ -129,6 +132,7 @@ class GlobalStoragesController extends StoragesController { * * @return DataResponse */ + #[AuthorizedAdminSetting(settings: Admin::class)] #[PasswordConfirmationRequired(strict: true)] public function update( $id, @@ -179,4 +183,22 @@ class GlobalStoragesController extends StoragesController { Http::STATUS_OK ); } + + // PHP attributes are not inherited, so these methods override the parent + // solely to attach #[AuthorizedAdminSetting] and expose them to delegated admins. + #[AuthorizedAdminSetting(settings: Admin::class)] + public function index() { + return parent::index(); + } + + #[AuthorizedAdminSetting(settings: Admin::class)] + public function show(int $id, $testOnly = true) { + return parent::show($id, $testOnly); + } + + #[AuthorizedAdminSetting(settings: Admin::class)] + #[PasswordConfirmationRequired(strict: true)] + public function destroy(int $id) { + return parent::destroy($id); + } } diff --git a/apps/files_external/tests/Settings/AdminTest.php b/apps/files_external/tests/Settings/AdminTest.php index 92eb9b89f6b..7abbb33d23d 100644 --- a/apps/files_external/tests/Settings/AdminTest.php +++ b/apps/files_external/tests/Settings/AdminTest.php @@ -98,4 +98,22 @@ class AdminTest extends TestCase { public function testGetPriority(): void { $this->assertSame(40, $this->admin->getPriority()); } + + public function testGetName(): void { + $this->l10n->expects($this->once()) + ->method('t') + ->with('External storage') + ->willReturn('External storage'); + + $this->assertSame('External storage', $this->admin->getName()); + } + + public function testGetAuthorizedAppConfig(): void { + $this->assertSame([], $this->admin->getAuthorizedAppConfig()); + } + + public function testImplementsIDelegatedSettings(): void { + $this->assertInstanceOf(\OCP\Settings\IDelegatedSettings::class, $this->admin); + $this->assertInstanceOf(\OCP\Settings\ISettings::class, $this->admin); + } }