Skip to content

Commit

Permalink
Only run these checks if app has custom AssetPolicy with extra logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseleite committed Sep 30, 2024
1 parent 5e637d7 commit a6c46a1
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions src/Policies/AssetFolderPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Statamic\Policies;

use Illuminate\Support\Facades\Gate;
use Statamic\Contracts\Assets\Asset as AssetContract;
use Statamic\Facades\User;

class AssetFolderPolicy
Expand All @@ -25,10 +27,14 @@ public function move($user, $assetFolder)
return false;
}

return $assetFolder
->assets(true)
->reject(fn ($asset) => $user->can('move', $asset))
->isEmpty();
if ($this->isUsingCustomAssetPolicy()) {
return $assetFolder
->assets(true)
->reject(fn ($asset) => $user->can('move', $asset))
->isEmpty();
}

return true;
}

public function rename($user, $assetFolder)
Expand All @@ -39,10 +45,14 @@ public function rename($user, $assetFolder)
return false;
}

return $assetFolder
->assets(true)
->reject(fn ($asset) => $user->can('rename', $asset))
->isEmpty();
if ($this->isUsingCustomAssetPolicy()) {
return $assetFolder
->assets(true)
->reject(fn ($asset) => $user->can('rename', $asset))
->isEmpty();
}

return true;
}

public function delete($user, $assetFolder)
Expand All @@ -53,9 +63,18 @@ public function delete($user, $assetFolder)
return false;
}

return $assetFolder
->assets(true)
->reject(fn ($asset) => $user->can('delete', $asset))
->isEmpty();
if ($this->isUsingCustomAssetPolicy()) {
return $assetFolder
->assets(true)
->reject(fn ($asset) => $user->can('delete', $asset))
->isEmpty();
}

return true;
}

protected function isUsingCustomAssetPolicy()
{
return Gate::policies()[AssetContract::class] !== AssetPolicy::class;
}
}

0 comments on commit a6c46a1

Please sign in to comment.