mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 11:48:05 +00:00
Webhook API
This commit is contained in:
@@ -128,11 +128,11 @@ class Webhook extends Model
|
||||
public static function routeBinder(string $value): Webhook
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$budgetId = (int)$value;
|
||||
$webhookId = (int)$value;
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
/** @var Webhook $webhook */
|
||||
$webhook = $user->webhooks()->find($budgetId);
|
||||
$webhook = $user->webhooks()->find($webhookId);
|
||||
if (null !== $webhook) {
|
||||
return $webhook;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -44,9 +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\Relations\HasMany;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* FireflyIII\Models\WebhookMessage
|
||||
@@ -93,6 +95,31 @@ class WebhookMessage extends Model
|
||||
'logs' => 'json',
|
||||
];
|
||||
|
||||
/**
|
||||
* Route binder. Converts the key in the URL to the specified object (or throw 404).
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return WebhookMessage
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public static function routeBinder(string $value): WebhookMessage
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$messageId = (int)$value;
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
/** @var WebhookMessage $message */
|
||||
$message = self::find($messageId);
|
||||
if (null !== $message) {
|
||||
if($message->webhook->user_id === $user->id) {
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new NotFoundHttpException;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return BelongsTo
|
||||
|
Reference in New Issue
Block a user