diff --git a/src/Listeners/LockListener.php b/src/Listeners/LockListener.php index 86ef777..0ee8b23 100755 --- a/src/Listeners/LockListener.php +++ b/src/Listeners/LockListener.php @@ -2,10 +2,12 @@ namespace Tv2regionerne\StatamicLocks\Listeners; +use Illuminate\Support\Carbon; use Illuminate\Validation\ValidationException; use Statamic\Events; use Statamic\Facades\Site; use Statamic\Facades\User; +use Statamic\Support\Str; use Tv2regionerne\StatamicLocks\Models\LockModel; class LockListener @@ -15,6 +17,13 @@ public function handle($event) $itemId = false; $itemType = false; + $path = request()->path(); + + // ignore locks on API requests + if (Str::of($path)->startsWith('api')) { + return; + } + if ($event instanceof Events\AssetSaving) { $itemId = $event->asset->id() ?? false; $itemType = 'asset'; @@ -38,9 +47,11 @@ public function handle($event) if ($lock = LockModel::where(['item_id' => $itemId, 'item_type' => $itemType, 'site' => Site::current()->handle()])->first()) { if (! $lock->user() || ! $user || $lock->user()->id() != $user->id()) { - throw ValidationException::withMessages([ - 'locked' => __('This item is locked'), - ]); + if ($lock->updated_at > Carbon::now()->subMinutes(config('statamic-locks.clear_locks_after', 5))) { + throw ValidationException::withMessages([ + 'locked' => __('This item is locked'), + ]); + } } } }