2024-10-28 18:35:14 -05:00
|
|
|
<?php
|
|
|
|
|
|
2025-01-28 17:33:54 -06:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2024-10-28 18:35:14 -05:00
|
|
|
namespace App\Imports;
|
|
|
|
|
|
|
|
|
|
use App\Models\Portfolio;
|
|
|
|
|
|
|
|
|
|
trait ValidatesPortfolioAccess
|
|
|
|
|
{
|
|
|
|
|
public function validatePortfolioAccess($collection)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$uniquePortfolios = $collection->unique('portfolio_id')->pluck('portfolio_id');
|
|
|
|
|
$countPortfoliosWithAccess = Portfolio::fullAccess($this->backupImport->user_id)
|
2025-01-28 17:14:49 -06:00
|
|
|
->whereIn('id', $uniquePortfolios)
|
|
|
|
|
->count();
|
2024-10-28 18:35:14 -05:00
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
$countPortfoliosWithAccess < $uniquePortfolios->count()
|
|
|
|
|
) {
|
2025-01-28 17:14:49 -06:00
|
|
|
throw new \Exception(__('You do not have access to that portfolio.'));
|
2024-10-28 18:35:14 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|