mirror of
https://github.com/nextcloud/server.git
synced 2026-06-08 08:16:43 -04:00
fix: Fix errors spotted by reviewers, fix @throws annotations
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
d3c06d5dea
commit
cccda66c7d
5 changed files with 19 additions and 14 deletions
|
|
@ -45,9 +45,9 @@ class WebhookCall extends QueuedJob {
|
|||
$response = $client->request($webhookListener->getHttpMethod(), $webhookListener->getUri(), $options);
|
||||
$statusCode = $response->getStatusCode();
|
||||
if ($statusCode >= 200 && $statusCode < 300) {
|
||||
$this->logger->warning('Webhook returned unexpected status code '.$statusCode, ['body' => $response->getBody()]);
|
||||
} else {
|
||||
$this->logger->debug('Webhook returned status code '.$statusCode, ['body' => $response->getBody()]);
|
||||
} else {
|
||||
$this->logger->warning('Webhook returned unexpected status code '.$statusCode, ['body' => $response->getBody()]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error('Webhook call failed: '.$e->getMessage(), ['exception' => $e]);
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ declare(strict_types=1);
|
|||
|
||||
namespace OCA\Webhooks\Controller;
|
||||
|
||||
use Doctrine\DBAL\Exception;
|
||||
use OCA\Webhooks\Db\AuthMethod;
|
||||
use OCA\Webhooks\Db\WebhookListenerMapper;
|
||||
use OCA\Webhooks\ResponseDefinitions;
|
||||
use OCP\AppFramework\Http\Attribute\ApiRoute;
|
||||
use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting;
|
||||
use OCP\AppFramework\Http\Attribute\OpenAPI;
|
||||
|
|
@ -210,7 +210,7 @@ class WebhooksController extends OCSController {
|
|||
throw new OCSBadRequestException($e->getMessage(), $e);
|
||||
} catch (\DomainException $e) {
|
||||
throw new OCSForbiddenException($e->getMessage(), $e);
|
||||
} catch (Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error('Error when deleting flow with id ' . $id, ['exception' => $e]);
|
||||
throw new OCSException('An internal error occurred', $e->getCode(), $e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,8 +42,6 @@ class WebhookListenerMapper extends QBMapper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws DoesNotExistException
|
||||
* @throws MultipleObjectsReturnedException
|
||||
* @throws Exception
|
||||
* @return WebhookListener[]
|
||||
*/
|
||||
|
|
@ -56,6 +54,9 @@ class WebhookListenerMapper extends QBMapper {
|
|||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function addWebhookListener(
|
||||
?string $appId,
|
||||
string $userId,
|
||||
|
|
@ -66,7 +67,7 @@ class WebhookListenerMapper extends QBMapper {
|
|||
?array $headers,
|
||||
AuthMethod $authMethod,
|
||||
?array $authData,
|
||||
) {
|
||||
): WebhookListener {
|
||||
$webhookListener = WebhookListener::fromParams(
|
||||
[
|
||||
'appId' => $appId,
|
||||
|
|
@ -83,6 +84,9 @@ class WebhookListenerMapper extends QBMapper {
|
|||
return $this->insert($webhookListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function updateWebhookListener(
|
||||
int $id,
|
||||
?string $appId,
|
||||
|
|
@ -94,7 +98,7 @@ class WebhookListenerMapper extends QBMapper {
|
|||
?array $headers,
|
||||
AuthMethod $authMethod,
|
||||
?array $authData,
|
||||
) {
|
||||
): WebhookListener {
|
||||
$webhookListener = WebhookListener::fromParams(
|
||||
[
|
||||
'id' => $id,
|
||||
|
|
@ -113,8 +117,6 @@ class WebhookListenerMapper extends QBMapper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws DoesNotExistException
|
||||
* @throws MultipleObjectsReturnedException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function deleteById(int $id): bool {
|
||||
|
|
@ -127,6 +129,7 @@ class WebhookListenerMapper extends QBMapper {
|
|||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @return list<string>
|
||||
* TODO cache
|
||||
*/
|
||||
|
|
@ -147,6 +150,9 @@ class WebhookListenerMapper extends QBMapper {
|
|||
return $configuredEvents;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getByEvent(string $event): array {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
|
||||
|
|
|
|||
|
|
@ -34,14 +34,13 @@ class WebhooksEventListener implements IEventListener {
|
|||
|
||||
public function handle(Event $event): void {
|
||||
$webhookListeners = $this->mapper->getByEvent($event::class);
|
||||
/** @var IUser */
|
||||
$user = $this->userSession->getUser();
|
||||
|
||||
foreach ($webhookListeners as $webhookListener) {
|
||||
// TODO add group membership to be able to filter on it
|
||||
$data = [
|
||||
'event' => $this->serializeEvent($event),
|
||||
'user' => JsonSerializer::serializeUser($user),
|
||||
'user' => (is_null($user) ? null : JsonSerializer::serializeUser($user)),
|
||||
'time' => time(),
|
||||
];
|
||||
if ($this->filterMatch($webhookListener->getEventFilter(), $data)) {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class Version1000Date20240527153425 extends SimpleMigrationStep {
|
|||
|
||||
if (!$schema->hasTable(WebhookListenerMapper::TABLE_NAME)) {
|
||||
$table = $schema->createTable(WebhookListenerMapper::TABLE_NAME);
|
||||
$table->addColumn('id', Types::INTEGER, [
|
||||
$table->addColumn('id', Types::BIGINT, [
|
||||
'autoincrement' => true,
|
||||
'notnull' => true,
|
||||
'length' => 4,
|
||||
|
|
@ -45,7 +45,7 @@ class Version1000Date20240527153425 extends SimpleMigrationStep {
|
|||
]);
|
||||
$table->addColumn('uri', Types::STRING, [
|
||||
'notnull' => true,
|
||||
'length' => 256,
|
||||
'length' => 4096,
|
||||
]);
|
||||
$table->addColumn('event', Types::TEXT, [
|
||||
'notnull' => true,
|
||||
|
|
|
|||
Loading…
Reference in a new issue