From 8ccbd5000d6610c777aa7aaddd550e17b8111f02 Mon Sep 17 00:00:00 2001 From: Leonid Nikitin Date: Tue, 5 Dec 2023 21:48:02 +0600 Subject: [PATCH] Add demo mode restriction to CaptchaToken destroy method. This commit adds a check to the `destroy` method in the `CaptchaTokenService`. It uses the `Helpers::isDemoModeAndUserDenyUpdate` function to prevent users from deleting tokens while the application is in demo mode. This was added to protect the application's state during presentations or demos. --- app/Models/CaptchaToken.php | 6 ++++++ app/Services/Private/CaptchaTokenService.php | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/app/Models/CaptchaToken.php b/app/Models/CaptchaToken.php index b837307..0abc23b 100644 --- a/app/Models/CaptchaToken.php +++ b/app/Models/CaptchaToken.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; @@ -36,4 +37,9 @@ final class CaptchaToken extends Model { return $this->hasMany(Captcha::class); } + + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } } diff --git a/app/Services/Private/CaptchaTokenService.php b/app/Services/Private/CaptchaTokenService.php index d4e973a..df66641 100644 --- a/app/Services/Private/CaptchaTokenService.php +++ b/app/Services/Private/CaptchaTokenService.php @@ -5,6 +5,7 @@ namespace App\Services\Private; use App\Dto\Builder\CaptchaToken as CaptchaTokenDto; use App\Dto\QuerySettingsDto; use App\Dto\Request\Private\CaptchaToken\StoreUpdate; +use App\Helpers\Helpers; use App\Models\User; use App\Models\CaptchaToken; use App\Repositories\CaptchaTokenRepository; @@ -133,6 +134,10 @@ final class CaptchaTokenService extends Service return $this->errFobidden(__('Access is denied')); } + if (Helpers::isDemoModeAndUserDenyUpdate($modelCaptchaToken->user)) { + return $this->errValidate(__('Demo Mode')); + } + try { DB::transaction(function () use ($modelCaptchaToken) { $this->captchaTokenHandler->handleDestroy($modelCaptchaToken);