diff --git a/apps/files_external/lib/Controller/GlobalStoragesController.php b/apps/files_external/lib/Controller/GlobalStoragesController.php index 3d78fe9a49a..287c00e179b 100644 --- a/apps/files_external/lib/Controller/GlobalStoragesController.php +++ b/apps/files_external/lib/Controller/GlobalStoragesController.php @@ -9,7 +9,9 @@ namespace OCA\Files_External\Controller; use OCA\Files_External\NotFoundException; 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; @@ -60,6 +62,7 @@ class GlobalStoragesController extends StoragesController { * @param ?array $applicableGroups groups for which to mount the storage * @param ?int $priority priority */ + #[AuthorizedAdminSetting(settings: Admin::class)] #[PasswordConfirmationRequired(strict: true)] public function create( string $mountPoint, @@ -123,6 +126,7 @@ class GlobalStoragesController extends StoragesController { * @param ?array $applicableGroups groups for which to mount the storage * @param ?int $priority priority */ + #[AuthorizedAdminSetting(settings: Admin::class)] #[PasswordConfirmationRequired(strict: true)] public function update( int $id, @@ -173,4 +177,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 7ff3dcf2321..d4ac8419024 100644 --- a/apps/files_external/tests/Settings/AdminTest.php +++ b/apps/files_external/tests/Settings/AdminTest.php @@ -126,4 +126,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); + } }