Webhook API

This commit is contained in:
James Cole
2021-03-07 12:13:22 +01:00
parent c4882231d1
commit ba163f82d1
19 changed files with 800 additions and 90 deletions

View File

@@ -44,8 +44,11 @@ declare(strict_types=1);
namespace FireflyIII\Models;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class WebhookAttempt
@@ -74,6 +77,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
*/
class WebhookAttempt extends Model
{
use SoftDeletes;
/**
* @codeCoverageIgnore
* @return BelongsTo
@@ -82,4 +86,29 @@ class WebhookAttempt extends Model
{
return $this->belongsTo(WebhookMessage::class);
}
/**
* Route binder. Converts the key in the URL to the specified object (or throw 404).
*
* @param string $value
*
* @return WebhookAttempt
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): WebhookAttempt
{
if (auth()->check()) {
$attemptId = (int)$value;
/** @var User $user */
$user = auth()->user();
/** @var WebhookAttempt $attempt */
$attempt = self::find($attemptId);
if (null !== $attempt) {
if($attempt->webhookMessage->webhook->user_id === $user->id) {
return $attempt;
}
}
}
throw new NotFoundHttpException;
}
}