2024-08-30 20:22:28 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Imports;
|
|
|
|
|
|
|
|
|
|
use Exception;
|
2024-10-21 22:23:20 -05:00
|
|
|
use App\Models\Portfolio;
|
2024-08-30 20:22:28 -05:00
|
|
|
|
|
|
|
|
trait ValidatesPortfolioPermissions {
|
|
|
|
|
|
|
|
|
|
public function validatePortfolioPermissions($collection)
|
|
|
|
|
{
|
|
|
|
|
$portfolios = auth()->user()->portfolios->pluck('id');
|
|
|
|
|
|
|
|
|
|
$collection->pluck('portfolio_id')->unique()->each(function($portfolio) use ($portfolios) {
|
|
|
|
|
|
2024-10-21 22:23:20 -05:00
|
|
|
if (
|
|
|
|
|
!$portfolios->contains($portfolio)
|
|
|
|
|
|| auth()->user()->cannot('fullAccess', Portfolio::find($portfolio))
|
|
|
|
|
) {
|
2024-08-30 20:22:28 -05:00
|
|
|
|
|
|
|
|
throw new Exception('You do not have permission to access that portfolio.');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|