diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-06-03 16:10:55 +0200 |
---|---|---|
committer | Côme Chilliet <91878298+come-nc@users.noreply.github.com> | 2024-06-11 14:10:29 +0200 |
commit | 261f08e631f0442f4077c0936c4b784e257830b1 (patch) | |
tree | 64fbe113355ae8828df1837cc3a9434719ddbcaf | |
parent | 75b2ed4c79f187114d66a299f11266b325f6baa3 (diff) | |
download | nextcloud-server-261f08e631f0442f4077c0936c4b784e257830b1.tar.gz nextcloud-server-261f08e631f0442f4077c0936c4b784e257830b1.zip |
feat: Add app_api app id to saved information about webhook
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r-- | apps/webhooks/lib/Controller/WebhooksController.php | 12 | ||||
-rw-r--r-- | apps/webhooks/lib/Db/WebhookListener.php | 6 | ||||
-rw-r--r-- | apps/webhooks/lib/Db/WebhookListenerMapper.php | 4 | ||||
-rwxr-xr-x | apps/webhooks/lib/Migration/Version1000Date20240527153425.php | 4 | ||||
-rw-r--r-- | apps/webhooks/openapi.json | 26 | ||||
-rw-r--r-- | apps/webhooks/tests/Db/WebhookListenerMapperTest.php | 1 |
6 files changed, 50 insertions, 3 deletions
diff --git a/apps/webhooks/lib/Controller/WebhooksController.php b/apps/webhooks/lib/Controller/WebhooksController.php index 21a06f5e563..0893743cdb9 100644 --- a/apps/webhooks/lib/Controller/WebhooksController.php +++ b/apps/webhooks/lib/Controller/WebhooksController.php @@ -20,6 +20,7 @@ use OCP\AppFramework\OCS\OCSException; use OCP\AppFramework\OCS\OCSForbiddenException; use OCP\AppFramework\OCSController; use OCP\IRequest; +use OCP\ISession; use Psr\Log\LoggerInterface; /** @@ -33,6 +34,7 @@ class WebhooksController extends OCSController { private LoggerInterface $logger, private WebhookListenerMapper $mapper, private ?string $userId, + private ISession $session, ) { parent::__construct($appName, $request); } @@ -97,8 +99,13 @@ class WebhooksController extends OCSController { ?string $authMethod, ?array $authData, ): DataResponse { + $appId = null; + if ($this->session->get('app_api') === true) { + $appId = $this->request->getHeader('EX-APP-ID'); + } try { $webhookListener = $this->mapper->addWebhookListener( + $appId, $this->userId, $httpMethod, $uri, @@ -151,9 +158,14 @@ class WebhooksController extends OCSController { ?string $authMethod, ?array $authData, ): DataResponse { + $appId = null; + if ($this->session->get('app_api') === true) { + $appId = $this->request->getHeader('EX-APP-ID'); + } try { $webhookListener = $this->mapper->updateWebhookListener( $id, + $appId, $this->userId, $httpMethod, $uri, diff --git a/apps/webhooks/lib/Db/WebhookListener.php b/apps/webhooks/lib/Db/WebhookListener.php index 8e16249b678..20d00959f8c 100644 --- a/apps/webhooks/lib/Db/WebhookListener.php +++ b/apps/webhooks/lib/Db/WebhookListener.php @@ -16,7 +16,10 @@ use OCP\AppFramework\Db\Entity; * @method string getUserId() */ class WebhookListener extends Entity implements \JsonSerializable { - /** @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; + + /** @var string id of the user who added the webhook listener */ protected $userId; /** @var string */ @@ -41,6 +44,7 @@ class WebhookListener extends Entity implements \JsonSerializable { protected $authData; public function __construct() { + $this->addType('appId', 'string'); $this->addType('userId', 'string'); $this->addType('httpMethod', 'string'); $this->addType('uri', 'string'); diff --git a/apps/webhooks/lib/Db/WebhookListenerMapper.php b/apps/webhooks/lib/Db/WebhookListenerMapper.php index 5ce824893ab..3b472231e37 100644 --- a/apps/webhooks/lib/Db/WebhookListenerMapper.php +++ b/apps/webhooks/lib/Db/WebhookListenerMapper.php @@ -57,6 +57,7 @@ class WebhookListenerMapper extends QBMapper { } public function addWebhookListener( + ?string $appId, string $userId, string $httpMethod, string $uri, @@ -68,6 +69,7 @@ class WebhookListenerMapper extends QBMapper { ) { $webhookListener = WebhookListener::fromParams( [ + 'appId' => $appId, 'userId' => $userId, 'httpMethod' => $httpMethod, 'uri' => $uri, @@ -83,6 +85,7 @@ class WebhookListenerMapper extends QBMapper { public function updateWebhookListener( int $id, + ?string $appId, string $userId, string $httpMethod, string $uri, @@ -95,6 +98,7 @@ class WebhookListenerMapper extends QBMapper { $webhookListener = WebhookListener::fromParams( [ 'id' => $id, + 'appId' => $appId, 'userId' => $userId, 'httpMethod' => $httpMethod, 'uri' => $uri, diff --git a/apps/webhooks/lib/Migration/Version1000Date20240527153425.php b/apps/webhooks/lib/Migration/Version1000Date20240527153425.php index b6c345a22e2..1b064143533 100755 --- a/apps/webhooks/lib/Migration/Version1000Date20240527153425.php +++ b/apps/webhooks/lib/Migration/Version1000Date20240527153425.php @@ -31,6 +31,10 @@ class Version1000Date20240527153425 extends SimpleMigrationStep { 'notnull' => true, 'length' => 4, ]); + $table->addColumn('app_id', Types::STRING, [ + 'notnull' => false, + 'length' => 64, + ]); $table->addColumn('user_id', Types::STRING, [ 'notnull' => true, 'length' => 64, diff --git a/apps/webhooks/openapi.json b/apps/webhooks/openapi.json index eeed54d7805..3a2c641b0a6 100644 --- a/apps/webhooks/openapi.json +++ b/apps/webhooks/openapi.json @@ -26,7 +26,8 @@ "id", "userId", "httpMethod", - "uri" + "uri", + "authMethod" ], "properties": { "id": { @@ -43,6 +44,27 @@ }, "event": { "type": "string" + }, + "eventFilter": { + "type": "array", + "items": { + "type": "object" + } + }, + "headers": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "authMethod": { + "type": "string" + }, + "authData": { + "type": "object", + "additionalProperties": { + "type": "object" + } } } }, @@ -709,4 +731,4 @@ } }, "tags": [] -} +}
\ No newline at end of file diff --git a/apps/webhooks/tests/Db/WebhookListenerMapperTest.php b/apps/webhooks/tests/Db/WebhookListenerMapperTest.php index 4481eb6661e..c9f6e39b31f 100644 --- a/apps/webhooks/tests/Db/WebhookListenerMapperTest.php +++ b/apps/webhooks/tests/Db/WebhookListenerMapperTest.php @@ -44,6 +44,7 @@ class WebhookListenerMapperTest extends TestCase { public function testInsertListenerAndGetIt() { $listener1 = $this->mapper->addWebhookListener( + null, 'bob', 'POST', 'https://webhook.example.com/endpoint', |