diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-06-11 14:40:29 +0200 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-06-11 14:42:25 +0200 |
commit | e0b9ff4fa255b4dd4c1e3881e26dff18053e129a (patch) | |
tree | 1224fc56339eb38e707029e05e5e98a7eacbf2bc | |
parent | bff7d3c76958740419074d8436416a0b8cc25daa (diff) | |
download | nextcloud-server-e0b9ff4fa255b4dd4c1e3881e26dff18053e129a.tar.gz nextcloud-server-e0b9ff4fa255b4dd4c1e3881e26dff18053e129a.zip |
fix(webhooks): Fix a few more psalm notices
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
3 files changed, 55 insertions, 21 deletions
diff --git a/apps/webhook_listeners/lib/BackgroundJobs/WebhookCall.php b/apps/webhook_listeners/lib/BackgroundJobs/WebhookCall.php index 9689d4cb585..9c9a4bb6dbe 100644 --- a/apps/webhook_listeners/lib/BackgroundJobs/WebhookCall.php +++ b/apps/webhook_listeners/lib/BackgroundJobs/WebhookCall.php @@ -28,6 +28,9 @@ class WebhookCall extends QueuedJob { parent::__construct($timeFactory); } + /** + * @param array $argument + */ protected function run($argument): void { [$data, $webhookId] = $argument; $webhookListener = $this->mapper->getById($webhookId); diff --git a/apps/webhook_listeners/lib/Controller/WebhooksController.php b/apps/webhook_listeners/lib/Controller/WebhooksController.php index e7a05f0983e..1c4306eabb8 100644 --- a/apps/webhook_listeners/lib/Controller/WebhooksController.php +++ b/apps/webhook_listeners/lib/Controller/WebhooksController.php @@ -13,6 +13,7 @@ use OCA\WebhookListeners\Db\AuthMethod; use OCA\WebhookListeners\Db\WebhookListener; use OCA\WebhookListeners\Db\WebhookListenerMapper; use OCA\WebhookListeners\ResponseDefinitions; +use OCA\WebhookListeners\Settings\Admin; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Http; use OCP\AppFramework\Http\Attribute\ApiRoute; @@ -53,7 +54,7 @@ class WebhooksController extends OCSController { * 200: Webhook registrations returned */ #[ApiRoute(verb: 'GET', url: '/api/v1/webhooks')] - #[AuthorizedAdminSetting(settings:'OCA\WebhookListeners\Settings\Admin')] + #[AuthorizedAdminSetting(settings:Admin::class)] public function index(): DataResponse { try { $webhookListeners = $this->mapper->getAll(); @@ -82,7 +83,7 @@ class WebhooksController extends OCSController { * 200: Webhook registration returned */ #[ApiRoute(verb: 'GET', url: '/api/v1/webhooks/{id}')] - #[AuthorizedAdminSetting(settings:'OCA\WebhookListeners\Settings\Admin')] + #[AuthorizedAdminSetting(settings:Admin::class)] public function show(int $id): DataResponse { try { return new DataResponse($this->mapper->getById($id)->jsonSerialize()); @@ -114,7 +115,7 @@ class WebhooksController extends OCSController { * @throws OCSException Other error */ #[ApiRoute(verb: 'POST', url: '/api/v1/webhooks')] - #[AuthorizedAdminSetting(settings:'OCA\WebhookListeners\Settings\Admin')] + #[AuthorizedAdminSetting(settings:Admin::class)] public function create( string $httpMethod, string $uri, @@ -135,6 +136,8 @@ class WebhooksController extends OCSController { throw new OCSBadRequestException('This auth method does not exist'); } try { + /* We can never reach here without a user in session */ + assert(is_string($this->userId)); $webhookListener = $this->mapper->addWebhookListener( $appId, $this->userId, @@ -178,7 +181,7 @@ class WebhooksController extends OCSController { * @throws OCSException Other error */ #[ApiRoute(verb: 'POST', url: '/api/v1/webhooks/{id}')] - #[AuthorizedAdminSetting(settings:'OCA\WebhookListeners\Settings\Admin')] + #[AuthorizedAdminSetting(settings:Admin::class)] public function update( int $id, string $httpMethod, @@ -200,6 +203,8 @@ class WebhooksController extends OCSController { throw new OCSBadRequestException('This auth method does not exist'); } try { + /* We can never reach here without a user in session */ + assert(is_string($this->userId)); $webhookListener = $this->mapper->updateWebhookListener( $id, $appId, @@ -237,7 +242,7 @@ class WebhooksController extends OCSController { * @throws OCSException Other error */ #[ApiRoute(verb: 'DELETE', url: '/api/v1/webhooks/{id}')] - #[AuthorizedAdminSetting(settings:'OCA\WebhookListeners\Settings\Admin')] + #[AuthorizedAdminSetting(settings:Admin::class)] public function destroy(int $id): DataResponse { try { $deleted = $this->mapper->deleteById($id); diff --git a/apps/webhook_listeners/lib/Db/WebhookListener.php b/apps/webhook_listeners/lib/Db/WebhookListener.php index 222e6b981bd..e9b63e01472 100644 --- a/apps/webhook_listeners/lib/Db/WebhookListener.php +++ b/apps/webhook_listeners/lib/Db/WebhookListener.php @@ -20,35 +20,60 @@ use OCP\Security\ICrypto; * @method ?array getHeaders() * @method ?string getAuthData() * @method void setAuthData(?string $data) - * @method ?string getAuthMethod() + * @method string getAuthMethod() + * @psalm-suppress PropertyNotSetInConstructor */ class WebhookListener extends Entity implements \JsonSerializable { - /** @var ?string id of the app_api application who added the webhook listener */ - protected $appId; - - /** @var string id of the user who added the webhook listener */ + /** + * @var ?string id of the app_api application who added the webhook listener + */ + protected $appId = null; + + /** + * @var string id of the user who added the webhook listener + * @psalm-suppress PropertyNotSetInConstructor + */ protected $userId; - /** @var string */ + /** + * @var string + * @psalm-suppress PropertyNotSetInConstructor + */ protected $httpMethod; - /** @var string */ + /** + * @var string + * @psalm-suppress PropertyNotSetInConstructor + */ protected $uri; - /** @var string */ + /** + * @var string + * @psalm-suppress PropertyNotSetInConstructor + */ protected $event; - /** @var array */ + /** + * @var array + * @psalm-suppress PropertyNotSetInConstructor + */ protected $eventFilter; - /** @var ?array */ - protected $headers; + /** + * @var ?array + */ + protected $headers = null; - /** @var ?string */ + /** + * @var string + * @psalm-suppress PropertyNotSetInConstructor + */ protected $authMethod; - /** @var ?string */ - protected $authData; + /** + * @var ?string + */ + protected $authData = null; private ICrypto $crypto; @@ -75,10 +100,11 @@ class WebhookListener extends Entity implements \JsonSerializable { } public function getAuthDataClear(): array { - if ($this->authData === null) { + $authData = $this->getAuthData(); + if ($authData === null) { return []; } - return json_decode($this->crypto->decrypt($this->getAuthData()), associative:true, flags:JSON_THROW_ON_ERROR); + return json_decode($this->crypto->decrypt($authData), associative:true, flags:JSON_THROW_ON_ERROR); } public function setAuthDataClear( |