From ed6547f95bf8426b826064fc50e80c0dd30ff5eb Mon Sep 17 00:00:00 2001 From: Josh Date: Sat, 5 Oct 2024 08:35:24 -0400 Subject: [PATCH 1/2] refactor: Replace security annotations with attributes in SettingsController Signed-off-by: Josh --- lib/Controller/SettingsController.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index b5fec4c2..16c37edf 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -9,8 +9,10 @@ use OCA\LogReader\Constants; use OCA\LogReader\Service\SettingsService; +use OCA\LogReader\Settings\Admin; use OCP\AppFramework\ApiController; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting; use OCP\AppFramework\Http\JSONResponse; use OCP\IConfig; use OCP\IRequest; @@ -31,9 +33,8 @@ public function __construct( /** * Get the current app config - * - * @AuthorizedAdminSetting(settings=OCA\LogReader\Settings\Admin) */ + #[AuthorizedAdminSetting(settings: Admin::class)] public function getAppConfig(): JSONResponse { return new JSONResponse($this->settingsService->getAppSettings()); } @@ -44,8 +45,8 @@ public function getAppConfig(): JSONResponse { * @param string $settingsKey AppConfig Key to store * @param mixed $settingsValues Corresponding AppConfig Value * - * @AuthorizedAdminSetting(settings=OCA\LogReader\Settings\Admin) */ + #[AuthorizedAdminSetting(settings: Admin::class)] public function updateAppConfig(string $settingsKey, $settingsValue): JSONResponse { $this->logger->debug('Updating AppConfig: {settingsKey} => {settingsValue}', [ 'settingsKey' => $settingsKey, From 3701975c47acc14e4063e4ab720451e6052fff59 Mon Sep 17 00:00:00 2001 From: Josh Date: Sat, 5 Oct 2024 08:39:33 -0400 Subject: [PATCH 2/2] refactor: Replace security annotations with attributes in LogController Signed-off-by: Josh --- lib/Controller/LogController.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Controller/LogController.php b/lib/Controller/LogController.php index 713b060a..ce1c91a3 100644 --- a/lib/Controller/LogController.php +++ b/lib/Controller/LogController.php @@ -9,8 +9,10 @@ use OCA\LogReader\Log\LogIteratorFactory; use OCA\LogReader\Log\SearchFilter; use OCA\LogReader\Service\SettingsService; +use OCA\LogReader\Settings\Admin; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting; use OCP\AppFramework\Http\JSONResponse; use OCP\IRequest; use Psr\Log\LoggerInterface; @@ -32,12 +34,12 @@ public function __construct($appName, } /** - * @AuthorizedAdminSetting(settings=OCA\LogReader\Settings\Admin) * @param string $query * @param int $count * @param int $offset * @return JSONResponse */ + #[AuthorizedAdminSetting(settings: Admin::class)] public function get($query = '', $count = 50, $offset = 0): JSONResponse { $logType = $this->settingsService->getLoggingType(); // we only support web access when `log_type` is set to `file` (the default) @@ -70,7 +72,6 @@ private function getLastItem() { } /** - * @AuthorizedAdminSetting(settings=OCA\LogReader\Settings\Admin) * @brief Use to poll for new log messages since $lastReqId. * * @note There is a possible race condition, when the user loads the @@ -83,6 +84,7 @@ private function getLastItem() { * will work in some cases but not when there are more than 50 messages of that * request. */ + #[AuthorizedAdminSetting(settings: Admin::class)] public function poll(string $lastReqId): JSONResponse { $logType = $this->settingsService->getLoggingType(); // we only support web access when `log_type` is set to `file` (the default)