Code fixes.

This commit is contained in:
James Cole
2021-05-24 08:06:56 +02:00
parent 3b1b353b79
commit 2bff7750b4
45 changed files with 331 additions and 248 deletions

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Models;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -31,14 +32,14 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class WebhookAttempt
*
* @property int $id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property string|null $deleted_at
* @property int $webhook_message_id
* @property int $status_code
* @property string|null $logs
* @property string|null $response
* @property int $id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property string|null $deleted_at
* @property int $webhook_message_id
* @property int $status_code
* @property string|null $logs
* @property string|null $response
* @property-read \FireflyIII\Models\WebhookMessage $webhookMessage
* @method static \Illuminate\Database\Eloquent\Builder|WebhookAttempt newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|WebhookAttempt newQuery()
@@ -59,6 +60,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class WebhookAttempt extends Model
{
use SoftDeletes;
/**
* @codeCoverageIgnore
* @return BelongsTo
@@ -84,10 +86,8 @@ class WebhookAttempt extends Model
$user = auth()->user();
/** @var WebhookAttempt $attempt */
$attempt = self::find($attemptId);
if (null !== $attempt) {
if($attempt->webhookMessage->webhook->user_id === $user->id) {
return $attempt;
}
if (null !== $attempt && $attempt->webhookMessage->webhook->user_id === $user->id) {
return $attempt;
}
}
throw new NotFoundHttpException;

View File

@@ -22,6 +22,7 @@
declare(strict_types=1);
namespace FireflyIII\Models;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -31,18 +32,18 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* FireflyIII\Models\WebhookMessage
*
* @property int $id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property string|null $deleted_at
* @property int $webhook_id
* @property bool $sent
* @property bool $errored
* @property int $attempts
* @property string $uuid
* @property array $message
* @property array|null $logs
* @property-read \FireflyIII\Models\Webhook $webhook
* @property int $id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property string|null $deleted_at
* @property int $webhook_id
* @property bool $sent
* @property bool $errored
* @property int $attempts
* @property string $uuid
* @property array $message
* @property array|null $logs
* @property-read \FireflyIII\Models\Webhook $webhook
* @method static \Illuminate\Database\Eloquent\Builder|WebhookMessage newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|WebhookMessage newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|WebhookMessage query()
@@ -59,7 +60,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @method static \Illuminate\Database\Eloquent\Builder|WebhookMessage whereWebhookId($value)
* @mixin \Eloquent
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\WebhookAttempt[] $webhookAttempts
* @property-read int|null $webhook_attempts_count
* @property-read int|null $webhook_attempts_count
*/
class WebhookMessage extends Model
{
@@ -70,7 +71,7 @@ class WebhookMessage extends Model
'errored' => 'boolean',
'uuid' => 'string',
'message' => 'json',
'logs' => 'json',
'logs' => 'json',
];
/**
@@ -89,10 +90,8 @@ class WebhookMessage extends Model
$user = auth()->user();
/** @var WebhookMessage $message */
$message = self::find($messageId);
if (null !== $message) {
if($message->webhook->user_id === $user->id) {
return $message;
}
if (null !== $message && $message->webhook->user_id === $user->id) {
return $message;
}
}
throw new NotFoundHttpException;